Ejemplo n.º 1
0
 /// <summary>
 /// this is the function that maps the directories from the computer recursively
 /// </summary>
 /// <param name="directory"></param>
 /// <param name="parentNode"></param>
 /// <param name="tree"></param>
 /// <param name="names"></param>
 /// <returns></returns>
 public TreeView getDirectories(DirectoryInfo directory, string parentNode, TreeView tree, ref List<string> names)
 {
     // TODO : Maybe the name of the treeviewitems should be the fullpath? that ensures its unique and we could later
     // use the names (full paths) in order to find the file quickly for TFS stuff
     // FIXED : have to pass the name of the parent node instead of using directory.Name because of the unique naming of the tree
     // elements. by passing the unique name we can find the correct parent node
     TreeViewItem parent = tree.FindName(parentNode) as TreeViewItem;
     // gets down to last directory
     DirectoryInfo[] dir = directory.GetDirectories();
     if (dir.Length > 0)
     {
         foreach (DirectoryInfo subDir in dir)
         {
             // im just skipping over the git stuff for now. we can figure out how to deal with it later
             if (!subDir.Name.Equals(".git"))
             {
                 string header = subDir.Name;
                 string name = header.Split('.')[0];
                 // passes the name to a function that addes numbers to the end of the name to
                 // ensure the name is unique
                 name = uniqueName(name, ref names);
                 TreeViewItem item = new TreeViewItem() { Header = header, Name = name };
                 parent.Items.Add(item);
                 item.RegisterName(name, item);
                 names.Add(name);
                 getDirectories(subDir,name, tree, ref names);
             }
         }
     }
     //map files to current level of tree
     FileInfo[] files = directory.GetFiles();
     if (files.Length > 0)
     {
         foreach (FileInfo file in files)
         {
             string header = file.Name;
             // this is more git stuff that we dont need to put in here but we might need to add more error stuff to catch weird
             // names and such
             if(header.Contains("git"))
             {
                 header = header.Replace(".", "NotNeeded");
             }
             string name = header.Split('.')[0];
             // passes the name to a function that addes numbers to the end of the name to
             // ensure the name is unique
             name = uniqueName(name, ref names);
             TreeViewItem item = new TreeViewItem() { Header = header, Name = name };
             parent.Items.Add(item);
             item.RegisterName(name, item);
             names.Add(name);
         }
     }
     return tree;
 }
Ejemplo n.º 2
0
 private void addDataToTree(TreeView treeView1, List<dynamic> actualList, List<dynamic> resultList, DBModule.TypeOfDepth depth, String value, int count)
 {
     // if (sendQuery != null)
     // {
     switch (depth)
     {
         case DBModule.TypeOfDepth.Section:
             {
                 int i = count;
                 foreach (DBModule.Section sectionName in resultList)
                 {
                     if (!isAdded(actualList, sectionName, depth))
                     {
                         TreeViewItem mainItem = new TreeViewItem() { Header = "Section: " + sectionName.SectionName, Name = "item" + i };
                         treeView1.Items.Add(mainItem);
                         mainItem.RegisterName("regName" + i, mainItem);
                         i++;
                     }
                 }
                 break;
             }
         case DBModule.TypeOfDepth.ForumThread:
             {
                 int i = count;
                 
                 foreach (ForumThread forumThread in resultList)
                 {
                     if (!isAdded(actualList, forumThread, depth))
                     {
                         if (!dict.ContainsKey(forumThread.SectionName))
                         {
                             TreeViewItem mainItem = new TreeViewItem() { Header = "Section: " + forumThread.SectionName, Name = "item" + i };
                             treeView1.Items.Add(mainItem);
                             dict.Add(forumThread.SectionName, "regName" + i);
                             mainItem.RegisterName("regName" + i, mainItem);
                             TreeViewItem subItem = new TreeViewItem() { Header = "Thread: " + forumThread.ThreadName, Name = "subItem" + i };
                             mainItem.Items.Add(subItem);
                             subItem.RegisterName("regSubName" + i, subItem);
                         }
                         else
                         {
                             TreeViewItem searchItem = treeView1.FindName(dict[forumThread.SectionName]) as TreeViewItem;
                             TreeViewItem subItem = new TreeViewItem() { Header = "Thread: " + forumThread.ThreadName, Name = "subItem" + i };
                             searchItem.Items.Add(subItem);
                             subItem.RegisterName("regSubName" + i, subItem);
                         }
                         i++;
                     }
                 }
                 break;
             }
         case DBModule.TypeOfDepth.Post:
             {
                 int i = count;
                 
                 foreach (Post post in resultList)
                 {
                     if (!isAdded(actualList, post, depth))
                     {
                         if (!dictSections.ContainsKey(post.SectionTitle))
                         {
                             TreeViewItem mainItem = new TreeViewItem() { Header = "Section: " + post.SectionTitle, Name = "item" + i };
                             treeView1.Items.Add(mainItem);
                             dictSections.Add(post.SectionTitle, "regName" + i);
                             mainItem.RegisterName("regName" + i, mainItem);
                             if (!dictThreads.ContainsKey(post.TopicTitle))
                             {
                                 TreeViewItem subItem = new TreeViewItem() { Header = "Thread: " + post.TopicTitle, Name = "subItem" + i };
                                 mainItem.Items.Add(subItem);
                                 dictThreads.Add(post.TopicTitle, "regSubName" + i);
                                 subItem.RegisterName("regSubName" + i, subItem);
                                 TreeViewItem postItem = new TreeViewItem() { Header = "Post: " + ChangeName(post.Content), Name = "postItem" + i };
                                 subItem.Items.Add(postItem);
                                 postItem.RegisterName("regPostName" + i, postItem);
                             }
                             else
                             {
                                 TreeViewItem searchThreadItem = treeView1.FindName(dictThreads[post.TopicTitle]) as TreeViewItem;
                                 TreeViewItem postItem = new TreeViewItem() { Header = "Post: " + ChangeName(post.Content), Name = "postItem" + i };
                                 searchThreadItem.Items.Add(postItem);
                                 postItem.RegisterName("regPostName" + i, postItem);
                             }
                         }
                         else
                         {
                             TreeViewItem searchItem = treeView1.FindName(dictSections[post.SectionTitle]) as TreeViewItem;
                             if (!dictThreads.ContainsKey(post.TopicTitle))
                             {
                                 TreeViewItem subItem = new TreeViewItem() { Header = "Thread: " + post.TopicTitle, Name = "subItem" + i };
                                 searchItem.Items.Add(subItem);
                                 subItem.RegisterName("regSubName" + i, subItem);
                                 TreeViewItem postItem = new TreeViewItem() { Header = "Post: " + ChangeName(post.Content), Name = "postItem" + i };
                                 subItem.Items.Add(postItem);
                                 postItem.RegisterName("regPostName" + i, postItem);
                             }
                             else
                             {
                                 TreeViewItem searchThreadItem = treeView1.FindName(dictThreads[post.TopicTitle]) as TreeViewItem;
                                 TreeViewItem postItem = new TreeViewItem() { Header = "Post: " + ChangeName(post.Content), Name = "postItem" + i };
                                 searchThreadItem.Items.Add(postItem);
                                 postItem.RegisterName("regPostName" + i, postItem);
                             }
                         }
                         i++;
                     }
                 }
                 break;
             }
     }
 }