System.Xml.XmlDocument.CreateElement(string)

Here are the examples of the csharp api System.Xml.XmlDocument.CreateElement(string) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

629 Examples 7

19 Source : BrushInfo.cs
with MIT License
from cwensley

public void WriteXml(XmlElement element)
		{
			if (encoding != null)
				element.SetAttribute("codepage", encoding.CodePage);
			foreach (var ch in characters)
			{
				var childElement = element.OwnerDoreplacedent.CreateElement("char");
				childElement.SetAttribute("value", (int)ch.character);
				element.AppendChild(childElement);
			}
		}

19 Source : CharacterDocumentInfo.cs
with MIT License
from cwensley

public override void WriteXml(XmlElement element)
		{
			base.WriteXml(element);
			element.SetAttribute("use9x", use9x);
			element.SetAttribute("dosAspect", dosAspect);
			element.SetAttribute("iceColours", iceColours);
			element.SetAttribute("insertMode", insertMode);
			element.SetAttribute("shiftSelect", shiftSelect);
			element.WriteChildSizeXml("attribute-dialog", AttributeDialogSize);
			element.WriteChildRectangleXml("attribute-dialog-bounds", AttributeDialogBounds);

			element.WriteChildListXml(brushes, "brush", "brushes");

			XmlElement charElement = element.OwnerDoreplacedent.CreateElement("characterSets");
			for (int set = 0; set < characterSets.GetLength(0); set++)
			{
				XmlElement charSet = charElement.OwnerDoreplacedent.CreateElement("characterSet");
				charSet.SetAttribute("set", set.ToString());

				for (int i = 0; i < characterSets.GetLength(1); i++)
				{
					charSet.SetAttribute("f" + Convert.ToString(i + 1), characterSets[set, i].ToString());
				}

				charElement.AppendChild(charSet);
			}
			element.AppendChild(charElement);
		}

19 Source : DocumentInfo.cs
with MIT License
from cwensley

public virtual void WriteXml(XmlElement element)
		{
			if (!AutoScroll)
				element.SetAttribute ("autoscroll", AutoScroll);
			XmlElement formatsElement = element.OwnerDoreplacedent.CreateElement("formats");
			formats.WriteXml(formatsElement);
			element.AppendChild(formatsElement);
			XmlElement zoomInfoElement = element.OwnerDoreplacedent.CreateElement("zoomInfo");
			zoomInfo.WriteXml(zoomInfoElement);
			element.AppendChild(zoomInfoElement);
		}

19 Source : DocumentInfo.cs
with MIT License
from cwensley

public void WriteXml(XmlElement element)
		{
			foreach (DoreplacedentInfo info in Values)
			{
				XmlElement infoElement = element.OwnerDoreplacedent.CreateElement("doreplacedentInfo");
				infoElement.SetAttribute("infoId", info.ID);
				info.WriteXml(infoElement);
				
				element.AppendChild(infoElement);
			}
		}

19 Source : Format.cs
with MIT License
from cwensley

public void WriteXml (XmlElement element)
        {
            foreach (Format info in this.Values) {
                XmlElement infoElement = element.OwnerDoreplacedent.CreateElement ("formatInfo");
                infoElement.SetAttribute ("infoId", info.ID);
                info.WriteXml (infoElement);
             
                element.AppendChild (infoElement);
            }
        }

19 Source : Main.cs
with MIT License
from cwensley

public void WriteXml()
        {
            try
            {
                if (EditMode)
                    Settings.EditFileSplit = splitter.Position;
                else
                    Settings.FileSplit = splitter.Position;


                var doc = new XmlDoreplacedent();
                var head = doc.CreateElement("pablo");

                Settings.WriteXml(head);


                var elem = doc.CreateElement("main");
                if (FileList.CurrentDirectory != null)
                {
                    var dir = FileList.CurrentDirectory;
                    while (dir is VirtualDirectoryInfo)
                    {
                        var file = ((VirtualDirectoryInfo)dir).FileInfo;
                        if (file == null)
                            break;
                        dir = file.Directory;
                    }
                    elem.SetAttribute("path", dir.FullName);
                }
                head.AppendChild(elem);

                head.WriteChildXml("main-window", new WindowStateSaver(this));


                doc.AppendChild(head);
                doc.Save(SettingsFile);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Error! {0}", ex);
            }

        }

19 Source : XmlExtensions.cs
with MIT License
from cwensley

public static void WriteChildXml<T>(this XmlElement element, string childElementName, T child)
			where T : IXmlReadable
		{
			if (EqualityComparer<T>.Default.Equals(child, default(T))) return;
			var childElement = element.OwnerDoreplacedent.CreateElement(childElementName);
			child.WriteXml(childElement);
			element.AppendChild(childElement);
		}

19 Source : XmlExtensions.cs
with MIT License
from cwensley

public static void WriteChildListXml<T>(this XmlElement element, IEnumerable<T> list, string childElement, string listElement = null)
			where T : IXmlReadable
		{
			XmlElement listNode = (!string.IsNullOrEmpty(listElement)) ? element.OwnerDoreplacedent.CreateElement(listElement) : element;

			foreach (T child in list)
			{
				if (!EqualityComparer<T>.Default.Equals(child, default(T)))
				{
					var childNode = element.OwnerDoreplacedent.CreateElement(childElement);
					child.WriteXml(childNode);
					listNode.AppendChild(childNode);
				}
			}

			if (listNode != element && !listNode.IsEmpty)
			{
				element.AppendChild(listNode);
			}
		}

19 Source : XmlExtensions.cs
with MIT License
from cwensley

public static void SaveXml(this IXmlReadable obj, Stream stream, string doreplacedentElementName = "object")
		{
			var doc = new XmlDoreplacedent();
			var topNode = doc.CreateElement(doreplacedentElementName);
			obj.WriteXml(topNode);
			doc.AppendChild(topNode);
			doc.Save(stream);
		}

19 Source : PrinterSettingInfoOp.cs
with GNU General Public License v3.0
from cymheart

public void AddPrinterSettingToFile(PrinterSettingInfo printerSettingInfo)
        {
            XmlDoreplacedent xmlDoc = new XmlDoreplacedent();
            XmlElement root;

            if (File.Exists(printerSettingPath))
            {
                xmlDoc.Load(printerSettingPath);//加载xml
            }
            else
            {
                XmlDeclaration xmldecl;
                xmldecl = xmlDoc.CreateXmlDeclaration("1.0", "gb2312", null);
                xmlDoc.AppendChild(xmldecl);

                //加入一个根元素     
                root = xmlDoc.CreateElement("Root");//创建一个<Root>节点 
                root.SetAttribute("name", "打印模块对应设置信息");//设置该节点genre属性 
                root.SetAttribute("ISBN", "2-3631-4");//设置该节点ISBN属性
                xmlDoc.AppendChild(root);

                XmlElement xesub1 = xmlDoc.CreateElement("Row");
                xesub1.SetAttribute("PrintModuleKey", printerSettingInfo.printModuleKey);//设置该节点打印模块关键字属性 
                xesub1.SetAttribute("PrinterName", printerSettingInfo.printerName);//设置该节点打印机名称属性 
                xesub1.SetAttribute("PageName", printerSettingInfo.pageName);
                xesub1.SetAttribute("PageSizeWidth", printerSettingInfo.pageSize.Width.ToString());//设置该节点打印机页面尺寸宽度属性 
                xesub1.SetAttribute("PageSizeHeight", printerSettingInfo.pageSize.Height.ToString());//设置该节点打印机页面尺寸高度属性        
                xesub1.SetAttribute("ExSettingFileName", printerSettingInfo.exSettingFileName);//设置该节点打印机扩展属性文件路径 
                root.AppendChild(xesub1);

                //保存创建好的XML文档
                Utils.CreateDir(printerSettingPath);
                xmlDoc.Save(printerSettingPath);
                return;
            }


            XmlNodeList xmlList = xmlDoc.GetElementsByTagName("Root"); //取得节点名为Root的XmlNode集合
            foreach (XmlNode xmlNode in xmlList)
            {
                XmlNodeList childList = xmlNode.ChildNodes; //取得row节点集合

                foreach (XmlNode cxmlNode in childList)
                {
                    if (cxmlNode.Attributes["PrintModuleKey"].Value == printerSettingInfo.printModuleKey)
                    {
                        cxmlNode.Attributes["PrinterName"].Value = printerSettingInfo.printerName;//设置该节点打印机名称属性 

                        cxmlNode.Attributes["PageName"].Value = printerSettingInfo.pageName;
                        cxmlNode.Attributes["PageSizeWidth"].Value = printerSettingInfo.pageSize.Width.ToString();//设置该节点打印机页面尺寸宽度属性 
                        cxmlNode.Attributes["PageSizeHeight"].Value = printerSettingInfo.pageSize.Height.ToString();//设置该节点打印机页面尺寸高度属性        

                        cxmlNode.Attributes["ExSettingFileName"].Value = printerSettingInfo.exSettingFileName;//设置该节点打印机扩展属性文件路径 
                        xmlDoc.Save(printerSettingPath);
                        return;
                    }
                }
            }

            XmlNodeList list = xmlDoc.GetElementsByTagName("Root");//创建一个<Node>节点 
            XmlNode rootx = list[0];
            XmlElement xesub = xmlDoc.CreateElement("Row");

            xesub.SetAttribute("PrintModuleKey", printerSettingInfo.printModuleKey);//设置该节点打印模块关键字属性 
            xesub.SetAttribute("PrinterName", printerSettingInfo.printerName);//设置该节点打印机名称属性 
            xesub.SetAttribute("PageName", printerSettingInfo.pageName);
            xesub.SetAttribute("PageSizeWidth", printerSettingInfo.pageSize.Width.ToString());//设置该节点打印机页面尺寸宽度属性 
            xesub.SetAttribute("PageSizeHeight", printerSettingInfo.pageSize.Height.ToString());//设置该节点打印机页面尺寸高度属性        
            xesub.SetAttribute("ExSettingFileName", printerSettingInfo.exSettingFileName);//设置该节点打印机扩展属性文件路径 
            rootx.AppendChild(xesub);

            //保存创建好的XML文档
            xmlDoc.Save(printerSettingPath);
        }

