Exemplo n.º 1
0
        public static void RunTest_Memory(string _filename, string _rootNode)
        {
            _xmlDoc = new PFXmlDocument(_rootNode);

            XmlElement xmlElement;
            XmlElement saveXmlElement;

            xmlElement     = _xmlDoc.AddNewElement(_xmlDoc.DocumentRootNode, "ProcessingDate", DateTime.Now.ToString());
            saveXmlElement = _xmlDoc.AddNewElement(_xmlDoc.DocumentRootNode, "IsEnabled", "True");
            xmlElement     = _xmlDoc.AddNewElement(saveXmlElement, "node1", "text1");
            xmlElement     = _xmlDoc.AddNewElement(saveXmlElement, "node2", "text2");
            _xmlDoc.AddNewAttribute(xmlElement, "attr1", "val1");
            xmlElement = _xmlDoc.AddNewElement(saveXmlElement, "node3", "text3");
            _xmlDoc.AddNewAttribute(xmlElement, "attr3a", "val3a");
            _xmlDoc.AddNewAttribute(xmlElement, "attr3b", "val3b");
            xmlElement = _xmlDoc.AddNewElement(_xmlDoc.DocumentRootNode, "FormBackground", "Red");
            _xmlDoc.SaveToFile(_filename);

            PFXmlDocument xmlDoc2 = new PFXmlDocument();

            xmlDoc2.LoadFromFile(_filename);
            Program._messageLog.WriteLine(xmlDoc2.OuterXml);
            Program._messageLog.WriteLine("\r\n" + xmlDoc2.InnerText);
            Program._messageLog.WriteLine("\r\n" + xmlDoc2.InnerXml);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates and initializes an instance of the class by loading a serialized version of the instance from a file.
        /// </summary>
        /// <param name="filePath">Full path for the input file.</param>
        /// <returns>An instance of PFDirectoryEx.</returns>
        public static PFDirectoryEx LoadFromXmlFile(string filePath)
        {
            //*************************************************************
            //Built-in serialization does not work on PFDirectoryEx class.
            //*************************************************************
            //XmlSerializer deserializer = new XmlSerializer(typeof(PFDirectoryEx));
            //TextReader textReader = new StreamReader(filePath);
            //PFDirectoryEx dirEx;
            //dirEx = (PFDirectoryEx)deserializer.Deserialize(textReader);
            //textReader.Close();
            //return dirEx;

            PFDirectoryEx pfD‏irectoryExInstance = null;

            PFXmlDocument xmldoc = new PFXmlDocument();

            xmldoc.LoadFromFile(filePath);
            string     searchPath         = xmldoc.DocumentRootNodeName + "/" + "FullName";
            XmlElement fullNameNode       = xmldoc.FindElement(searchPath);
            string     PathForNewInstance = string.Empty;

            if (fullNameNode != null)
            {
                PathForNewInstance = fullNameNode.InnerText;
            }
            if (PathForNewInstance.Length > 0)
            {
                pfD‏irectoryExInstance = new PFDirectoryEx(PathForNewInstance, true);
            }

            return(pfD‏irectoryExInstance);
        }
Exemplo n.º 3
0
        private string ToXmlStringSummary()
        {
            Type          t      = this.GetType();
            PFXmlDocument xmldoc = new PFXmlDocument(t.Name);

            xmldoc.AddNewElement(xmldoc.DocumentRootNode, "Name", this.Name);

            xmldoc.AddNewElement(xmldoc.DocumentRootNode, "FullName", this.FullName);

            xmldoc.AddNewElement(xmldoc.DocumentRootNode, "NumBytesInDirectory", this.NumBytesInDirectory.ToString("#,##0"));

            xmldoc.AddNewElement(xmldoc.DocumentRootNode, "NumFilesInDirectory", this.NumFilesInDirectory.ToString("#,##0"));

            xmldoc.AddNewElement(xmldoc.DocumentRootNode, "NumSubdirectoriesInDirectory", this.NumSubdirectoriesInDirectory.ToString("#,##0"));

            xmldoc.AddNewElement(xmldoc.DocumentRootNode, "NumBytesInDirectoryTree", this.NumBytesInDirectoryTree.ToString("#,##0"));

            xmldoc.AddNewElement(xmldoc.DocumentRootNode, "TotalNumFilesInDirectoryTree", this.TotalNumFilesInDirectoryTree.ToString("#,##0"));

            xmldoc.AddNewElement(xmldoc.DocumentRootNode, "TotalNumSubdirectoriesInDirectoryTree", this.TotalNumSubdirectoriesInDirectoryTree.ToString("#,##0"));

            xmldoc.AddNewElement(xmldoc.DocumentRootNode, "NumErrors", this.NumErrors.ToString("#,##0"));

            xmldoc.AddNewElement(xmldoc.DocumentRootNode, "ErrorMessages", this.ErrorMessages);



            return(xmldoc.OuterXml);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Returns a string containing the contents of the object in XML format.
        /// </summary>
        /// <returns>String value in xml format.</returns>
        /// ///<remarks>XML Serialization is used for the transformation.</remarks>
        public string ToXmlString()
        {
            Type          t      = this.GetType();
            PFXmlDocument xmldoc = new PFXmlDocument(t.Name);

            PropertyInfo[] props = t.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);

            int inx    = 0;
            int maxInx = props.Length - 1;

            for (inx = 0; inx <= maxInx; inx++)
            {
                PropertyInfo prop = props[inx];
                object       val  = prop.GetValue(this, null);

                xmldoc.AddNewElement(xmldoc.DocumentRootNode, prop.Name, val.ToString());
            }


            return(xmldoc.OuterXml);

            //XmlSerializer ser = new XmlSerializer(typeof(PFFileEx));
            //StringWriter tex = new StringWriter();
            //ser.Serialize(tex, this);
            //return tex.ToString();
        }
Exemplo n.º 5
0
        public static void LoadBadXMLTest()
        {
            string        xml    = "<root></notroot>";
            PFXmlDocument xmlDoc = new PFXmlDocument();

            try
            {
                xmlDoc.LoadFromString(xml);
            }
            catch (System.Exception ex)
            {
                Program._messageLog.WriteLine(AppMessages.FormatErrorMessage(ex));
                AppMessages.DisplayErrorMessage(AppMessages.FormatErrorMessage(ex));
                throw new System.Exception("LoadBadXMLTest reports an error.\n", ex);
            }
        }
Exemplo n.º 6
0
        private string ToXmlStringDetail()
        {
            Type          t      = this.GetType();
            PFXmlDocument xmldoc = new PFXmlDocument(t.Name);

            PropertyInfo[] props = t.GetProperties(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);

            int inx    = 0;
            int maxInx = props.Length - 1;

            for (inx = 0; inx <= maxInx; inx++)
            {
                PropertyInfo prop = props[inx];
                object       val  = prop.GetValue(this, null);

                xmldoc.AddNewElement(xmldoc.DocumentRootNode, prop.Name, val.ToString());
            }


            return(xmldoc.OuterXml);
        }
Exemplo n.º 7
0
        public static void CreateXMLDoc(string _filename, string _rootNode)
        {
            _xmlDoc = new PFXmlDocument(_rootNode);
            XmlDeclaration xmldec = _xmlDoc.XmlDoc.CreateXmlDeclaration("1.0", "utf-16", null);

            //XmlElement root = _xmlDoc.XmlDoc.DocumentElement;
            //_xmlDoc.XmlDoc.DocumentElement.SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
            //_xmlDoc.XmlDoc.DocumentElement.SetAttribute("xmlns:xsd", "http://www.w3.org/2001/XMLSchema");
            //_xmlDoc.XmlDoc.InsertBefore(xmldec, root);
            _xmlDoc.SaveToFile(_filename);
            _msg.Length = 0;
            if (File.Exists(_filename))
            {
                _msg.Append("File created: ");
                _msg.Append(_filename);
            }
            else
            {
                _msg.Append("File create failed for : ");
                _msg.Append(_filename);
            }
            Program._messageLog.WriteLine(_msg.ToString());
        }