 03d49ce2df
			
		
	
	03d49ce2df
	
	
	
		
			
			Added ReviewDate property to ProcInfo class Changed how RevDate and ReviewDate values obtained from 16-bit data Added AddSlaveNode and AddSlaveItem methods to ConfigInfo class Added validity check to verify Procedure Set Path and Process Only In Location are in synch
		
			
				
	
	
		
			110 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
			
		
		
	
	
			110 lines
		
	
	
		
			3.7 KiB
		
	
	
	
		
			C#
		
	
	
	
	
	
| // ========================================================================
 | |
| // Copyright 2006 - Volian Enterprises, Inc. All rights reserved.          
 | |
| // Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
 | |
| // ------------------------------------------------------------------------
 | |
| // $Workfile: $     $Revision: $                                           
 | |
| // $Author: $   $Date: $                                                   
 | |
| //                                                                         
 | |
| // $History: $                                                             
 | |
| // ========================================================================
 | |
| using System;
 | |
| using System.Collections.Generic;
 | |
| using System.Text;
 | |
| using System.Xml;
 | |
| 
 | |
| namespace DataLoader
 | |
| {
 | |
| 	class ConfigInfo
 | |
| 	{
 | |
| 		private XmlDocument xmldoc;
 | |
| 		public ConfigInfo(string xml)
 | |
| 		{
 | |
|             xmldoc = new XmlDocument();
 | |
|             if (xml == null)
 | |
|                 xmldoc.LoadXml("<Config/>");
 | |
|             else
 | |
|                 xmldoc.LoadXml(xml);
 | |
| 		}
 | |
| 
 | |
| 		public ConfigInfo(string xml, string ename, string aname, string avalue)
 | |
| 		{
 | |
|             xmldoc = new XmlDocument();
 | |
|             if (xml == null)
 | |
|                 xmldoc.LoadXml("<Config/>");
 | |
|             else
 | |
|                 xmldoc.LoadXml(xml);
 | |
| 			AddItem(ename, aname.Replace(' ','_'), avalue);
 | |
| 		}
 | |
| 		public bool AddItem(string ename, string aname, string avalue)
 | |
| 		{
 | |
| 			if (aname != null && aname != "")
 | |
| 			{
 | |
|                 //if (xmldoc == null)
 | |
|                 //{
 | |
|                 //    xmldoc = new XmlDocument();
 | |
|                 //    xmldoc.AppendChild(xmldoc.CreateElement("ConfigInfo"));
 | |
|                 //}
 | |
|                 // see if ename element exists, use it to add attributes, 
 | |
|                 // otherwise, create the element.
 | |
| 
 | |
|                 XmlNode nxml = null;
 | |
|                 XmlNodeList xl = xmldoc.DocumentElement.SelectNodes(string.Format("//{0}", ename));
 | |
|                 switch (xl.Count)
 | |
|                 {
 | |
|                     case 0: // No nodes found
 | |
|                         nxml = xmldoc.DocumentElement.AppendChild(xmldoc.CreateElement(ename));
 | |
|                         break;
 | |
|                     default: // Found the node
 | |
|                         nxml = xl[0];
 | |
|                         if (nxml.GetType() != typeof(XmlElement))
 | |
|                         {
 | |
| 							frmLoader._MyLog.ErrorFormat("Invalid xml element type when migrating config data - element = {0}, name = {1} , value = {2}", ename, aname, avalue);
 | |
|                             return false;
 | |
|                         }
 | |
|                         break;
 | |
|                 }
 | |
|                 XmlAttribute xa = nxml.Attributes.Append(xmldoc.CreateAttribute(aname.Replace(' ', '_')));
 | |
|                 xa.Value = avalue;
 | |
| 				return true;
 | |
| 			}
 | |
| 			return false;
 | |
| 		}
 | |
| 
 | |
| 		public int ItemCount
 | |
| 		{
 | |
| 			get { return xmldoc.DocumentElement.ChildNodes.Count; }
 | |
| 		}
 | |
| 
 | |
| 		public override string ToString()
 | |
| 		{
 | |
| 			if (xmldoc != null) return xmldoc.InnerXml;
 | |
| 			else return null;
 | |
| 		}
 | |
| 		public void AddSlaveNode(int index)
 | |
| 		{
 | |
| 			XmlElement slaves = xmldoc.SelectSingleNode("Config/Slaves") as XmlElement;
 | |
| 			if (slaves == null)
 | |
| 			{
 | |
| 				slaves = xmldoc.CreateElement("Slaves");
 | |
| 				xmldoc.DocumentElement.AppendChild(slaves);
 | |
| 			}
 | |
| 			XmlElement slave = xmldoc.CreateElement("Slave");
 | |
| 			XmlAttribute xa = xmldoc.CreateAttribute("index");
 | |
| 			xa.InnerText = index.ToString();
 | |
| 			slave.Attributes.Append(xa);
 | |
| 			slaves.AppendChild(slave);
 | |
| 		}
 | |
| 		public void AddSlaveItem(int index, string aname, string avalue)
 | |
| 		{
 | |
| 			string srch = "Config/Slaves/Slave[@index='" + index.ToString() + "']";
 | |
| 			XmlElement slave = xmldoc.SelectSingleNode(srch) as XmlElement;
 | |
| 			if (slave != null)
 | |
| 			{
 | |
| 				XmlAttribute xa = xmldoc.CreateAttribute(aname);
 | |
| 				xa.InnerText = avalue;
 | |
| 				slave.Attributes.Append(xa);
 | |
| 			}
 | |
| 		}
 | |
| 	}
 | |
| }
 |