19 Source : PrintModuleInfoOp.cs
with GNU General Public License v3.0
from cymheart

public void AddPrintModuleToFile(PrintModuleInfo printModuleInfo)
        {
            XmlDoreplacedent xmlDoc = new XmlDoreplacedent();
            XmlElement root;

            if (File.Exists(printModuleSetPath))
            {
                xmlDoc.Load(printModuleSetPath);//加载xml
            }
            else
            {
                XmlDeclaration xmldecl;
                xmldecl = xmlDoc.CreateXmlDeclaration("1.0", "gb2312", null);
                xmlDoc.AppendChild(xmldecl);

                //加入一个根元素     
                root = xmlDoc.CreateElement("Root");//创建一个<Root>节点 
                root.SetAttribute("name", "打印模块信息设置");//设置该节点genre属性 
                root.SetAttribute("ISBN", "2-3631-4");//设置该节点ISBN属性
                xmlDoc.AppendChild(root);

                XmlElement xesub1 = xmlDoc.CreateElement("Row");
                xesub1.SetAttribute("key", printModuleInfo.key);//设置该节点key属性 
                xesub1.SetAttribute("name", printModuleInfo.name);//设置该节点name属性 
                root.AppendChild(xesub1);

                //保存创建好的XML文档
                Utils.CreateDir(printModuleSetPath);
                xmlDoc.Save(printModuleSetPath);
                return;
            }


            XmlNodeList xmlList = xmlDoc.GetElementsByTagName("Root"); //取得节点名为Root的XmlNode集合
            foreach (XmlNode xmlNode in xmlList)
            {
                XmlNodeList childList = xmlNode.ChildNodes; //取得row节点集合

                foreach (XmlNode cxmlNode in childList)
                {
                    if (cxmlNode.Attributes["key"].Value == printModuleInfo.key)
                    {
                        cxmlNode.Attributes["name"].Value = printModuleInfo.name;
                        xmlDoc.Save(printModuleSetPath);
                        return;
                    }
                }
            }

            XmlNodeList list = xmlDoc.GetElementsByTagName("Root");//创建一个<Node>节点 
            XmlNode rootx = list[0];
            XmlElement xesub = xmlDoc.CreateElement("Row");

            xesub.SetAttribute("key", printModuleInfo.key);//设置该节点key属性 
            xesub.SetAttribute("name", printModuleInfo.name);//设置该节点name属性 
            rootx.AppendChild(xesub);

            //保存创建好的XML文档
            xmlDoc.Save(printModuleSetPath);
        }

19 Source : PrinterDefaultSettingOp.cs
with GNU General Public License v3.0
from cymheart

public void SetDefaultXmlFile(string defaultSetFilePath)
        {
            XmlDoreplacedent xmlDoc = new XmlDoreplacedent();
          
            if (File.Exists(defaultSetPath))
            {
                xmlDoc.Load(defaultSetPath);//加载xml
            }
            else
            {
                XmlDeclaration xmldecl;
                xmldecl = xmlDoc.CreateXmlDeclaration("1.0", "gb2312", null);
                xmlDoc.AppendChild(xmldecl);

                //加入一个根元素     
                XmlElement root = xmlDoc.CreateElement("Node");//创建一个<Node>节点 
                root.SetAttribute("name", "默认设置");//设置该节点genre属性 
                root.SetAttribute("ISBN", "2-3631-4");//设置该节点ISBN属性
                xmlDoc.AppendChild(root);

                XmlElement xesub1 = xmlDoc.CreateElement("Row");
                xesub1.SetAttribute("name", "默认内容文件路径");//设置该节点genre属性 
                xesub1.InnerText = defaultSetFilePath;
                root.AppendChild(xesub1);

                //保存创建好的XML文档
                Utils.CreateDir(defaultSetPath);
                xmlDoc.Save(defaultSetPath);
                return;
            }


            XmlNodeList xmlList = xmlDoc.GetElementsByTagName("Node"); //取得节点名为Node的XmlNode集合
            foreach (XmlNode xmlNode in xmlList)
            {
                XmlNodeList childList = xmlNode.ChildNodes; //取得row节点集合

                foreach (XmlNode cxmlNode in childList)
                {
                    if (cxmlNode.Attributes["name"].Value == "默认内容文件路径")
                    {
                        cxmlNode.InnerText = defaultSetFilePath;

                        //保存创建好的XML文档
                        xmlDoc.Save(defaultSetPath);

                        return;
                    }
                }
            }


            XmlNodeList list = xmlDoc.GetElementsByTagName("Node");//创建一个<Node>节点 
            XmlNode rootx = list[0];
            XmlElement xesub = xmlDoc.CreateElement("Row");
            xesub.SetAttribute("name", "默认内容文件路径");//设置该节点name属性 
            xesub.InnerText = defaultSetFilePath;
            rootx.AppendChild(xesub);

            //保存创建好的XML文档
            xmlDoc.Save(defaultSetPath);
        }

19 Source : PrinterDefaultSettingOp.cs
with GNU General Public License v3.0
from cymheart

