CSLA - Format, Minimal, VEObject
This commit is contained in:
@@ -1,40 +1,23 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Xml;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
public class Comparator
|
||||
{
|
||||
private XmlDocument _ResultsDoc;
|
||||
public XmlDocument ResultsDoc
|
||||
{
|
||||
get { return _ResultsDoc; }
|
||||
set { _ResultsDoc = value; }
|
||||
}
|
||||
private XmlDocument _XDoc1;
|
||||
public XmlDocument XDoc1
|
||||
{
|
||||
get { return _XDoc1; }
|
||||
set { _XDoc1 = value; }
|
||||
}
|
||||
private XmlDocument _XDoc2;
|
||||
public XmlDocument XDoc2
|
||||
{
|
||||
get { return _XDoc2; }
|
||||
set { _XDoc2 = value; }
|
||||
}
|
||||
public Comparator(XmlDocument xdoc1, XmlDocument xdoc2)
|
||||
public XmlDocument ResultsDoc { get; set; }
|
||||
public XmlDocument XDoc1 { get; set; }
|
||||
public XmlDocument XDoc2 { get; set; }
|
||||
public Comparator(XmlDocument xdoc1, XmlDocument xdoc2)
|
||||
{
|
||||
XDoc1 = xdoc1;
|
||||
XDoc2 = xdoc2;
|
||||
ResultsDoc = new XmlDocument();
|
||||
ResultsDoc.LoadXml(@"<PlantFormat></PlantFormat>");
|
||||
}
|
||||
public Comparator(string existingFC, string importedFC) //string fName1, string fName2)
|
||||
public Comparator(string existingFC, string importedFC)
|
||||
{
|
||||
XDoc1 = new XmlDocument();
|
||||
XDoc1.LoadXml(existingFC);
|
||||
@@ -104,12 +87,12 @@ namespace VEPROMS.CSLA.Library
|
||||
xnss1.Add(GetKey(xc1), xc1);
|
||||
foreach (XmlNode xc2 in xns2.Values)
|
||||
if (xnss1.ContainsKey(GetKey(xc2)))
|
||||
Compare(xnss1[GetKey(xc2)], xc2, path + "/" + GetKey(xc2));
|
||||
Compare(xnss1[GetKey(xc2)], xc2, $"{path}/{GetKey(xc2)}");
|
||||
else
|
||||
xnss2.Add(GetKey(xc2), xc2);
|
||||
// element differences, if counts are different. xns1 elements are not found in xns2 and xns2 elements are not found in xns1
|
||||
if (xns1.Count == 0 && xns2.Count == 0) return;
|
||||
Console.WriteLine(" {0} {1} {2}", path + "/" + xn1.Name, xns1.Count, xns2.Count);
|
||||
Console.WriteLine($" {path}/{xn1.Name} {xns1.Count} {xns2.Count}");
|
||||
foreach (string key in xnss1.Keys)
|
||||
{
|
||||
if (xnss1[key].Attributes.Count > 0 || xnss1[key].ChildNodes.Count > 0)
|
||||
@@ -210,18 +193,14 @@ namespace VEPROMS.CSLA.Library
|
||||
public string GetKey1(XmlNode xn)
|
||||
{
|
||||
if (xn.Attributes == null) return xn.Name;
|
||||
XmlAttribute xi = xn.Attributes.GetNamedItem("Index") as XmlAttribute;
|
||||
if (xi != null)
|
||||
{
|
||||
XmlAttribute xa = xn.Attributes.GetNamedItem("Name") as XmlAttribute;
|
||||
if (xa != null) return string.Format("{0}[{1}]", xn.Name, xa.Value);
|
||||
return string.Format("{0}[{1}]", xn.Name, xi.Value);
|
||||
}
|
||||
XmlAttribute xt = xn.Attributes.GetNamedItem("Token") as XmlAttribute;
|
||||
if(xt != null) return string.Format("{0}[{1}]", xn.Name, xt.Value);
|
||||
XmlAttribute xw = xn.Attributes.GetNamedItem("ReplaceWord") as XmlAttribute;
|
||||
if(xw != null) return string.Format("{0}[{1}]", xn.Name, xw.Value);
|
||||
return xn.Name;
|
||||
if (xn.Attributes.GetNamedItem("Index") is XmlAttribute xi)
|
||||
{
|
||||
if (xn.Attributes.GetNamedItem("Name") is XmlAttribute xa) return string.Format("{0}[{1}]", xn.Name, xa.Value);
|
||||
return string.Format("{0}[{1}]", xn.Name, xi.Value);
|
||||
}
|
||||
if (xn.Attributes.GetNamedItem("Token") is XmlAttribute xt) return string.Format("{0}[{1}]", xn.Name, xt.Value);
|
||||
if (xn.Attributes.GetNamedItem("ReplaceWord") is XmlAttribute xw) return string.Format("{0}[{1}]", xn.Name, xw.Value);
|
||||
return xn.Name;
|
||||
}
|
||||
static private XmlNode makeXPath(XmlDocument doc, string xpath)
|
||||
{
|
||||
@@ -252,7 +231,6 @@ namespace VEPROMS.CSLA.Library
|
||||
string name = nextNodeInXPath.Substring(indx, nextNodeInXPath.IndexOf("=",indx)-indx);
|
||||
XmlAttribute xKeyd = doc.CreateAttribute(name);
|
||||
indx = nextNodeInXPath.IndexOf("='",indx)+2;
|
||||
string value = nextNodeInXPath.Substring(indx,nextNodeInXPath.IndexOf("'", indx) - indx);
|
||||
xKeyd.Value = nextNodeInXPath.Substring(indx,nextNodeInXPath.IndexOf("'",indx)-indx);
|
||||
node.Attributes.Append(xKeyd);
|
||||
}
|
||||
@@ -277,58 +255,56 @@ namespace VEPROMS.CSLA.Library
|
||||
// go through attributes in first xml document, see if they exist in the 2nd xml document & are identical attribute
|
||||
foreach (XmlAttribute xa1 in atts1)
|
||||
{
|
||||
XmlAttribute xa2 = atts2.GetNamedItem(xa1.Name) as XmlAttribute;
|
||||
if (xa2 == null)
|
||||
{
|
||||
XmlNode xnr = MakeXPathFormat(path);
|
||||
if (xnr != null)
|
||||
{
|
||||
XmlAttribute xKey = ResultsDoc.CreateAttribute(xa1.Name+"Old");
|
||||
xKey.Value = xa1.Value;
|
||||
xnr.Attributes.Append(xKey);
|
||||
xKey = ResultsDoc.CreateAttribute("OldKey");
|
||||
xKey.Value = GetKey(atts1Par);
|
||||
if (xKey.Value != null) xnr.Attributes.Append(xKey);
|
||||
}
|
||||
}
|
||||
else if (xa2.Value != xa1.Value)
|
||||
{
|
||||
XmlNode xnr = MakeXPathFormat(path);
|
||||
if (xnr != null)
|
||||
{
|
||||
XmlAttribute xKey = ResultsDoc.CreateAttribute(xa1.Name + "Old");
|
||||
xKey.Value = xa1.Value;
|
||||
xnr.Attributes.Append(xKey);
|
||||
XmlAttribute xKey2 = ResultsDoc.CreateAttribute(xa2.Name + "New");
|
||||
xKey2.Value = xa2.Value;
|
||||
xnr.Attributes.Append(xKey2);
|
||||
xKey = ResultsDoc.CreateAttribute("OldKey");
|
||||
xKey.Value = GetKey(atts1Par);
|
||||
if (xKey.Value != null) xnr.Attributes.Append(xKey);
|
||||
xKey = ResultsDoc.CreateAttribute("NewKey");
|
||||
xKey.Value = GetKey(atts2Par);
|
||||
if (xKey.Value != null) xnr.Attributes.Append(xKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(atts2.GetNamedItem(xa1.Name) is XmlAttribute xa2))
|
||||
{
|
||||
XmlNode xnr = MakeXPathFormat(path);
|
||||
if (xnr != null)
|
||||
{
|
||||
XmlAttribute xKey = ResultsDoc.CreateAttribute(xa1.Name + "Old");
|
||||
xKey.Value = xa1.Value;
|
||||
xnr.Attributes.Append(xKey);
|
||||
xKey = ResultsDoc.CreateAttribute("OldKey");
|
||||
xKey.Value = GetKey(atts1Par);
|
||||
if (xKey.Value != null) xnr.Attributes.Append(xKey);
|
||||
}
|
||||
}
|
||||
else if (xa2.Value != xa1.Value)
|
||||
{
|
||||
XmlNode xnr = MakeXPathFormat(path);
|
||||
if (xnr != null)
|
||||
{
|
||||
XmlAttribute xKey = ResultsDoc.CreateAttribute(xa1.Name + "Old");
|
||||
xKey.Value = xa1.Value;
|
||||
xnr.Attributes.Append(xKey);
|
||||
XmlAttribute xKey2 = ResultsDoc.CreateAttribute(xa2.Name + "New");
|
||||
xKey2.Value = xa2.Value;
|
||||
xnr.Attributes.Append(xKey2);
|
||||
xKey = ResultsDoc.CreateAttribute("OldKey");
|
||||
xKey.Value = GetKey(atts1Par);
|
||||
if (xKey.Value != null) xnr.Attributes.Append(xKey);
|
||||
xKey = ResultsDoc.CreateAttribute("NewKey");
|
||||
xKey.Value = GetKey(atts2Par);
|
||||
if (xKey.Value != null) xnr.Attributes.Append(xKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
// go through attributes in 2nd xml document to see if they exist in the first xml document & are identical
|
||||
foreach (XmlAttribute xa2 in atts2)
|
||||
{
|
||||
XmlAttribute xa1 = atts1.GetNamedItem(xa2.Name) as XmlAttribute;
|
||||
if (xa1 == null)
|
||||
{
|
||||
XmlNode xnr = MakeXPathFormat(path);
|
||||
if (xnr != null)
|
||||
{
|
||||
XmlAttribute xKey = ResultsDoc.CreateAttribute(xa2.Name+"New");
|
||||
xKey.Value = xa2.Value;
|
||||
xnr.Attributes.Append(xKey);
|
||||
xKey = ResultsDoc.CreateAttribute("NewKey");
|
||||
xKey.Value = GetKey(atts2Par);
|
||||
if (xKey.Value != null) xnr.Attributes.Append(xKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(atts1.GetNamedItem(xa2.Name) is XmlAttribute))
|
||||
{
|
||||
XmlNode xnr = MakeXPathFormat(path);
|
||||
if (xnr != null)
|
||||
{
|
||||
XmlAttribute xKey = ResultsDoc.CreateAttribute(xa2.Name + "New");
|
||||
xKey.Value = xa2.Value;
|
||||
xnr.Attributes.Append(xKey);
|
||||
xKey = ResultsDoc.CreateAttribute("NewKey");
|
||||
xKey.Value = GetKey(atts2Par);
|
||||
if (xKey.Value != null) xnr.Attributes.Append(xKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user