Пример #1
0
        public void ReadRecords()
        {
            Console.WriteLine("Program start reading recent file history...");
            XmlTextReader reader = null;

            try
            {
                // Load the reader with the data file and ignore all white space nodes.
                reader = new XmlTextReader(RSFile);
                int filter = 0; //the bit used to filter out entries
                reader.WhitespaceHandling = WhitespaceHandling.None;
                String fileName  = "";
                String extension = "";
                String filePath  = "";
                String mTime     = "";
                String cTime     = "";
                String eTime     = "";
                String missing   = "";
                String stored_in = "";
                //the flag used to indicate what is the current tag:
                int tag = -1;
                // Parse the file and display each of the nodes.
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        tag = GetFlag(reader.Name);
                        if (tag == 0)
                        {
                            filter    = 0;
                            fileName  = "";
                            extension = "";
                            filePath  = "";
                        }
                        if (tag == -2)
                        {
                            filter = 1;
                        }
                        //Console.WriteLine("<{0}>", reader.Name);
                        break;

                    case XmlNodeType.Text:
                        if (tag == 1)
                        {
                            filePath = reader.Value;
                        }                                              // full name of the file indicate the path of the file
                        if (tag == 8)
                        {
                            fileName = reader.Value;
                        }                                              //the file_only property indicate the name of the file
                        if (tag == 7)
                        {
                            extension = reader.Value;
                        }                                               // the extension of the file
                        if (tag == 2)
                        {
                            mTime = reader.Value;
                        }                                           //modified Time
                        if (tag == 3)
                        {
                            cTime = reader.Value;
                        }                                           //created Time
                        if (tag == 4)
                        {
                            eTime = reader.Value;
                        }                                           //execute Time
                        if (tag == 5)
                        {
                            missing = reader.Value;
                        }                                             //missing?
                        if (tag == 6)
                        {
                            stored_in = reader.Value;
                        }                                               //stored_in
                        //Console.WriteLine(reader.Value);
                        break;

                    case XmlNodeType.EndElement:
                        if ((filter == 0) && (reader.Name == "item"))
                        {
                            if ((Tools.IsValid(fileName, filePath, extension, stored_in)) && (Tools.IsValidTimeRange(mTime, cTime, eTime, lastUpdate, DateTime.Now) != -1))
                            {
                                FileNode tempNode = new FileNode();
                                tempNode.SetFileName(fileName);
                                tempNode.SetCreatedTime(cTime);
                                tempNode.SetExecuteTime(eTime);
                                tempNode.SetModifiedTime(mTime);
                                tempNode.SetFilePath(filePath);
                                tempNode.SetMissing(missing);
                                LinkedListNode <FileNode> node = new LinkedListNode <FileNode>(tempNode);
                                // Console.WriteLine(tempNode.GetFilename());
                                fileList.AddLast(node);
                            }
                        }
                        // Console.WriteLine("</{0}>", reader.Name);
                        break;

                    default:
                        break;
                    }
                }
            }

            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            Console.WriteLine("Reading Finished...");
        }
Пример #2
0
        public void ReadRecords()
        {
            Console.WriteLine("Program start reading recent file history...");
            XmlTextReader reader = null;

            try
            {
                // Load the reader with the data file and ignore all white space nodes.
                reader = new XmlTextReader(RSFile);
                sync   = 1;
                int filter = 0; //the bit used to filter out entries
                reader.WhitespaceHandling = WhitespaceHandling.None;
                String fileName  = "";
                String extension = "";
                String filePath  = "";
                String mTime     = "";
                String cTime     = "";
                String eTime     = "";
                //the flag used to indicate what is the current tag:
                int tag = -1;
                // Parse the file and display each of the nodes.
                while (reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        tag = GetFlag(reader.Name);
                        if (tag == 0)
                        {
                            filter    = 0;
                            fileName  = "";
                            extension = "";
                            filePath  = "";
                        }
                        if (tag == -2)
                        {
                            filter = 1;
                        }
                        //Console.WriteLine("<{0}>", reader.Name);
                        break;

                    case XmlNodeType.Text:
                        if (tag == 1)
                        {
                            filePath = reader.Value;
                        }                                              // full name of the file indicate the path of the file
                        if (tag == 8)
                        {
                            fileName = reader.Value;
                        }                                              //the file_only property indicate the name of the file
                        if (tag == 7)
                        {
                            extension = reader.Value;
                        }                                               // the extension of the file
                        if (tag == 2)
                        {
                            mTime = reader.Value;
                        }                                           //modified Time
                        if (tag == 3)
                        {
                            cTime = reader.Value;
                        }                                           //created Time
                        if (tag == 4)
                        {
                            eTime = reader.Value;
                        }                                           //execute Time
                        //Console.WriteLine(reader.Value);
                        break;

                    case XmlNodeType.EndElement:
                        if ((filter == 0) && (reader.Name == "item"))
                        {
                            if (IsValid(fileName, filePath, extension, mTime, cTime, eTime))
                            {
                                FileNode tempNode = new FileNode();
                                tempNode.SetFileName(fileName);
                                LinkedListNode <FileNode> node = new LinkedListNode <FileNode>(tempNode);
                                // Console.WriteLine(tempNode.GetFilename());
                                fileList.AddLast(node);
                            }
                        }
                        // Console.WriteLine("</{0}>", reader.Name);
                        break;

                    default:
                        break;

                        /*
                         * case XmlNodeType.CDATA:
                         *  Console.WriteLine("3");
                         *  Console.WriteLine("<![CDATA[{0}]]>", reader.Value);
                         *  break;
                         * case XmlNodeType.ProcessingInstruction:
                         *  Console.WriteLine("4");
                         *  Console.WriteLine("<?{0} {1}?>", reader.Name, reader.Value);
                         *  break;
                         * case XmlNodeType.Comment:
                         *  Console.WriteLine("5");
                         *  Console.WriteLine("<!--{0}-->", reader.Value);
                         *  break;
                         * case XmlNodeType.XmlDeclaration:
                         *  Console.WriteLine("6");
                         *  Console.WriteLine("<?xml version='1.0'?>");
                         *  break;
                         * case XmlNodeType.Document:
                         *  Console.WriteLine("7");
                         *  break;
                         * case XmlNodeType.DocumentType:
                         *  Console.WriteLine("8");
                         *  Console.WriteLine("<!DOCTYPE {0} [{1}]", reader.Name, reader.Value);
                         *  break;
                         * case XmlNodeType.EntityReference:
                         *  Console.WriteLine("9");
                         *  Console.WriteLine(reader.Name);
                         *  break;*/
                    }
                }
            }

            finally
            {
                if (reader != null)
                {
                    reader.Close();
                }
            }
            sync = 0;
            Console.WriteLine("Reading Finished...");
        }