public void SetDefaultXmlSize(SizeF defaultSize)
        {
            XmlDoreplacedent xmlDoc = new XmlDoreplacedent();
            XmlElement root;

            if (File.Exists(defaultSetPath))
            {
                xmlDoc.Load(defaultSetPath);//加载xml
            }
            else
            {
                XmlDeclaration xmldecl;
                xmldecl = xmlDoc.CreateXmlDeclaration("1.0", "gb2312", null);
                xmlDoc.AppendChild(xmldecl);

                //加入一个根元素     
                root = xmlDoc.CreateElement("Node");//创建一个<Node>节点 
                root.SetAttribute("name", "默认设置文件路径");//设置该节点genre属性 
                root.SetAttribute("ISBN", "2-3631-4");//设置该节点ISBN属性
                xmlDoc.AppendChild(root);

                XmlElement xesub1 = xmlDoc.CreateElement("Row");
                xesub1.SetAttribute("name", "尺寸");//设置该节点name属性 
                xesub1.SetAttribute("width", defaultSize.Width.ToString());//设置该节点name属性 
                xesub1.SetAttribute("height", defaultSize.Height.ToString());//设置该节点name属性 
                root.AppendChild(xesub1);

                //保存创建好的XML文档
                Utils.CreateDir(defaultSetPath);
                xmlDoc.Save(defaultSetPath);
                return;
            }


            XmlNodeList xmlList = xmlDoc.GetElementsByTagName("Node"); //取得节点名为Node的XmlNode集合
            foreach (XmlNode xmlNode in xmlList)
            {
                XmlNodeList childList = xmlNode.ChildNodes; //取得row节点集合

                foreach (XmlNode cxmlNode in childList)
                {
                    if (cxmlNode.Attributes["name"].Value == "尺寸")
                    {
                                      cxmlNode.Attributes["width"].Value = defaultSize.Width.ToString();
                        cxmlNode.Attributes["height"].Value = defaultSize.Height.ToString();

                        //保存创建好的XML文档
                        xmlDoc.Save(defaultSetPath);
                        return;
                    }
                }
            }

            XmlNodeList list = xmlDoc.GetElementsByTagName("Node");//创建一个<Node>节点 
            XmlNode rootx = list[0];
            XmlElement xesub = xmlDoc.CreateElement("Row");
            xesub.SetAttribute("name", "尺寸");//设置该节点name属性 
            xesub.SetAttribute("width", defaultSize.Width.ToString());//设置该节点name属性 
            xesub.SetAttribute("height", defaultSize.Height.ToString());//设置该节点name属性 
            rootx.AppendChild(xesub);

            //保存创建好的XML文档
            xmlDoc.Save(defaultSetPath);

        }

19 Source : PrinterDefaultSettingOp.cs
with GNU General Public License v3.0
from cymheart

public void SetDefaultXmlPrinter(string defaultPrinter)
        {
            XmlDoreplacedent xmlDoc = new XmlDoreplacedent();
 
            if (File.Exists(defaultSetPath))
            {
                xmlDoc.Load(defaultSetPath);//加载xml
            }
            else
            {
                XmlDeclaration xmldecl;
                xmldecl = xmlDoc.CreateXmlDeclaration("1.0", "gb2312", null);
                xmlDoc.AppendChild(xmldecl);

                //加入一个根元素     
                XmlElement root = xmlDoc.CreateElement("Node");//创建一个<Node>节点 
                root.SetAttribute("name", "默认设置");//设置该节点genre属性 
                root.SetAttribute("ISBN", "2-3631-4");//设置该节点ISBN属性
                xmlDoc.AppendChild(root);

                XmlElement xesub1 = xmlDoc.CreateElement("Row");
                xesub1.SetAttribute("name", "默认打印机");//设置该节点genre属性 
                xesub1.InnerText = defaultPrinter;
                root.AppendChild(xesub1);

                //保存创建好的XML文档
                Utils.CreateDir(defaultSetPath);
                xmlDoc.Save(defaultSetPath);
                return;
            }


            XmlNodeList xmlList = xmlDoc.GetElementsByTagName("Node"); //取得节点名为Node的XmlNode集合
            foreach (XmlNode xmlNode in xmlList)
            {
                XmlNodeList childList = xmlNode.ChildNodes; //取得row节点集合

                foreach (XmlNode cxmlNode in childList)
                {
                    if (cxmlNode.Attributes["name"].Value == "默认打印机")
                    {
                        cxmlNode.InnerText = defaultPrinter;

                        //保存创建好的XML文档
                        xmlDoc.Save(defaultSetPath);

                        return;
                    }
                }
            }


            XmlNodeList list = xmlDoc.GetElementsByTagName("Node");//创建一个<Node>节点 
            XmlNode rootx = list[0];
            XmlElement xesub = xmlDoc.CreateElement("Row");
            xesub.SetAttribute("name", "默认打印机");//设置该节点name属性 
            xesub.InnerText = defaultPrinter;
            rootx.AppendChild(xesub);

            //保存创建好的XML文档
            xmlDoc.Save(defaultSetPath);
        }

19 Source : PrinterPreSettingOp.cs
with GNU General Public License v3.0
from cymheart

public void AddPrinterPreSettingFile(string fileName)
        {
            XmlDoreplacedent xmlDoc = new XmlDoreplacedent();
            XmlElement root;

            if (File.Exists(printerSetPath))
            {
                xmlDoc.Load(printerSetPath);//加载xml
            }
            else
            {
                XmlDeclaration xmldecl;
                xmldecl = xmlDoc.CreateXmlDeclaration("1.0", "gb2312", null);
                xmlDoc.AppendChild(xmldecl);

                //加入一个根元素     
                root = xmlDoc.CreateElement("Node");//创建一个<Node>节点 
                root.SetAttribute("name", "默认设置");//设置该节点genre属性 
                root.SetAttribute("ISBN", "2-3631-4");//设置该节点ISBN属性
                xmlDoc.AppendChild(root);

                XmlElement xesub1 = xmlDoc.CreateElement("Row");
                xesub1.SetAttribute("RegeditKey", "");//设置该节点name属性 
                xesub1.SetAttribute("Domain", "");//设置该节点name属性 
                xesub1.SetAttribute("SubKey", "");//设置该节点name属性 
                xesub1.InnerText = fileName;
                root.AppendChild(xesub1);

                //保存创建好的XML文档
                Utils.CreateDir(printerSetPath);
                xmlDoc.Save(printerSetPath);
                return;
            }


            XmlNodeList xmlList = xmlDoc.GetElementsByTagName("Node"); //取得节点名为Node的XmlNode集合
            foreach (XmlNode xmlNode in xmlList)
            {
                XmlNodeList childList = xmlNode.ChildNodes; //取得row节点集合

                foreach (XmlNode cxmlNode in childList)
                {
                    if (cxmlNode.InnerText.Equals(fileName))
                        return;
                }
            }

            XmlNodeList list = xmlDoc.GetElementsByTagName("Node");//创建一个<Node>节点 
            XmlNode rootx = list[0];
            XmlElement xesub = xmlDoc.CreateElement("Row");

            xesub.SetAttribute("RegeditKey", "");//设置该节点name属性 
            xesub.SetAttribute("Domain", "");//设置该节点name属性 
            xesub.SetAttribute("SubKey", "");//设置该节点name属性 
            xesub.InnerText = fileName;
            rootx.AppendChild(xesub);

            //保存创建好的XML文档
            xmlDoc.Save(printerSetPath);

        }

19 Source : MeshHe2.cs
with GNU General Public License v3.0
from dd-bim

public void WriteSvg(string fileName, 
            string fill = "green", 
            string stroke = "black", 
            string stroke_width = "1")
        {
            double minx = double.MaxValue, maxx = -double.MaxValue,
                miny = double.MaxValue, maxy = -double.MaxValue;
            foreach (var p in Points)
            {
                if (p.X < minx)
                { minx = p.X; }
                if (p.X > maxx)
                { maxx = p.X; }
                if (p.Y < miny)
                { miny = p.Y; }
                if (p.Y > maxy)
                { maxy = p.Y; }
            }
            int width = (int)Math.Ceiling((maxx - minx) / minDist);
            int height = (int)Math.Ceiling((maxy - miny) / minDist);

            var doreplacedent = new XmlDoreplacedent();
            var root = doreplacedent.CreateElement("svg");
            doreplacedent.AppendChild(root);
            root.SetAttribute("xmlns", "http://www.w3.org/2000/svg");
            root.SetAttribute("width", width.ToString());
            root.SetAttribute("height", height.ToString());
            root.SetAttribute("stroke", stroke);
            root.SetAttribute("fill", fill);
            root.SetAttribute("stroke-width", stroke_width);

            foreach (var poly in Polygons)
            {
                var pa = doreplacedent.CreateElement("path");
                pa.SetAttribute("fill-rule", "nonzero");//nonzero?
                StringBuilder sb = new StringBuilder("M");
                var he = poly.Exterior;
                do
                {
                    var p = Points[he.Point];
                    int x = (int)Math.Round((p.X - minx) / minDist);
                    int y = (int)Math.Round((maxy - p.Y) / minDist);
                    sb.Append(x + " " + y + " L");
                    he = he.Next;
                } while (he != poly.Exterior);
                sb[sb.Length - 1] = 'Z';
                foreach (var first in poly.Interiors)
                {
                    sb.AppendLine();
                    sb.Append("M");
                    he = first;
                    do
                    {
                        var p = Points[he.Point];
                        int x = (int)Math.Round((p.X - minx) / minDist);
                        int y = (int)Math.Round((maxy - p.Y) / minDist);
                        sb.Append(x + " " + y + " L");
                        he = he.Next;
                    } while (he != first);
                    sb[sb.Length - 1] = 'Z';
                }
                pa.SetAttribute("d", sb.ToString());
                root.AppendChild(pa);
            }

            doreplacedent.Save(fileName + ".svg");
        }

