Пример #1
0
 public TreeDirectory(Repository repository, string relativePath, TreeDirectory parent, FileStatus status, string name)
     : base(repository, relativePath, parent, status, name)
 {
     _directories = new List<TreeDirectory>();
     _files = new List<TreeFile>();
     _commits = new List<TreeCommit>();
 }
Пример #2
0
 public TreeDirectory(Repository repository, string relativePath, TreeDirectory parent, FileStatus status, string name)
     : base(repository, relativePath, parent, status, name)
 {
     _directories = new List <TreeDirectory>();
     _files       = new List <TreeFile>();
     _commits     = new List <TreeCommit>();
 }
Пример #3
0
        private void InvokeDirectoryAdded(TreeDirectory folder)
        {
            var handler = DirectoryAdded;

            if (handler != null)
            {
                handler(this, new TreeDirectoryEventArgs(folder));
            }
        }
Пример #4
0
        private void OnDirectoryDeleted(TreeDirectory folder)
        {
            var handler = DirectoryDeleted;

            if (handler != null)
            {
                handler(this, new TreeDirectoryEventArgs(folder));
            }
        }
Пример #5
0
        private void InvokeAddedDirectory(TreeDirectory folder)
        {
            var handler = folder.StagedStatus == StagedStatus.Staged ? NewStagedFolder : NewUnstagedFolder;

            if (handler != null)
            {
                handler(this, new TreeDirectoryEventArgs(folder));
            }
        }
Пример #6
0
        private static void Remove(TreeDirectory folder)
        {
            var from = folder.Parent;

            from.Directories.Remove(folder);
            if (from.Files.Count == 0 && from.Directories.Count == 0 && from.Parent != null)
            {
                Remove(from);
            }
        }
Пример #7
0
 protected TreeItem(Repository repository, string relativePath,
     TreeDirectory parent, FileStatus status, string name)
     : base(repository, name)
 {
     _parent = parent;
     if(parent != null)
     {
         _stagedStatus = parent._stagedStatus;
     }
     _status = status;
     _relativePath = relativePath;
 }
Пример #8
0
 protected TreeItem(Repository repository, string relativePath,
                    TreeDirectory parent, FileStatus status, string name)
     : base(repository, name)
 {
     _parent = parent;
     if (parent != null)
     {
         _stagedStatus = parent._stagedStatus;
     }
     _status       = status;
     _relativePath = relativePath;
 }
Пример #9
0
        private void SetContent(IList <TreeContentData> tree)
        {
            Root.Files.Clear();
            Root.Directories.Clear();
            var trees = new Dictionary <string, TreeDirectory>();

            foreach (var item in tree)
            {
                int    slashPos = item.Name.IndexOf('/');
                string name     = (slashPos == -1)?(item.Name):GetName(item.Name);
                var    parent   = _root;
                while (slashPos != -1)
                {
                    string        parentPath = item.Name.Substring(0, slashPos);
                    TreeDirectory p;
                    if (!trees.TryGetValue(parentPath, out p))
                    {
                        p = new TreeDirectory(Repository, parentPath, parent, GetName(parentPath));
                        parent.AddDirectory(p);
                        trees.Add(parentPath, p);
                    }
                    parent   = p;
                    slashPos = item.Name.IndexOf('/', slashPos + 1);
                }
                switch (item.Type)
                {
                case TreeContentType.Tree:
                {
                    var dir = new TreeDirectory(Repository, item.Name, parent, name);
                    trees.Add(item.Name, dir);
                    parent.AddDirectory(dir);
                }
                break;

                case TreeContentType.Blob:
                {
                    var blob = new TreeFile(Repository, item.Name, parent, FileStatus.Cached, name, ((BlobData)item).Size);
                    parent.AddFile(blob);
                }
                break;

                case TreeContentType.Commit:
                {
                    var commit = new TreeCommit(Repository, item.Name, parent, FileStatus.Cached, name);
                    parent.AddCommit(commit);
                }
                break;
                }
            }
        }
