Beispiel #1
0
 private void revert_Click(object sender, RoutedEventArgs e)
 {
     if (this.versions != null)
     {
         FBVersion   lastVers = (FBVersion)this.versions[versions.Length - 1].Clone();
         FBDirectory dir      = lastVers.root;
         Dictionary <string, List <TreeViewItemFat> > revertItems = new Dictionary <string, List <TreeViewItemFat> >();
         if (revertList.Items.Count == 0)
         {
             MessageBox.Show("There are no file to revert in the list please add them!", "List empty");
         }
         foreach (TreeViewItemFat el in revertList.Items)
         {
             if (!revertItems.ContainsKey(el.relativePath))
             {
                 revertItems[el.relativePath] = new List <TreeViewItemFat>();
             }
             revertItems[el.relativePath].Add(el);
         }
         modifyDir(revertItems, dir, dir.Name);
         se.resetToVersion(lastVers);
         revertList.Items.Clear();
     }
     else
     {
         MessageBox.Show("There is a problem with connection, please retry to login!", "Error in connection");
     }
 }
Beispiel #2
0
        private void CleanUpDir(FBDirectory dir, string relPath)
        {
            string targetPath = conf.targetPath.get();

            string[]      dirs     = Directory.GetDirectories(targetPath + "\\" + relPath);
            List <string> realdirs = new List <string>();
            List <string> versdirs = new List <string>();

            foreach (string d in dirs)
            {
                realdirs.Add(Path.GetFileName(d));
            }
            foreach (FBAbstractElement el in dir.content.Values)
            {
                if (el.GetType() == typeof(FBDirectory))
                {
                    if (!realdirs.Contains(el.Name))
                    {
                        Directory.CreateDirectory(targetPath + "\\" + relPath + "\\" + el.Name);
                    }

                    CleanUpDir((FBDirectory)el, relPath + "\\" + el.Name);
                    versdirs.Add(el.Name);
                }
            }
            foreach (string d in realdirs)
            {
                if (!versdirs.Contains(d))
                {
                    Directory.Delete(targetPath + "\\" + relPath + "\\" + d, true);
                }
            }
        }
Beispiel #3
0
        private TreeViewItem CreateDirectoryNode(FBDirectory root, string path)
        {
            TreeViewItemFat treeItem = new TreeViewItemFat();

            treeItem.version      = selectedVersion;
            treeItem.item         = root;
            treeItem.Header       = root.Name;
            treeItem.relativePath = path;

            foreach (String key in root.content.Keys)
            {
                if (root.content[key].GetType() == typeof(FBDirectory))
                {
                    FBDirectory child = (FBDirectory)root.content[key];
                    treeItem.Items.Add(CreateDirectoryNode(child, path + "\\" + child.Name));
                    treeItem.IsExpanded = true;
                }
                else
                {
                    TreeViewItemFat ti = new TreeViewItemFat()
                    {
                        Header = key
                    };
                    ti.version      = selectedVersion;
                    ti.item         = root.content[key];
                    ti.relativePath = path;
                    if (findItem(revertList.Items, ti) != null)
                    {
                        ti.Select = true;
                    }
                    treeItem.Items.Add(ti);
                }
            }
            if (root.content.Count == 0)
            {
                treeItem.Items.Add(new TreeViewItemFat()
                {
                    Header = ""
                });
            }

            return(treeItem);
        }
Beispiel #4
0
 private void modifyDir(Dictionary <string, List <TreeViewItemFat> > revertItems, FBDirectory dir, string relPath)
 {
     // recursion inside the existing directories
     foreach (FBAbstractElement el in dir.content.Values)
     {
         if (el.GetType() == typeof(FBDirectory))
         {
             modifyDir(revertItems, (FBDirectory)el, relPath + "\\" + el.Name);
         }
     }
     //add new directory if necessary
     foreach (string key in revertItems.Keys)
     {
         if (key.Contains(relPath + "\\"))
         {
             string newDirName = key.Substring((relPath + "\\").Length);
             newDirName = newDirName.Split('\\')[0];
             if (!dir.content.ContainsKey(newDirName))
             {
                 dir.addContent(new FBDirectory(newDirName));
                 modifyDir(revertItems, (FBDirectory)dir.content[newDirName], relPath + "\\" + newDirName);
             }
         }
     }
     //adding or replacing files in the directory
     if (revertItems.ContainsKey(relPath))
     {
         foreach (TreeViewItemFat tv in revertItems[relPath])
         {
             if (dir.content.ContainsKey(tv.item.Name))
             {
                 dir.content.Remove(tv.item.Name);
             }
             dir.addContent(tv.item);
         }
     }
     //revertItems.Remove(relPath);
 }