19 Source : Obfuscator.cs
with MIT License
from Dentrax

protected override void AsyncStartObfuscation() {
            List<string> replacedembliesPaths = new List<string>();
            List<bool> replacedembliesToObfuscate = new List<bool>();

            LogProgress("[0]: Starting...");

            this.m_xmlDoreplacedent = new XmlDoreplacedent();
            this.m_xmlElement = this.m_xmlDoreplacedent.CreateElement("mappings");
            this.m_xmlDoreplacedent.AppendChild(m_xmlElement);

            UpdateProgress("[1]: Loading replacedemblies...", 10);
            foreach (string replacedemblyPath in m_replacedemblies.Keys) {
                try {
                    replacedemblyDefinition replacedembly = replacedemblyDefinition.Readreplacedembly(replacedemblyPath);
                    foreach (ModuleDefinition module in replacedembly.Modules)
                        LogProgress($"[OK]: Module loaded: {module.Name}");

                    this.m_replacedemblyDefinitions.Add(replacedembly);
                    replacedembliesPaths.Add(Path.GetFileName(replacedemblyPath));
                    replacedembliesToObfuscate.Add(m_replacedemblies[replacedemblyPath]);
                } catch (Exception ex) {
                    LogProgress($"[ERR]: Module load failed: {ex.Message}");
                    continue;
                }
            }

            UpdateProgress("[2]: Starting obfuscate...", 20);

            int progressCurrent = 20;
            int progressIncrement = 60 / this.m_replacedemblyDefinitions.Count;

            int replacedemblyIndex = -1;
            foreach (replacedemblyDefinition replacedembly in m_replacedemblyDefinitions) {
                replacedemblyIndex++;

                if (!replacedembliesToObfuscate[replacedemblyIndex])
                    continue;

                LogProgress("Obfuscating replacedembly: " + replacedembly.Name.Name);

                LogProgress("Obfuscating Types");
                foreach (TypeDefinition type in replacedembly.MainModule.Types)
                    DoObfuscateType(type);

                if (m_obfuscationInfo.ObfuscateNamespaces)
                    LogProgress("Obfuscating Namespaces");
                    foreach (TypeDefinition type in replacedembly.MainModule.Types)
                        DoObfuscateNamespace(type);

                if (m_obfuscationInfo.ObfuscateResources)
                    LogProgress("Obfuscating Resources");
                    foreach (Resource resource in replacedembly.MainModule.Resources)
                        DoObfuscateResource(resource);

                progressCurrent += progressIncrement;
            }

            UpdateProgress("[3]: Saving replacedembly...", 80);

            replacedemblyIndex = -1;
            foreach (replacedemblyDefinition replacedembly in m_replacedemblyDefinitions) {
                replacedemblyIndex++;

                if (Directory.Exists(this.m_obfuscationInfo.OutputDirectory) == false)
                    Directory.CreateDirectory(this.m_obfuscationInfo.OutputDirectory);

                string outputFileName = Path.Combine(this.m_obfuscationInfo.OutputDirectory, "Obfuscated_" + replacedembliesPaths[replacedemblyIndex]);

                if (File.Exists(outputFileName))
                    File.Delete(outputFileName);

                replacedembly.Write(outputFileName);
            }

            this.m_xmlDoreplacedent.Save(Path.Combine(m_obfuscationInfo.OutputDirectory, "Mapping.xml"));

            UpdateProgress("[4]: Testing replacedembly...", 90);

            foreach (string replacedemblyPath in this.m_replacedemblies.Keys) {
                if (!File.Exists(replacedemblyPath)) {
                    LogProgress($"[FAIL]: File not exists: {replacedemblyPath}");
                    continue;
                }

                try {
                    replacedemblyDefinition replacedembly = replacedemblyDefinition.Readreplacedembly(replacedemblyPath);
                    foreach (ModuleDefinition module in replacedembly.Modules)
                        LogProgress($"[OK]: {module.Name}");

                } catch (Exception ex) {
                    LogProgress($"[FAIL]: {replacedemblyPath} - Exception: {ex.Message}");
                }

            }

            UpdateProgress("[5]: Complete.", 100);
        }

19 Source : Obfuscator.cs
with MIT License
from Dentrax

void AddToXMLMap(ObfuscationItem item, string initialName, String obfuscated) {
            XmlElement element = this.m_xmlDoreplacedent.CreateElement("mapping");
            this.m_xmlElement.AppendChild(element);
            element.SetAttribute("Type", item.ToString());
            element.SetAttribute("InitialValue", initialName);
            element.SetAttribute("ObfuscatedValue", obfuscated);
        }

19 Source : Document.cs
with MIT License
from dhodges47

public static XmlNode CreateTemporaryDomNode()
		{
			string tmpName = "_" + tmpNameCounter++;
			if (tmpFragment == null)
			{
				tmpFragment = GetTemporaryDoreplacedent().CreateDoreplacedentFragment();
				tmpDoreplacedent.AppendChild(tmpFragment);
			}

			XmlNode node = GetTemporaryDoreplacedent().CreateElement(tmpName);
			tmpFragment.AppendChild(node);
			return node;
		}

19 Source : HomeController.cs
with MIT License
from dinazil

public ActionResult About()
        {
            var doc = new XmlDoreplacedent();
            doc.AppendChild(doc.CreateElement("root"));
            for (int i = 0; i < 100000; ++i)
            {
                doc.DoreplacedentElement.AppendChild(doc.CreateElement("element" + i));
            }
            doc.OuterXml.ToString();

            ViewBag.Message = "About us.";

            return View();
        }

19 Source : DataForge.cs
with MIT License
from dolkensp

internal void Compile()
		{
			var root = this._xmlDoreplacedent.CreateElement("DataForge");
			this._xmlDoreplacedent.AppendChild(root);

			foreach (var dataMapping in this.Require_StrongMapping)
			{
				var strong = this.Array_StrongValues[dataMapping.RecordIndex];

				if (strong.Index == 0xFFFFFFFF)
				{
#if NONULL
					dataMapping.Node.ParentNode.RemoveChild(dataMapping.Node);
#else
                    dataMapping.Item1.ParentNode.ReplaceChild(
                        this._xmlDoreplacedent.CreateElement("null"),
                        dataMapping.Item1);
#endif
				}
				else
				{
					dataMapping.Node.ParentNode.ReplaceChild(
						this.DataMap[strong.StructType][(Int32)strong.Index],
						dataMapping.Node);
				}
			}

			foreach (var dataMapping in this.Require_WeakMapping1)
			{
				var weak = this.Array_WeakValues[dataMapping.RecordIndex];

				var weakAttribute = dataMapping.Node;

				if (weak.Index == 0xFFFFFFFF)
				{
					weakAttribute.Value = String.Format("0");
				}
				else
				{
					var targetElement = this.DataMap[weak.StructType][(Int32)weak.Index];

					weakAttribute.Value = targetElement.GetPath();
				}
			}

			foreach (var dataMapping in this.Require_WeakMapping2)
			{
				var weakAttribute = dataMapping.Node;

				if (dataMapping.StructIndex == 0xFFFF)
				{
					weakAttribute.Value = "null";
				}
				else if (dataMapping.RecordIndex == -1)
				{
					var targetElement = this.DataMap[dataMapping.StructIndex];

					weakAttribute.Value = targetElement.FirstOrDefault()?.GetPath();
				}
				else
				{
					var targetElement = this.DataMap[dataMapping.StructIndex][dataMapping.RecordIndex];

					weakAttribute.Value = targetElement.GetPath();
				}
			}

			var i = 0;
			foreach (var record in this.RecordDefinitionTable)
			{
				var fileReference = record.FileName;

				if (fileReference.Split('/').Length == 2)
				{
					fileReference = fileReference.Split('/')[1];
				}

				if (!record.FileName.ToLowerInvariant().Contains(record.Name.ToLowerInvariant()) &&
					!record.FileName.ToLowerInvariant().Contains(record.Name.Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries).Last().ToLowerInvariant()))
				{
					Console.WriteLine("Warning {0} doesn't match {1}", record.Name, record.FileName);
				}

				if (String.IsNullOrWhiteSpace(fileReference))
				{
					fileReference = String.Format(@"Dump\{0}_{1}.xml", record.Name, i++);
				}

				if (record.Hash.HasValue && record.Hash != Guid.Empty)
				{
					var hash = this.CreateAttribute("__ref");
					hash.Value = $"{record.Hash}";
					this.DataMap[record.StructIndex][record.VariantIndex].Attributes.Append(hash);
				}

				if (!String.IsNullOrWhiteSpace(record.FileName))
				{
					var path = this.CreateAttribute("__path");
					path.Value = $"{record.FileName}";
					this.DataMap[record.StructIndex][record.VariantIndex].Attributes.Append(path);
				}
				
				this.DataMap[record.StructIndex][record.VariantIndex] = this.DataMap[record.StructIndex][record.VariantIndex].Rename(record.Name);
				root.AppendChild(this.DataMap[record.StructIndex][record.VariantIndex]);
			}
		}