Пример #10
0
        private void InvokeRemovedDirectory(TreeDirectory folder)
        {
            foreach (var subFolder in folder.Directories)
            {
                InvokeRemovedDirectory(subFolder);
            }
            folder.MarkAsDeleted();
            var handler = folder.StagedStatus == StagedStatus.Staged ? RemovedStagedFolder : RemovedUnstagedFolder;

            handler?.Invoke(this, new TreeDirectoryEventArgs(folder));
            foreach (var file in folder.Files)
            {
                InvokeRemovedFile(file);
            }
        }
Пример #11
0
        private Tree(Repository repository, string treeHash, bool load)
            : base(repository)
        {
            Verify.Argument.IsNeitherNullNorWhitespace(treeHash, "treeHash");

            _treeHash = treeHash;
            var strRoot = repository.WorkingDirectory;
            if(strRoot.EndsWith("\\"))
            {
                strRoot = strRoot.Substring(0, strRoot.Length - 1);
            }
            int i = strRoot.LastIndexOf('\\');
            string name = (i != -1) ? strRoot.Substring(i + 1) : strRoot;
            _root = new TreeDirectory(Repository, string.Empty, null, name);
            if(load)
            {
                Refresh();
            }
        }
Пример #12
0
 /// <summary>Create <see cref="Status"/> object.</summary>
 /// <param name="repository">Related repository.</param>
 internal Status(Repository repository)
     : base(repository)
 {
     _unstagedPlainList = new Dictionary<string, TreeFile>();
     _stagedPlainList = new Dictionary<string, TreeFile>();
     var strRoot = Repository.WorkingDirectory;
     if(strRoot.EndsWithOneOf(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar))
     {
         strRoot = strRoot.Substring(0, strRoot.Length - 1);
     }
     _unstagedRoot = new TreeDirectory(Repository, string.Empty, null, strRoot)
         {
             StagedStatus = StagedStatus.Unstaged
         };
     _stagedRoot = new TreeDirectory(Repository, string.Empty, null, strRoot)
         {
             StagedStatus = StagedStatus.Staged
         };
 }
Пример #13
0
        /// <summary>Create <see cref="Status"/> object.</summary>
        /// <param name="repository">Related repository.</param>
        internal Status(Repository repository)
            : base(repository)
        {
            _unstagedPlainList = new Dictionary <string, TreeFile>();
            _stagedPlainList   = new Dictionary <string, TreeFile>();
            var strRoot = Repository.WorkingDirectory;

            if (strRoot.EndsWithOneOf(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar))
            {
                strRoot = strRoot.Substring(0, strRoot.Length - 1);
            }
            _unstagedRoot = new TreeDirectory(Repository, string.Empty, null, strRoot)
            {
                StagedStatus = StagedStatus.Unstaged
            };
            _stagedRoot = new TreeDirectory(Repository, string.Empty, null, strRoot)
            {
                StagedStatus = StagedStatus.Staged
            };
        }
Пример #14
0
        public static TreeDirectory CreateTreeDirectory(Repository repository, TreeDirectoryData treeDirectoryData)
        {
            Verify.Argument.IsNotNull(repository, "repository");
            Verify.Argument.IsNotNull(treeDirectoryData, "treeDirectoryData");

            var directory = new TreeDirectory(repository, treeDirectoryData.Name, null, treeDirectoryData.ShortName)
            {
                StagedStatus = treeDirectoryData.StagedStatus,
            };

            foreach (var subDirectory in treeDirectoryData.Directories)
            {
                directory.AddDirectory(CreateTreeDirectory(repository, subDirectory));
            }
            foreach (var file in treeDirectoryData.Files)
            {
                directory.AddFile(ObjectFactories.CreateTreeFile(repository, file));
            }
            return(directory);
        }
