Esempio n. 1
0
        //keyword should not be empty string
        public LinkedList <FileNode> FindFilesByFileNameKeywords(String keyword)
        {
            XElement               fileList  = XElement.Load(ffile);
            List <FileNode>        list      = new List <FileNode>();
            IEnumerable <XElement> fileNodes = fileList.Elements();

            foreach (var file in fileNodes)
            {
                if (file.Element("File_Name").Value.Contains(keyword))
                {
                    FileNode currentNode = new FileNode();
                    currentNode.SetFileID(file.Attribute("ID").Value);
                    currentNode.SetCreatedTime(file.Element("Created_Time").Value);
                    currentNode.SetModifiedTime(file.Element("Modified_Time").Value);
                    currentNode.SetExecuteTime(file.Element("Execute_Time").Value);
                    currentNode.SetFileName(file.Element("File_Name").Value);
                    currentNode.SetFilePath(file.Element("File_Path").Value);
                    currentNode.SetExtension(file.Element("Extension").Value);
                    currentNode.SetMeetings(file.Element("Meetings").Value);
                    currentNode.SetMissing(file.Element("Missing").Value);
                    list.Add(currentNode);
                }
            }
            list.Sort((x, y) => y.GetModifiedTime().CompareTo(x.GetModifiedTime()));
            LinkedList <FileNode> n = new LinkedList <FileNode>();

            foreach (FileNode item in list)
            {
                n.AddLast(item);
            }
            return(n);
        }
Esempio n. 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);
                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...");
        }