19 Source : Extensions.cs
with MIT License
from dolkensp

public static XmlElement Rename(this XmlElement element, String name)
        {
            var buffer = element.OwnerDoreplacedent.CreateElement(cleanString.Replace(name, "_"));

            while (element.ChildNodes.Count > 0)
            {
                buffer.AppendChild(element.ChildNodes[0]);
            }

            while (element.Attributes.Count > 0)
            {
                XmlAttribute attribute = element.Attributes[0];
                buffer.Attributes.Append(attribute);
            }

            return buffer;
        }

19 Source : DataForge.cs
with MIT License
from dolkensp

internal XmlElement CreateElement(String name) { return this._xmlDoreplacedent.CreateElement(name); }

19 Source : SvgCacheManager.cs
with MIT License
from dotnet-campus

private XmlElement getCacheElm(Uri uri)
		{
			if(uri == lastUri && lastCacheElm != null)
			{
				return lastCacheElm;
			}
			else
			{
				//string xpath = "/cache/resource[@url='" + uri.ToString() + "']";
                string xpath = "/cache/resource[@url='" + uri.ToString().Replace("'", "'") + "']";
                XmlNode node = cacheDoc.SelectSingleNode(xpath);
				if(node != null)
				{
					lastCacheElm = node as XmlElement;
				}
				else
				{
					lastCacheElm = cacheDoc.CreateElement("resource");
					cacheDoc.DoreplacedentElement.AppendChild(lastCacheElm);
					lastCacheElm.SetAttribute("url", uri.ToString());
				}

				lastUri = uri;
				return lastCacheElm;
			}
		}

19 Source : Document.cs
with MIT License
from dotnet-campus

IElement IDoreplacedent.CreateElement(
            string tagName)
        {
            return (IElement)CreateElement(tagName);
        }

19 Source : WpfCacheManager.cs
with MIT License
from dotnet-campus

private XmlElement GetCacheElm(Uri uri)
		{
			if(uri == lastUri && lastCacheElm != null)
			{
				return lastCacheElm;
			}
			else
			{
				//string xpath = "/cache/resource[@url='" + uri.ToString() + "']";
                string xpath = "/cache/resource[@url='" + uri.ToString().Replace("'", "'") + "']";
                XmlNode node = cacheDoc.SelectSingleNode(xpath);
				if(node != null)
				{
					lastCacheElm = node as XmlElement;
				}
				else
				{
					lastCacheElm = cacheDoc.CreateElement("resource");
					cacheDoc.DoreplacedentElement.AppendChild(lastCacheElm);
					lastCacheElm.SetAttribute("url", uri.ToString());
				}

				lastUri = uri;
				return lastCacheElm;
			}
		}

19 Source : AndroidXMLConverter.cs
with MIT License
from DotNetPlus

public static XmlDoreplacedent ReswToAndroidXML(
          ReswInfo reswInfo,
          bool supportPluralization = false)
        {
            Dictionary<string, List<ReswItem>> groupedItems;
            if (supportPluralization)
            {
                groupedItems = (from item in reswInfo.Items let simplifiedKey = ExtractReswKey(item.Key) group item by simplifiedKey into groupItem select groupItem).ToDictionary(k => k.Key, k => k.Select(j => j).ToList());
            }
            else
            {
                groupedItems = reswInfo.Items.ToDictionary(p => p.Key, p => new List<ReswItem>() { p });
            }

            var androidXML = new XmlDoreplacedent();
            var resourcesNode = androidXML.CreateElement("resources");
            androidXML.AppendChild(androidXML.CreateComment("smartling.instruction_comments_enabled = on"));
            androidXML.AppendChild(androidXML.CreateComment(@"smartling.placeholder_format_custom = \{\d\}"));
            androidXML.AppendChild(resourcesNode);

            foreach (var resourceItem in groupedItems.OrderBy(k => k.Key))
            {
                switch (resourceItem.Value.Count)
                {
                    case 0:
                        break;
                    case 1:
                        {
                            var valueNode = resourceItem.Value.First();
                            if (valueNode.Comment != null)
                            {
                                resourcesNode.AppendChild(androidXML.CreateComment(valueNode.Comment));
                            }

                            var stringNode = androidXML.CreateElement("string");
                            stringNode.SetAttribute("name", resourceItem.Key);
                            stringNode.AppendChild(androidXML.CreateTextNode(valueNode.Value));

                            resourcesNode.AppendChild(stringNode);
                        }
                        break;
                    default:
                        {
                            var pluralsNode = androidXML.CreateElement("plurals");
                            pluralsNode.SetAttribute("name", resourceItem.Key);
                            foreach (var reswItem in resourceItem.Value)
                            {
                                if (reswItem.Comment != null)
                                {
                                    pluralsNode.AppendChild(androidXML.CreateComment(reswItem.Comment));
                                }

                                var itemNode = androidXML.CreateElement("item");
                                var quanreplacedy = reswItem.Key.Split('_').Last().ToLower();
                                itemNode.SetAttribute("quanreplacedy", quanreplacedy);
                                itemNode.AppendChild(androidXML.CreateTextNode(reswItem.Value));
                                pluralsNode.AppendChild(itemNode);
                            }
                            resourcesNode.AppendChild(pluralsNode);
                        }
                        break;
                }
            }

            return androidXML;
        }

19 Source : ProjectTestContext.cs
with MIT License
from dragonglasscom

public void AddreplacedemblyReferences(IEnumerable<string> replacedemblyPaths)
        {
                /*
    <ItemGroup>
    <Reference Include="Cryptlet.Messages">
    <HintPath>..\..\..\Epiphyte\dotnet\Epiphyte\CryptletMessages\bin\Debug\netcoreapp2.0\Cryptlet.Messages.dll</HintPath>
    </Reference>
    </ItemGroup>
     */

                var projectDoc = new XmlDoreplacedent();
                projectDoc.Load(ProjectFilePath);
                var projectElement = projectDoc.DoreplacedentElement;
                var itemGroupElement = projectDoc.CreateElement("ItemGroup");
                projectElement.AppendChild(itemGroupElement);
                foreach (var dll in replacedemblyPaths)
                {
                    var referenceElement = projectDoc.CreateElement("Reference");
                    itemGroupElement.AppendChild(referenceElement);
                    var includeAttribute = projectDoc.CreateAttribute("Include");
                    includeAttribute.Value = Path.GetFileNameWithoutExtension(dll);
                    referenceElement.Attributes.Append(includeAttribute);
                    var hintPathElement = projectDoc.CreateElement("HintPath");
                    hintPathElement.InnerText = dll;
                    referenceElement.AppendChild(hintPathElement);
                }

                projectDoc.Save(ProjectFilePath);
        }

19 Source : ProjectTestContext.cs
with MIT License
from dragonglasscom