Пример #15
0
        private Tree(Repository repository, string treeHash, bool load)
            : base(repository)
        {
            Verify.Argument.IsNeitherNullNorWhitespace(treeHash, nameof(treeHash));

            _treeHash = treeHash;
            var strRoot = repository.WorkingDirectory;

            if (strRoot.EndsWith("\\"))
            {
                strRoot = strRoot.Substring(0, strRoot.Length - 1);
            }
            int    i    = strRoot.LastIndexOf('\\');
            string name = (i != -1) ? strRoot.Substring(i + 1) : strRoot;

            _root = new TreeDirectory(Repository, string.Empty, null, name);
            if (load)
            {
                Refresh();
            }
        }
Пример #16
0
        private bool Merge(
            IDictionary <string, TreeFile> oldPlainList, TreeDirectory oldRoot,
            IDictionary <string, TreeFileData> newPlainList, TreeDirectoryData newRoot)
        {
            bool res        = false;
            var  removeList = new List <string>();

            foreach (var oldFileKvp in oldPlainList)
            {
                TreeFileData file;
                if (newPlainList.TryGetValue(oldFileKvp.Key, out file))
                {
                    newPlainList.Remove(oldFileKvp.Key);
                    ObjectFactories.UpdateTreeFile(oldFileKvp.Value, file);
                }
                else
                {
                    removeList.Add(oldFileKvp.Key);
                    res = true;
                }
            }

            foreach (var s in removeList)
            {
                oldPlainList.Remove(s);
            }

            if (newPlainList.Count != 0)
            {
                res = true;
                foreach (var newFileKvp in newPlainList)
                {
                    oldPlainList.Add(newFileKvp.Key, ObjectFactories.CreateTreeFile(Repository, newFileKvp.Value));
                }
            }

            Update(newRoot, oldRoot);
            return(res);
        }
Пример #17
0
 private void OnDirectoryDeleted(TreeDirectory folder)
 {
     DirectoryDeleted?.Invoke(this, new TreeDirectoryEventArgs(folder));
 }
Пример #18
0
 public static void UpdateTreeDirectory(TreeDirectory treeDirectory, TreeDirectoryData treeDirectoryData)
 {
     Verify.Argument.IsNotNull(treeDirectory, "treeDirectory");
     Verify.Argument.IsNotNull(treeDirectoryData, "treeDirectoryData");
 }
Пример #19
0
 private void InvokeDirectoryAdded(TreeDirectory folder)
 {
     DirectoryAdded?.Invoke(this, new TreeDirectoryEventArgs(folder));
 }
Пример #20
0
 public TreeDirectoryEventArgs(TreeDirectory folder)
 {
     Folder = folder;
 }
Пример #21
0
        public static TreeDirectory CreateTreeDirectory(Repository repository, TreeDirectoryData treeDirectoryData)
        {
            Verify.Argument.IsNotNull(repository, "repository");
            Verify.Argument.IsNotNull(treeDirectoryData, "treeDirectoryData");

            var directory = new TreeDirectory(repository, treeDirectoryData.Name, null, treeDirectoryData.ShortName)
            {
                StagedStatus = treeDirectoryData.StagedStatus,
            };
            foreach(var subDirectory in treeDirectoryData.Directories)
            {
                directory.AddDirectory(CreateTreeDirectory(repository, subDirectory));
            }
            foreach(var file in treeDirectoryData.Files)
            {
                directory.AddFile(ObjectFactories.CreateTreeFile(repository, file));
            }
            return directory;
        }
Пример #22
0
 protected TreeItem(Repository repository, string relativePath,
                    TreeDirectory parent, string name)
     : this(repository, relativePath, parent, FileStatus.Unknown, name)
 {
 }
Пример #23
0
 internal void AddDirectory(TreeDirectory folder)
 {
     folder.Parent = this;
     _directories.Add(folder);
     InvokeDirectoryAdded(folder);
 }
Пример #24
0
 internal void RemoveDirectory(TreeDirectory folder)
 {
     folder.Parent = null;
     _directories.Remove(folder);
     OnDirectoryDeleted(folder);
 }
