Exemplo n.º 1
0
 public override void Cleanup()
 {
     CurrentDirectoryNode = null;
     CurrentDirectoryPath = string.Empty;
     DirectoryRoot        = null;
     CleanUpEvent();
 }
        private List <CNode> GetChildrenNodes(CNode root)
        {
            List <CNode> tempList = new List <CNode>();

            SearchChildrenNode(root, tempList);
            return(tempList);
        }
Exemplo n.º 3
0
 public DirectoryCNode(int rank, string name, CNode parent, string path)
 {
     this.Rank         = rank;
     this.Name         = name;
     this.Parent       = parent;
     this.Path         = path;
     this.ChildrenNode = new ObservableCollection <CNode>();
 }
 private void GetChildrenNodePath(CNode rootNode, Dictionary <string, string> tempDic)
 {
     foreach (CNode childNode in rootNode.ChildrenNode)
     {
         tempDic.Add((childNode as ConvertNode).CreateNameString(), (childNode as ConvertNode).CreateSearchString(string.Empty));
         GetChildrenNodePath(childNode, tempDic);
     }
 }
 private void SearchChildrenNode(CNode root, List <CNode> list)
 {
     if (root.ChildrenNode != null)
     {
         foreach (CNode child in root.ChildrenNode)
         {
             list.Add(child);
             SearchChildrenNode(child, list);
         }
     }
 }
Exemplo n.º 6
0
        private void ParseDirectory(DirectoryCNode rNode, Parser psr, bool parseFlag)
        {
            ParseDirectoryNode(rNode, psr, parseFlag);
            CNode node = psr.Get_FileScheme();

            if (node != null && node.ChildrenNode.Count > 0)
            {
                FileSchemeList.Add(node);
                rNode.CurrentNodeList.Add(node);
            }
        }
Exemplo n.º 7
0
 public ConvertNode(CNode node)
 {
     this.Name         = node.Name;
     this.Rank         = node.Rank;
     this.Parent       = node.Parent;
     this.ChildrenNode = node.ChildrenNode;
     if (node is JsonCNode)
     {
         this.SchemeType = FileType.JSON;
     }
     else
     {
         this.SchemeType = FileType.XML;
     }
 }
Exemplo n.º 8
0
        private void GetDirectories(DirectoryInfo root, CNode rNode, int rank)
        {
            rank++;
            foreach (FileInfo fi in root.GetFiles(jsonFilterString))
            {
                (rNode as DirectoryCNode).jsonPathList.Add(fi.FullName);
            }
            foreach (FileInfo fi in root.GetFiles(xmlFilterString))
            {
                (rNode as DirectoryCNode).xmlPathList.Add(fi.FullName);
            }

            foreach (DirectoryInfo dir in root.GetDirectories())
            {
                CNode subNode = new DirectoryCNode(rank, dir.Name, rNode, dir.FullName);
                rNode.ChildrenNode.Add(subNode);
                GetDirectories(dir, subNode, rank);
            }
        }
Exemplo n.º 9
0
 public void MergeNode(CNode root, CNode current)
 {
     if (current != null)
     {
         foreach (CNode node in current.ChildrenNode)
         {
             CNode rnode = root.ChildrenNode.Where(rc => rc.Name == node.Name).FirstOrDefault();
             if (rnode == null)
             {
                 rnode = node.Clone() as CNode;
                 root.ChildrenNode.Add(rnode);
             }
             else
             {
                 (rnode as XmlCNode).Count += (node as XmlCNode).Count;
                 MergeNode(rnode, node);
             }
         }
     }
 }
Exemplo n.º 10
0
        public bool Parser(string path)
        {
            bool   result     = true;
            string jsonString = File.ReadAllText(path);

            CurrentNode = new JsonCNode()
            {
                Name = "json", Count = 1,
            };
            try
            {
                ParseJson((JsonCNode)this.CurrentNode, JObject.Parse(jsonString), startRank);
                MergeNode(Root, CurrentNode);
            }
            catch (Exception ex)
            {
                //TODO: log4net
                result = false;
            }
            return(result);
        }