public void SetRootNamespaceInProject(string rootNamespace)
        {
            var projectDoc = new XmlDoreplacedent();
            projectDoc.Load(ProjectFilePath);
            var propertyGroupElement = projectDoc.DoreplacedentElement.SelectSingleNode("PropertyGroup");
            var rootNsElement = propertyGroupElement.SelectSingleNode("RootNamespace");
            if (rootNsElement == null)
            {
                rootNsElement = projectDoc.CreateElement("RootNamespace");
                propertyGroupElement.AppendChild(rootNsElement);
            }

            rootNsElement.InnerText = rootNamespace;
            projectDoc.Save(ProjectFilePath);
        }

19 Source : ProjectTestContext.cs
with MIT License
from dragonglasscom

public void SetreplacedemblyNameInProject(string rootNamespace)
        {
            var projectDoc = new XmlDoreplacedent();
            projectDoc.Load(ProjectFilePath);
            var propertyGroupElement = projectDoc.DoreplacedentElement.SelectSingleNode("PropertyGroup");
            var replacedemblyNameElement = propertyGroupElement.SelectSingleNode("replacedemblyName");
            if (replacedemblyNameElement == null)
            {
                replacedemblyNameElement = projectDoc.CreateElement("replacedemblyName");
                propertyGroupElement.AppendChild(replacedemblyNameElement);
            }

            replacedemblyNameElement.InnerText = rootNamespace;
            projectDoc.Save(ProjectFilePath);
        }

19 Source : ThriftConfig.cs
with Apache License 2.0
from duyanming

private bool Save()
        {
            try
            {
                XmlDoreplacedent xml = new XmlDoreplacedent();
                xml.Load(Path.Combine(Directory.GetCurrentDirectory(), AnnoFile));
                XmlNode servers = xml.SelectSingleNode("//configuration/Servers");//查找<Servers> 
                servers.RemoveAll();
                List<ServiceInfo> tempIps = new List<ServiceInfo>();
                ServiceInfoList.ForEach(p =>
                {
                    if (tempIps.FindAll(t => p.Ip == t.Ip && p.Port == t.Port).Count <= 0)
                    {
                        tempIps.Add(p);
                    }
                });
                tempIps.ForEach(p =>
                {
                    XmlElement xe = xml.CreateElement("dc");
                    xe.SetAttribute("name", p.Name);
                    xe.SetAttribute("nickname", p.NickName);
                    xe.SetAttribute("ip", p.Ip);
                    xe.SetAttribute("port", p.Port.ToString());
                    xe.SetAttribute("timeout", p.Timeout.ToString());
                    xe.SetAttribute("weight", p.Weight.ToString());
                    servers.AppendChild(xe);
                });
                xml.Save(Path.Combine(Directory.GetCurrentDirectory(), AnnoFile));
            }
            catch (Exception ex)
            {
                Log.Anno(ex, typeof(ThriftConfig));
                return false;
            }
            return true;
        }

19 Source : ThriftConfig.cs
with Apache License 2.0
from duyanming

private bool Save()
        {
            try
            {
                XmlDoreplacedent xml = new XmlDoreplacedent();
                xml.Load(Path.Combine(Directory.GetCurrentDirectory(), AnnoFile));
                XmlNode servers = xml.SelectSingleNode("//configuration/Servers");//查找<Servers> 
                servers.RemoveAll();
                List<ServiceInfo> tempIps = new List<ServiceInfo>();
                ServiceInfoList.ForEach(p =>
                {
                    if (tempIps.FindAll(t => p.Ip == t.Ip && p.Port == t.Port).Count <= 0)
                    {
                        tempIps.Add(p);
                    }
                });
                tempIps.ForEach(p =>
                {
                    XmlElement xe = xml.CreateElement("dc");
                    xe.SetAttribute("name", p.Name);
                    xe.SetAttribute("nickname", p.NickName);
                    xe.SetAttribute("ip", p.Ip);
                    xe.SetAttribute("port", p.Port.ToString());
                    xe.SetAttribute("timeout", p.Timeout.ToString());
                    xe.SetAttribute("weight", p.Weight.ToString());
                    servers.AppendChild(xe);
                });
                xml.Save(Path.Combine(Directory.GetCurrentDirectory(), AnnoFile));
            }
            catch (Exception ex)
            {
                Log.Anno(ex,typeof(ThriftConfig));
                return false;
            }
            return true;
        }

19 Source : Config.cs
with MIT License
from ecjtuseclab

public static void SetValue(string key, string value)
        {
            System.Xml.XmlDoreplacedent xDoc = new System.Xml.XmlDoreplacedent();
            xDoc.Load(HttpContext.Current.Server.MapPath("~/XmlConfig/system.config"));
            System.Xml.XmlNode xNode;
            System.Xml.XmlElement xElem1;
            System.Xml.XmlElement xElem2;
            xNode = xDoc.SelectSingleNode("//appSettings");

            xElem1 = (System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='" + key + "']");
            if (xElem1 != null) xElem1.SetAttribute("value", value);
            else
            {
                xElem2 = xDoc.CreateElement("add");
                xElem2.SetAttribute("key", key);
                xElem2.SetAttribute("value", value);
                xNode.AppendChild(xElem2);
            }
            xDoc.Save(HttpContext.Current.Server.MapPath("~/XmlConfig/system.config"));
        }

19 Source : Configs.cs
with MIT License
from ecjtuseclab

public static void SetValue(string key, string value)
        {
            System.Xml.XmlDoreplacedent xDoc = new System.Xml.XmlDoreplacedent();
            xDoc.Load(HttpContext.Current.Server.MapPath("~/Configs/system.config"));
            System.Xml.XmlNode xNode;
            System.Xml.XmlElement xElem1;
            System.Xml.XmlElement xElem2;
            xNode = xDoc.SelectSingleNode("//appSettings");

            xElem1 = (System.Xml.XmlElement)xNode.SelectSingleNode("//add[@key='" + key + "']");
            if (xElem1 != null) xElem1.SetAttribute("value", value);
            else
            {
                xElem2 = xDoc.CreateElement("add");
                xElem2.SetAttribute("key", key);
                xElem2.SetAttribute("value", value);
                xNode.AppendChild(xElem2);
            }
            xDoc.Save(HttpContext.Current.Server.MapPath("~/Configs/system.config"));
        }

19 Source : XMLUtils.cs
with Mozilla Public License 2.0
from ehsan2022002

public static string XmlEscape(string unescaped)
        {
            var doc = new XmlDoreplacedent();
            XmlNode node = doc.CreateElement("root");
            node.InnerText = unescaped;
            return node.InnerXml;
        }

19 Source : XmlUtilities.cs
with MIT License
from enricosada

internal static XmlElement RenameXmlElement(XmlElement oldElement, string newElementName, string xmlNamespace)
        {
            XmlElement newElement = (xmlNamespace == null)
                ? oldElement.OwnerDoreplacedent.CreateElement(newElementName)
                : oldElement.OwnerDoreplacedent.CreateElement(newElementName, xmlNamespace);

            // Copy over all the attributes.
            foreach (XmlAttribute oldAttribute in oldElement.Attributes)
            {
                XmlAttribute newAttribute = (XmlAttribute)oldAttribute.CloneNode(true);
                newElement.SetAttributeNode(newAttribute);
            }

            // Copy over all the child nodes.
            foreach (XmlNode oldChildNode in oldElement.ChildNodes)
            {
                XmlNode newChildNode = oldChildNode.CloneNode(true);
                newElement.AppendChild(newChildNode);
            }

            if (oldElement.ParentNode != null)
            {
                // Add the new element in the same place the old element was.
                oldElement.ParentNode.ReplaceChild(newElement, oldElement);
            }

            return newElement;
        }

19 Source : InvalidProjectfileException_Tests.cs
with MIT License
from enricosada

[Test]
        public void CtorArity4()
        {
            string message = "Message";
            InvalidProjectFileException invalidProjectFileException =
                    new InvalidProjectFileException(new XmlDoreplacedent().CreateElement("name"), message, "errorSubCategory", "errorCode", "HelpKeyword");
            replacedertion.replacedertEquals(String.Empty, invalidProjectFileException.ProjectFile);

            // preserve a bug in Orcas SP1:  if projectFile is empty but non-null, extra spaces get added to the message.
            replacedertion.replacedertEquals(message + "  ", invalidProjectFileException.Message);
            replacedertion.replacedertEquals("errorSubCategory", invalidProjectFileException.ErrorSubcategory);
            replacedertion.replacedertEquals("errorCode", invalidProjectFileException.ErrorCode);
            replacedertion.replacedertEquals("HelpKeyword", invalidProjectFileException.HelpKeyword);
            replacedertion.replacedertEquals(0, invalidProjectFileException.LineNumber);
            replacedertion.replacedertEquals(0, invalidProjectFileException.ColumnNumber);
        }