Пример #25
0
 public static void UpdateTreeDirectory(TreeDirectory treeDirectory, TreeDirectoryData treeDirectoryData)
 {
     Verify.Argument.IsNotNull(treeDirectory, nameof(treeDirectory));
     Verify.Argument.IsNotNull(treeDirectoryData, nameof(treeDirectoryData));
 }
Пример #26
0
 public TreeFile(Repository repository, string relativePath, TreeDirectory parent, FileStatus status, string name, long size)
     : base(repository, relativePath, parent, status, name)
 {
     _size = size;
 }
Пример #27
0
 internal void RemoveDirectory(TreeDirectory folder)
 {
     folder.Parent = null;
     _directories.Remove(folder);
     OnDirectoryDeleted(folder);
 }
Пример #28
0
 internal void AddDirectory(TreeDirectory folder)
 {
     folder.Parent = this;
     _directories.Add(folder);
     InvokeDirectoryAdded(folder);
 }
Пример #29
0
 private static void Remove(TreeDirectory folder)
 {
     var from = folder.Parent;
     from.Directories.Remove(folder);
     if(from.Files.Count == 0 && from.Directories.Count == 0 && from.Parent != null)
     {
         Remove(from);
     }
 }
Пример #30
0
 private void InvokeAddedDirectory(TreeDirectory folder)
 {
     var handler = folder.StagedStatus == StagedStatus.Staged ? NewStagedFolder : NewUnstagedFolder;
     if(handler != null) handler(this, new TreeDirectoryEventArgs(folder));
 }
Пример #31
0
 public static void UpdateTreeDirectory(TreeDirectory treeDirectory, TreeDirectoryData treeDirectoryData)
 {
     Verify.Argument.IsNotNull(treeDirectory, "treeDirectory");
     Verify.Argument.IsNotNull(treeDirectoryData, "treeDirectoryData");
 }
Пример #32
0
        private void Update(TreeDirectoryData sourceDirectory, TreeDirectory targetDirectory)
        {
            bool[] existance;
            bool[] matched;

            #region update subdirectories

            existance	= new bool[targetDirectory.Directories.Count];
            matched		= new bool[sourceDirectory.Directories.Count];
            for(int i = 0; i < targetDirectory.Directories.Count; ++i)
            {
                var targetSubDirectory = targetDirectory.Directories[i];
                for(int j = 0; j < sourceDirectory.Directories.Count; ++j)
                {
                    if(!matched[j])
                    {
                        var sourceSubDirectory = sourceDirectory.Directories[j];
                        if(targetSubDirectory.Name == sourceSubDirectory.ShortName)
                        {
                            existance[i]	= true;
                            matched[j]		= true;
                            Update(sourceSubDirectory, targetSubDirectory);
                            break;
                        }
                    }
                }
            }
            for(int i = targetDirectory.Directories.Count - 1; i >= 0; --i)
            {
                if(!existance[i])
                {
                    var directory = targetDirectory.Directories[i];
                    targetDirectory.RemoveDirectoryAt(i);
                    InvokeRemovedDirectory(directory);
                }
            }
            for(int i = 0; i < sourceDirectory.Directories.Count; ++i)
            {
                if(!matched[i])
                {
                    var directory = ObjectFactories.CreateTreeDirectory(Repository, sourceDirectory.Directories[i]);
                    targetDirectory.AddDirectory(directory);
                    InvokeAddedDirectory(directory);
                }
            }

            #endregion

            #region update files

            existance	= new bool[targetDirectory.Files.Count];
            matched		= new bool[sourceDirectory.Files.Count];
            for(int i = 0; i < targetDirectory.Files.Count; ++i)
            {
                var targetFile = targetDirectory.Files[i];
                for(int j = 0; j < sourceDirectory.Files.Count; ++j)
                {
                    if(!matched[j])
                    {
                        var sourceFile = sourceDirectory.Files[j];
                        if(targetFile.Name == sourceFile.ShortName)
                        {
                            existance[i]	= true;
                            matched[j]		= true;
                            targetFile.Status = sourceFile.FileStatus;
                            break;
                        }
                    }
                }
            }
            for(int i = targetDirectory.Files.Count - 1; i >= 0; --i)
            {
                if(!existance[i])
                {
                    var file = targetDirectory.Files[i];
                    targetDirectory.RemoveFileAt(i);
                    InvokeRemovedFile(file);
                }
            }
            for(int i = 0; i < sourceDirectory.Files.Count; ++i)
            {
                if(!matched[i])
                {
                    var treeFile = ObjectFactories.CreateTreeFile(Repository, sourceDirectory.Files[i]);
                    targetDirectory.AddFile(treeFile);
                    InvokeNewFile(treeFile);
                }
            }

            #endregion
        }