Exemplo n.º 11
0
 private CNode ParseFile(CNode dNode, Parser psr, List <string> filePathList)
 {
     if (filePathList != null)
     {
         foreach (string filePath in filePathList)
         {
             if (psr.ParseFile(filePath))
             {
                 CNode node = psr.Get_FileScheme();
                 SetNodeEvent(node);
                 psr.MergeNode(dNode, psr.GetCurrentNode());
             }
             else
             {
                 //TODO: log4net
                 continue;
             }
         }
     }
     return(dNode);
 }
Exemplo n.º 12
0
        private void ParseXml(XmlNode xDoc, CNode root, int rank)
        {
            XmlNodeList Nodechildren = xDoc.ChildNodes;

            rank++;
            foreach (XmlNode xn in Nodechildren)
            {
                if (xn is XmlElement)
                {
                    XmlCNode thisNode = (XmlCNode)root.ChildrenNode.Where(cn => cn.Name == xn.Name).FirstOrDefault();
                    if (thisNode == null)
                    {
                        XmlCNode newNode = new XmlCNode();
                        newNode.Name   = xn.Name;
                        newNode.Rank   = rank;
                        newNode.Parent = root;
                        newNode.Count  = startCount;
                        root.ChildrenNode.Add(newNode);
                        thisNode = newNode;
                    }
                    else
                    {
                        thisNode.Count++;
                    }
                    foreach (XmlAttribute xa in xn.Attributes)
                    {
                        if (thisNode.Attributes.Keys.Contains(xa.Name))
                        {
                            thisNode.Attributes[xa.Name]++;
                        }
                        else
                        {
                            thisNode.Attributes.Add(xa.Name, startCount);
                        }
                    }
                    ParseXml(xn, thisNode, rank);
                }
            }
        }
Exemplo n.º 13
0
        public void SetNode(CNode root)
        {
            if (RootNodeCollection == null)
            {
                RootNodeCollection = new ObservableCollection <CNode>();
            }
            CNode node = RootNodeCollection.Where(fs => fs.Name == root.Name).FirstOrDefault();

            if (node != null)
            {
                node = root;
            }
            else
            {
                if (this.viewDispatcher != null)
                {
                    this.viewDispatcher.Invoke((Action)(() =>
                    {
                        RootNodeCollection.Add(root);
                    }));
                }
            }
        }
Exemplo n.º 14
0
        internal void LoadDirectory(string dPath)
        {
            FileSchemeList.Clear();
            int   startRank = 0;
            CNode rootNode  = new DirectoryCNode(startRank, Path.GetDirectoryName(dPath), null, dPath);

            GetDirectories(new DirectoryInfo(dPath), rootNode, startRank);
            DirectoryRoot = rootNode;
            this.mainDispatcher.Invoke((Action)(() =>
            {
                CurrentDirectoryNode = rootNode;
            }));

            Parser psr = new Parser();

            psr.Set_ParserInstance(new XmlParser());
            ParseDirectory(rootNode as DirectoryCNode, psr, true);

            psr.Set_ParserInstance(new JsonParser());
            ParseDirectory(rootNode as DirectoryCNode, psr, false);

            ParseFileDoneEvent(FileSchemeList);
        }
Exemplo n.º 15
0
        public bool Parser(string path)
        {
            bool   result    = true;
            string xmlString = File.ReadAllText(path);

            CurrentNode = new XmlCNode()
            {
                Name = "xml", Count = 1,
            };

            try
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.LoadXml(xmlString);
                ParseXml(xDoc, CurrentNode, startRank);
                MergeNode(Root, CurrentNode);
            }
            catch (Exception ex)
            {
                //TODO: log4net
                result = false;
            }
            return(result);
        }
Exemplo n.º 16
0
 internal void SetCurrentDirectoryNode(CNode dNode)
 {
     CurrentDirectoryNode = dNode;
 }