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>(); }
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>(); }
private void InvokeDirectoryAdded(TreeDirectory folder) { var handler = DirectoryAdded; if (handler != null) { handler(this, new TreeDirectoryEventArgs(folder)); } }
private void OnDirectoryDeleted(TreeDirectory folder) { var handler = DirectoryDeleted; if (handler != null) { handler(this, new TreeDirectoryEventArgs(folder)); } }
private void InvokeAddedDirectory(TreeDirectory folder) { var handler = folder.StagedStatus == StagedStatus.Staged ? NewStagedFolder : NewUnstagedFolder; if (handler != null) { handler(this, new TreeDirectoryEventArgs(folder)); } }
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); } }
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; }
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; }
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; } } }
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); } }
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(); } }
/// <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 }; }
/// <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 }; }
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); }
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(); } }
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); }
private void OnDirectoryDeleted(TreeDirectory folder) { DirectoryDeleted?.Invoke(this, new TreeDirectoryEventArgs(folder)); }
public static void UpdateTreeDirectory(TreeDirectory treeDirectory, TreeDirectoryData treeDirectoryData) { Verify.Argument.IsNotNull(treeDirectory, "treeDirectory"); Verify.Argument.IsNotNull(treeDirectoryData, "treeDirectoryData"); }
private void InvokeDirectoryAdded(TreeDirectory folder) { DirectoryAdded?.Invoke(this, new TreeDirectoryEventArgs(folder)); }
public TreeDirectoryEventArgs(TreeDirectory folder) { Folder = folder; }
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; }
protected TreeItem(Repository repository, string relativePath, TreeDirectory parent, string name) : this(repository, relativePath, parent, FileStatus.Unknown, name) { }
internal void AddDirectory(TreeDirectory folder) { folder.Parent = this; _directories.Add(folder); InvokeDirectoryAdded(folder); }
internal void RemoveDirectory(TreeDirectory folder) { folder.Parent = null; _directories.Remove(folder); OnDirectoryDeleted(folder); }
public static void UpdateTreeDirectory(TreeDirectory treeDirectory, TreeDirectoryData treeDirectoryData) { Verify.Argument.IsNotNull(treeDirectory, nameof(treeDirectory)); Verify.Argument.IsNotNull(treeDirectoryData, nameof(treeDirectoryData)); }
public TreeFile(Repository repository, string relativePath, TreeDirectory parent, FileStatus status, string name, long size) : base(repository, relativePath, parent, status, name) { _size = size; }
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); } }
private void InvokeAddedDirectory(TreeDirectory folder) { var handler = folder.StagedStatus == StagedStatus.Staged ? NewStagedFolder : NewUnstagedFolder; if(handler != null) handler(this, new TreeDirectoryEventArgs(folder)); }
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 }
public TreeCommit(Repository repository, string relativePath, TreeDirectory parent, FileStatus status, string name) : base(repository, relativePath, parent, status, name) { }
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; } } }
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); } }
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 }
public TreeDirectory(Repository repository, string relativePath, TreeDirectory parent, string name) : this(repository, relativePath, parent, FileStatus.Unknown, name) { }
private void InvokeDirectoryAdded(TreeDirectory folder) { var handler = DirectoryAdded; if(handler != null) handler(this, new TreeDirectoryEventArgs(folder)); }
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; }
public TreeFile(Repository repository, string relativePath, TreeDirectory parent, FileStatus status, string name, long size) : base(repository, relativePath, parent, status, name) { Size = size; }
private void OnDirectoryDeleted(TreeDirectory folder) { var handler = DirectoryDeleted; if(handler != null) handler(this, new TreeDirectoryEventArgs(folder)); }