19 Source : InvalidProjectfileException_Tests.cs
with MIT License
from enricosada

[Test]
        [ExpectedException(typeof(ArgumentNullException))]
        public void CtorArity4_NullMessageString()
        {
            string message = null;
            InvalidProjectFileException invalidProjectFileException =
                    new InvalidProjectFileException(new XmlDoreplacedent().CreateElement("name"), message, "subcategory", "ErrorCode", "HelpKeyword");
            replacedertion.replacedertEquals(String.Empty, invalidProjectFileException.ProjectFile);
            replacedertion.replacedertEquals(message, invalidProjectFileException.Message);
            replacedertion.replacedertNull(invalidProjectFileException.ErrorSubcategory);
            replacedertion.replacedertEquals("ErrorCode", invalidProjectFileException.ErrorCode);
            replacedertion.replacedertEquals("HelpKeyword", invalidProjectFileException.HelpKeyword);
            replacedertion.replacedertEquals(0, invalidProjectFileException.LineNumber);
            replacedertion.replacedertEquals(0, invalidProjectFileException.ColumnNumber);
        }

19 Source : InvalidProjectfileException_Tests.cs
with MIT License
from enricosada

[Test]
        [ExpectedException(typeof(ArgumentException))]
        public void CtorArity4_EmptyMessageString()
        {
            string message = String.Empty;
            InvalidProjectFileException invalidProjectFileException =
                    new InvalidProjectFileException(new XmlDoreplacedent().CreateElement("Name"), message, String.Empty, String.Empty, String.Empty);
        }

19 Source : InvalidProjectfileException_Tests.cs
with MIT License
from enricosada

[Test]
        public void CtorArity4_EmptyStringOtherParams()
        {
            string message = "Message";
            InvalidProjectFileException invalidProjectFileException =
                    new InvalidProjectFileException(new XmlDoreplacedent().CreateElement("Name"), message, String.Empty, String.Empty, String.Empty);
            replacedertion.replacedertEquals(String.Empty, invalidProjectFileException.ProjectFile);

            // preserve a bug in Orcas SP1:  if projectFile is empty but non-null, extra spaces get added to the message.
            replacedertion.replacedertEquals(message + "  ", invalidProjectFileException.Message);
            replacedertion.replacedertEquals(String.Empty, invalidProjectFileException.ErrorSubcategory);
            replacedertion.replacedertEquals(String.Empty, invalidProjectFileException.ErrorCode);
            replacedertion.replacedertEquals(String.Empty, invalidProjectFileException.HelpKeyword);
            replacedertion.replacedertEquals(0, invalidProjectFileException.LineNumber);
            replacedertion.replacedertEquals(0, invalidProjectFileException.ColumnNumber);
        }

19 Source : InvalidProjectfileException_Tests.cs
with MIT License
from enricosada

[Test]
        public void CtorArity4_NullStringOtherParams()
        {
            string message = "Message";
            InvalidProjectFileException invalidProjectFileException =
                new InvalidProjectFileException(new XmlDoreplacedent().CreateElement("Name"), message, null, null, null);
            replacedertion.replacedertEquals(String.Empty, invalidProjectFileException.ProjectFile);

            // preserve a bug in Orcas SP1:  if projectFile is empty but non-null, extra spaces get added to the message.
            replacedertion.replacedertEquals(message + "  ", invalidProjectFileException.Message);
            replacedertion.replacedertEquals(null, invalidProjectFileException.ErrorSubcategory);
            replacedertion.replacedertEquals(null, invalidProjectFileException.ErrorCode);
            replacedertion.replacedertEquals(null, invalidProjectFileException.HelpKeyword);
        }

19 Source : BatchingEngine_Tests.cs
with MIT License
from enricosada

[Test]
        public void GetBuckets()
        {
            List<string> parameters = new List<string>();
            parameters.Add("@(File);$(unittests)");
            parameters.Add("$(obj)\\%(Filename).ext");
            parameters.Add("@(File->'%(extension)')");  // attributes in transforms don't affect batching

            Hashtable itemsByType = new Hashtable(StringComparer.OrdinalIgnoreCase);

            BuildItemGroup items = new BuildItemGroup();
            items.AddNewItem("File", "a.foo");
            items.AddNewItem("File", "b.foo");
            items.AddNewItem("File", "c.foo");
            items.AddNewItem("File", "d.foo");
            items.AddNewItem("File", "e.foo");
            itemsByType["FILE"] = items;

            items = new BuildItemGroup();
            items.AddNewItem("Doc", "a.doc");
            items.AddNewItem("Doc", "b.doc");
            items.AddNewItem("Doc", "c.doc");
            items.AddNewItem("Doc", "d.doc");
            items.AddNewItem("Doc", "e.doc");
            itemsByType["DOC"] = items;

            BuildPropertyGroup properties = new BuildPropertyGroup();
            properties.SetProperty("UnitTests", "unittests.foo");
            properties.SetProperty("OBJ", "obj");

            ArrayList buckets = BatchingEngine.PrepareBatchingBuckets(new XmlDoreplacedent().CreateElement("Foo"), parameters, CreateLookup(itemsByType, properties));

            replacedertion.replacedertEquals(5, buckets.Count);

            foreach (ItemBucket bucket in buckets)
            {
                // non-batching data -- same for all buckets
                XmlAttribute tempXmlAttribute = (new XmlDoreplacedent()).CreateAttribute("attrib");
                tempXmlAttribute.Value = "'$(Obj)'=='obj'";

                replacedertion.replacedert(BuildEngine.Utilities.EvaluateCondition(tempXmlAttribute.Value,
                    tempXmlAttribute, bucket.Expander, null, ParserOptions.AllowAll, null, null));
                replacedertion.replacedertEquals("a.doc;b.doc;c.doc;d.doc;e.doc", ExpandItemsIntoString(bucket, "@(doc)"));
                replacedertion.replacedertEquals("unittests.foo", ExpandMetadataAndProperties(bucket, "$(bogus)$(UNITTESTS)"));
            }

            replacedertion.replacedertEquals("a.foo", ExpandItemsIntoString((ItemBucket)buckets[0], "@(File)"));
            replacedertion.replacedertEquals(".foo", ExpandItemsIntoString((ItemBucket)buckets[0], "@(File->'%(Extension)')"));
            replacedertion.replacedertEquals("obj\\a.ext", ExpandMetadataAndProperties((ItemBucket)buckets[0], "$(obj)\\%(Filename).ext"));

            // we weren't batching on this attribute, so it has no value
            replacedertion.replacedertEquals(String.Empty, ExpandMetadataAndProperties((ItemBucket)buckets[0], "%(Extension)"));

            items = ((ItemBucket)buckets[0]).Expander.ExpandSingleItemListExpressionIntoItemsLeaveEscaped("@(file)", null);
            replacedertion.replacedertNotNull(items);
            replacedertion.replacedertEquals(1, items.Count);

            int invalidProjectFileExceptions = 0;
            try
            {
                // This should throw because we don't allow item lists to be concatenated
                // with other strings.
                items = ((ItemBucket)buckets[0]).Expander.ExpandSingleItemListExpressionIntoItemsLeaveEscaped("@(file);$(unitests)", null);
            }
            catch (InvalidProjectFileException)
            {
                invalidProjectFileExceptions++;
            }

            // We do allow separators in item vectors, this results in an item group with a single flattened item
            items = ((ItemBucket)buckets[0]).Expander.ExpandSingleItemListExpressionIntoItemsLeaveEscaped("@(file, ',')", null);
            replacedertion.replacedertNotNull(items);
            replacedertion.replacedertEquals(1, items.Count);
            replacedertion.replacedertEquals("a.foo", items[0].FinalItemSpec);

            replacedertion.replacedertEquals(1, invalidProjectFileExceptions);
        }

