Beispiel #1
0
        override public Boolean isEqualTo(FBAbstractElement other)
        {
            if (other.GetType() != this.GetType())
            {
                return(false);
            }

            FBDirectory othdir = (FBDirectory)other;

            if (othdir.content.Count != this.content.Count)
            {
                return(false);
            }

            foreach (KeyValuePair <string, FBAbstractElement> entry in this.content)
            {
                if (!othdir.content.ContainsKey(entry.Key))
                {
                    return(false);
                }
                else
                if (!entry.Value.isEqualTo(othdir.content[entry.Key]))
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #2
0
        public override FBAbstractElement Clone()
        {
            FBDirectory newDir = new FBDirectory(this.Name);

            foreach (FBAbstractElement abs in this.content.Values)
            {
                newDir.addContent(abs.Clone());
            }
            return(newDir);
        }
        public override FBAbstractElement generate()
        {
            DirectoryInfo dinfo = new DirectoryInfo(this.path);
            FBDirectory newDir = new FBDirectory(dinfo.Name);

            foreach (DirectoryInfo dir in dinfo.GetDirectories())
            {
                FBDirectoryBuilder db = new FBDirectoryBuilder(dir.FullName);
                newDir.addContent(db.generate());
            }

            foreach (FileInfo fil in dinfo.GetFiles())
            {
                FBFileBuilder fb = new FBFileBuilder(fil.FullName);
                newDir.addContent(fb.generate());
            }

            return newDir;
        }
Beispiel #4
0
        static public FBDirectory operator -(FBDirectory first, FBDirectory second)
        {
            FBDirectory ret = new FBDirectory(first.Name);

            ret.Name = first.Name;

            foreach (KeyValuePair <string, FBAbstractElement> entry in first.content)
            {
                if (!second.content.ContainsKey(entry.Key))
                {
                    ret.addContent(entry.Value.Clone());
                }
                else
                {
                    if (!entry.Value.isEqualTo(second.content[entry.Key]))
                    {
                        if (entry.Value.GetType().Equals(first.GetType()) && second.content[entry.Key].GetType().Equals(first.GetType()))
                        {
                            ret.addContent((FBDirectory)entry.Value - (FBDirectory)second.content[entry.Key]);
                            continue;
                        }
                        ret.addContent(entry.Value.Clone());
                        continue;
                    }
                    if (entry.Value.GetType() != first.GetType())
                    {
                        if (entry.Value.Name != second.content[entry.Key].Name)
                        {
                            ret.addContent(entry.Value.Clone());
                        }
                    }
                }
            }

            if (ret.content.Count == 0)
            {
                return(null);
            }
            return(ret);
        }
Beispiel #5
0
        override public FBAbstractElement generate()
        {
            DirectoryInfo dinfo  = new DirectoryInfo(this.path);
            FBDirectory   newDir = new FBDirectory(dinfo.Name);

            foreach (DirectoryInfo dir in dinfo.GetDirectories())
            {
                if ((dir.Attributes & FileAttributes.Hidden) != FileAttributes.Hidden)
                {
                    FBDirectoryBuilder db = new FBDirectoryBuilder(dir.FullName);
                    newDir.addContent(db.generate());
                }
            }

            foreach (FileInfo fil in dinfo.GetFiles())
            {
                FBFileBuilder fb = new FBFileBuilder(fil.FullName);
                newDir.addContent(fb.generate());
            }

            return(newDir);
        }
Beispiel #6
0
        public static FBDirectory operator -(FBDirectory first, FBDirectory second)
        {
            FBDirectory ret = new FBDirectory(first.Name);
            ret.Name = first.Name;

            foreach (KeyValuePair<string, FBAbstractElement> entry in first.content)
            {
                if (!second.content.ContainsKey(entry.Key))
                {
                    ret.addContent(entry.Value.Clone());
                }
                else
                {
                    if (!entry.Value.isEqualTo(second.content[entry.Key]))
                    {
                        if (entry.Value.GetType().Equals(first.GetType()) && second.content[entry.Key].GetType().Equals(first.GetType()))
                        {
                            ret.addContent((FBDirectory)entry.Value - (FBDirectory)second.content[entry.Key]);
                            continue;
                        }
                        ret.addContent(entry.Value.Clone());
                        continue;
                    }
                    if (entry.Value.GetType() != first.GetType())
                    {
                        if (entry.Value.Name != second.content[entry.Key].Name)
                        {
                            ret.addContent(entry.Value.Clone());
                        }
                    }
                }
            }

            if (ret.content.Count == 0) return null;
            return ret;
        }
        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.Name))
                    {
                        dir.content.Remove(tv.Name);
                    }
                    dir.addContent(tv.item);

                }
            }
            //revertItems.Remove(relPath);
        }
        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 #9
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 #10
0
 public FBVersion(string name)
 {
     this.timestamp = DateTime.UtcNow;
     root           = new FBDirectory(this.timestamp.ToString());
 }
Beispiel #11
0
 public FBVersion(string name)
 {
     this.timestamp = DateTime.UtcNow;
     root = new FBDirectory(this.timestamp.ToString());
 }
Beispiel #12
0
 public override FBAbstractElement Clone()
 {
     FBDirectory newDir = new FBDirectory(this.Name);
     foreach (FBAbstractElement abs in this.content.Values)
     {
         newDir.addContent(abs.Clone());
     }
     return newDir;
 }