Пример #33
0
 public TreeCommit(Repository repository, string relativePath, TreeDirectory parent, FileStatus status, string name)
     : base(repository, relativePath, parent, status, name)
 {
 }
Пример #34
0
 public TreeCommit(Repository repository, string relativePath, TreeDirectory parent, FileStatus status, string name)
     : base(repository, relativePath, parent, status, name)
 {
 }
Пример #35
0
 private void SetContent(IList<TreeContentData> tree)
 {
     Root.Files.Clear();
     Root.Directories.Clear();
     var trees = new Dictionary<string, TreeDirectory>();
     foreach(var item in tree)
     {
         int slashPos = item.Name.IndexOf('/');
         string name = (slashPos == -1)?(item.Name):GetName(item.Name);
         var parent = _root;
         while(slashPos != -1)
         {
             string parentPath = item.Name.Substring(0, slashPos);
             TreeDirectory p;
             if(!trees.TryGetValue(parentPath, out p))
             {
                 p = new TreeDirectory(Repository, parentPath, parent, GetName(parentPath));
                 parent.AddDirectory(p);
                 trees.Add(parentPath, p);
             }
             parent = p;
             slashPos = item.Name.IndexOf('/', slashPos + 1);
         }
         switch(item.Type)
         {
             case TreeContentType.Tree:
                 {
                     var dir = new TreeDirectory(Repository, item.Name, parent, name);
                     trees.Add(item.Name, dir);
                     parent.AddDirectory(dir);
                 }
                 break;
             case TreeContentType.Blob:
                 {
                     var blob = new TreeFile(Repository, item.Name, parent, FileStatus.Cached, name, ((BlobData)item).Size);
                     parent.AddFile(blob);
                 }
                 break;
             case TreeContentType.Commit:
                 {
                     var commit = new TreeCommit(Repository, item.Name, parent, FileStatus.Cached, name);
                     parent.AddCommit(commit);
                 }
                 break;
         }
     }
 }
Пример #36
0
 private void InvokeRemovedDirectory(TreeDirectory folder)
 {
     foreach(var subFolder in folder.Directories)
     {
         InvokeRemovedDirectory(subFolder);
     }
     folder.MarkAsDeleted();
     var handler = folder.StagedStatus == StagedStatus.Staged ? RemovedStagedFolder : RemovedUnstagedFolder;
     if(handler != null) handler(this, new TreeDirectoryEventArgs(folder));
     foreach(var file in folder.Files)
     {
         InvokeRemovedFile(file);
     }
 }