19 Source : BatchingEngine_Tests.cs
with MIT License
from enricosada

[Test]
        public void ValidUnqualifiedMetadataReference()
        {
            List<string> parameters = new List<string>();
            parameters.Add("@(File)");
            parameters.Add("%(Culture)");

            Hashtable itemsByType = new Hashtable(StringComparer.OrdinalIgnoreCase);

            BuildItemGroup items = new BuildItemGroup();
            itemsByType["FILE"] = items;

            BuildItem a = items.AddNewItem("File", "a.foo");
            BuildItem b = items.AddNewItem("File", "b.foo");
            a.SetMetadata("Culture", "fr-fr");
            b.SetMetadata("Culture", "en-en");

            BuildPropertyGroup properties = new BuildPropertyGroup();

            ArrayList buckets = BatchingEngine.PrepareBatchingBuckets(new XmlDoreplacedent().CreateElement("Foo"), parameters, CreateLookup(itemsByType, properties));
            replacedertion.replacedertEquals(2, buckets.Count);
        }

19 Source : BatchingEngine_Tests.cs
with MIT License
from enricosada

[Test]
        [ExpectedException(typeof(InvalidProjectFileException))]
        public void InvalidUnqualifiedMetadataReference()
        {
            List<string> parameters = new List<string>();
            parameters.Add("@(File)");
            parameters.Add("%(Culture)");

            Hashtable itemsByType = new Hashtable(StringComparer.OrdinalIgnoreCase);

            BuildItemGroup items = new BuildItemGroup();
            itemsByType["FILE"] = items;

            BuildItem a = items.AddNewItem("File", "a.foo");
            BuildItem b = items.AddNewItem("File", "b.foo");
            a.SetMetadata("Culture", "fr-fr");

            BuildPropertyGroup properties = new BuildPropertyGroup();

            // This is expected to throw because not all items contain a value for metadata "Culture".
            // Only a.foo has a Culture metadata.  b.foo does not.
            ArrayList buckets = BatchingEngine.PrepareBatchingBuckets(new XmlDoreplacedent().CreateElement("Foo"), parameters, CreateLookup(itemsByType, properties));
        }

19 Source : ItemExpander_Tests.cs
with MIT License
from enricosada

[Test]
        public void ExpandEmbeddedItemVectorsBasic()
        {
            Hashtable itemGroupsByType = this.GenerateTesreplacedems();

            XmlNode foo = new XmlDoreplacedent().CreateElement("Foo");
            string evaluatedString = ItemExpander.ExpandEmbeddedItemVectors("@(Compile)", foo, LookupHelpers.CreateLookup(itemGroupsByType).ReadOnlyLookup);
            replacedertion.replacedertEquals("a.cs;b.cs", evaluatedString);
        }

19 Source : BatchingEngine_Tests.cs
with MIT License
from enricosada

[Test]
        [ExpectedException(typeof(InvalidProjectFileException))]
        public void NoItemsConsumed()
        {
            List<string> parameters = new List<string>();
            parameters.Add("$(File)");
            parameters.Add("%(Culture)");

            Hashtable itemsByType = new Hashtable(StringComparer.OrdinalIgnoreCase);
            BuildPropertyGroup properties = new BuildPropertyGroup();

            // This is expected to throw because we have no idea what item list %(Culture) refers to.
            ArrayList buckets = BatchingEngine.PrepareBatchingBuckets(new XmlDoreplacedent().CreateElement("Foo"), parameters, CreateLookup(itemsByType, properties));
        }

19 Source : BatchingEngine_Tests.cs
with MIT License
from enricosada

[Test]
        public void Regress_Mutation_DuplicateBatchingBucketsAreFoldedTogether()
        {
            List<string> parameters = new List<string>();
            parameters.Add("%(File.Culture)");

            Hashtable itemsByType = new Hashtable(StringComparer.OrdinalIgnoreCase);
            
            BuildItemGroup items = new BuildItemGroup();
            items.AddNewItem("File", "a.foo");
            items.AddNewItem("File", "b.foo"); // Need at least two items for this test case to ensure multiple buckets might be possible
            itemsByType["FILE"] = items;

            BuildPropertyGroup properties = new BuildPropertyGroup();

            ArrayList buckets = BatchingEngine.PrepareBatchingBuckets(new XmlDoreplacedent().CreateElement("Foo"), parameters, CreateLookup(itemsByType, properties));

            // If duplicate buckes have been folded correctly, then there will be exactly one bucket here
            // containing both a.foo and b.foo.
            replacedertion.replacedertEquals(1, buckets.Count);
        }

19 Source : EngineProxy_Tests.cs
with MIT License
from enricosada

[SetUp]
        public void SetUp()
        {
            // Whole bunch of setup code.
            XmlElement taskNode = new XmlDoreplacedent().CreateElement("MockTask");
            LoadedType taskClreplaced = new LoadedType(typeof(MockTask), new replacedemblyLoadInfo(typeof(MockTask).replacedembly.FullName, null));
            engine = new Engine(@"c:\");
            Project project = new Project(engine);
            EngineCallback engineCallback = new EngineCallback(engine);
            taskExecutionModule = new MockTaskExecutionModule(engineCallback);
            int handleId = engineCallback.CreateTaskContext(project, null, null, taskNode, EngineCallback.inProcNode, new BuildEventContext(BuildEventContext.InvalidNodeId, BuildEventContext.InvalidTargetId, BuildEventContext.InvalidProjectContextId, BuildEventContext.InvalidTaskId));
            TaskEngine taskEngine = new TaskEngine
                                (
                                    taskNode,
                                    null, /* host object */
                                    "In Memory",
                                    project.FullFileName,
                                    engine.LoggingServices,
                                    handleId,
                                    taskExecutionModule,
                                    null
                                );
            taskEngine.TaskClreplaced = taskClreplaced;

            engineProxy = new EngineProxy(taskExecutionModule, handleId, project.FullFileName, project.FullFileName, engine.LoggingServices, null);
            taskExecutionModule2 = new MockTaskExecutionModule(engineCallback, TaskExecutionModule.TaskExecutionModuleMode.MultiProcFullNodeMode);
            engineProxy2 = new EngineProxy(taskExecutionModule2, handleId, project.FullFileName, project.FullFileName, engine.LoggingServices, null);

        }

19 Source : EngineProxy_Tests.cs
with MIT License
from enricosada

internal EngineProxy CreateEngineProxyWithDummyTaskEngine(Engine e, Project p)
        {
            // UNDONE need a real handle Id and a real TEM pointer
            XmlElement taskNode = new XmlDoreplacedent().CreateElement("MockTask");

            BuildRequest request = new BuildRequest(EngineCallback.invalidEngineHandle, "mockproject", null, (BuildPropertyGroup)null, null, -1, false, false);
            ProjectBuildState context = new ProjectBuildState(request, new ArrayList(), new BuildEventContext(0, 0, 0, 0));
            int handleId = e.EngineCallback.CreateTaskContext(p, null, context, taskNode, 0, new BuildEventContext(0, 0, 0, 0));
            TaskEngine taskEngine = new TaskEngine
                                (
                                    taskNode,
                                    null, /* host object */
                                    p.FullFileName,
                                    p.FullFileName,
                                    e.LoggingServices,
                                    handleId,
                                    e.NodeManager.TaskExecutionModule,
                                    new BuildEventContext(0, 0, 0, 0)
                                );
            e.Scheduler.Initialize(new INodeDescription[] { null });
            return new EngineProxy(e.NodeManager.TaskExecutionModule, handleId, p.FullFileName, p.FullFileName, e.LoggingServices, new BuildEventContext(0, 0, 0, 0));
        }

19 Source : ItemExpander_Tests.cs
with MIT License
from enricosada

[Test]
        public void ExpandEmbeddedItemVectorsSeparator()
        {
            Hashtable itemGroupsByType = this.GenerateTesreplacedems();

            XmlNode foo = new XmlDoreplacedent().CreateElement("Foo");
            string evaluatedString = ItemExpander.ExpandEmbeddedItemVectors("@(Compile, '#')", foo, LookupHelpers.CreateLookup(itemGroupsByType).ReadOnlyLookup);
            replacedertion.replacedertEquals("a.cs#b.cs", evaluatedString);
        }

See More Examples