Пример #37
0
        private void Update(TreeDirectoryData sourceDirectory, TreeDirectory targetDirectory)
        {
            bool[] existance;
            bool[] matched;

            #region update subdirectories

            existance = new bool[targetDirectory.Directories.Count];
            matched   = new bool[sourceDirectory.Directories.Count];
            for (int i = 0; i < targetDirectory.Directories.Count; ++i)
            {
                var targetSubDirectory = targetDirectory.Directories[i];
                for (int j = 0; j < sourceDirectory.Directories.Count; ++j)
                {
                    if (!matched[j])
                    {
                        var sourceSubDirectory = sourceDirectory.Directories[j];
                        if (targetSubDirectory.Name == sourceSubDirectory.ShortName)
                        {
                            existance[i] = true;
                            matched[j]   = true;
                            Update(sourceSubDirectory, targetSubDirectory);
                            break;
                        }
                    }
                }
            }
            for (int i = targetDirectory.Directories.Count - 1; i >= 0; --i)
            {
                if (!existance[i])
                {
                    var directory = targetDirectory.Directories[i];
                    targetDirectory.RemoveDirectoryAt(i);
                    InvokeRemovedDirectory(directory);
                }
            }
            for (int i = 0; i < sourceDirectory.Directories.Count; ++i)
            {
                if (!matched[i])
                {
                    var directory = ObjectFactories.CreateTreeDirectory(Repository, sourceDirectory.Directories[i]);
                    targetDirectory.AddDirectory(directory);
                    InvokeAddedDirectory(directory);
                }
            }

            #endregion

            #region update files

            existance = new bool[targetDirectory.Files.Count];
            matched   = new bool[sourceDirectory.Files.Count];
            for (int i = 0; i < targetDirectory.Files.Count; ++i)
            {
                var targetFile = targetDirectory.Files[i];
                for (int j = 0; j < sourceDirectory.Files.Count; ++j)
                {
                    if (!matched[j])
                    {
                        var sourceFile = sourceDirectory.Files[j];
                        if (targetFile.Name == sourceFile.ShortName)
                        {
                            existance[i]      = true;
                            matched[j]        = true;
                            targetFile.Status = sourceFile.FileStatus;
                            break;
                        }
                    }
                }
            }
            for (int i = targetDirectory.Files.Count - 1; i >= 0; --i)
            {
                if (!existance[i])
                {
                    var file = targetDirectory.Files[i];
                    targetDirectory.RemoveFileAt(i);
                    InvokeRemovedFile(file);
                }
            }
            for (int i = 0; i < sourceDirectory.Files.Count; ++i)
            {
                if (!matched[i])
                {
                    var treeFile = ObjectFactories.CreateTreeFile(Repository, sourceDirectory.Files[i]);
                    targetDirectory.AddFile(treeFile);
                    InvokeNewFile(treeFile);
                }
            }

            #endregion
        }
Пример #38
0
 public TreeDirectory(Repository repository, string relativePath, TreeDirectory parent, string name)
     : this(repository, relativePath, parent, FileStatus.Unknown, name)
 {
 }
Пример #39
0
 private void InvokeDirectoryAdded(TreeDirectory folder)
 {
     var handler = DirectoryAdded;
     if(handler != null) handler(this, new TreeDirectoryEventArgs(folder));
 }
Пример #40
0
        private bool Merge(
            IDictionary<string, TreeFile>	  oldPlainList, TreeDirectory	  oldRoot,
            IDictionary<string, TreeFileData> newPlainList,	TreeDirectoryData newRoot)
        {
            bool res = false;
            var removeList = new List<string>();

            foreach(var oldFileKvp in oldPlainList)
            {
                TreeFileData file;
                if(newPlainList.TryGetValue(oldFileKvp.Key, out file))
                {
                    newPlainList.Remove(oldFileKvp.Key);
                    ObjectFactories.UpdateTreeFile(oldFileKvp.Value, file);
                }
                else
                {
                    removeList.Add(oldFileKvp.Key);
                    res = true;
                }
            }

            foreach(var s in removeList)
            {
                oldPlainList.Remove(s);
            }

            if(newPlainList.Count != 0)
            {
                res = true;
                foreach(var newFileKvp in newPlainList)
                {
                    oldPlainList.Add(newFileKvp.Key, ObjectFactories.CreateTreeFile(Repository, newFileKvp.Value));
                }
            }

            Update(newRoot, oldRoot);
            return res;
        }
Пример #41
0
 public TreeFile(Repository repository, string relativePath, TreeDirectory parent, FileStatus status, string name, long size)
     : base(repository, relativePath, parent, status, name)
 {
     Size = size;
 }
Пример #42
0
 private void OnDirectoryDeleted(TreeDirectory folder)
 {
     var handler = DirectoryDeleted;
     if(handler != null) handler(this, new TreeDirectoryEventArgs(folder));
 }