Exemplo n.º 1
0
 public TreeDirectoryData(string name, string shortName, TreeDirectoryData parent, FileStatus fileStatus, StagedStatus stagedStatus)
     : base(name, fileStatus, stagedStatus)
 {
     _parent = parent;
     ShortName = shortName;
     _files = new List<TreeFileData>();
     _directories = new List<TreeDirectoryData>();
 }
Exemplo n.º 2
0
 public TreeDirectoryData(string name, string shortName, TreeDirectoryData parent, FileStatus fileStatus, StagedStatus stagedStatus)
     : base(name, fileStatus, stagedStatus)
 {
     Parent      = parent;
     ShortName   = shortName;
     Files       = new List <TreeFileData>();
     Directories = new List <TreeDirectoryData>();
 }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }
Exemplo n.º 5
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
        }
Exemplo n.º 6
0
        private static TreeDirectoryData BreakIntoTree(IDictionary <string, TreeFileData> files, StagedStatus stagedStatus)
        {
            var root = new TreeDirectoryData("", "", null, FileStatus.Cached, stagedStatus);
            var dirs = new Dictionary <string, TreeDirectoryData>();
            var path = new StringBuilder();

            foreach (var tfinfo in files.Values)
            {
                var parent     = root;
                var name       = tfinfo.Name;
                var nameLength = name.Length;
                //if(name.EndsWith("/"))
                //{
                //    --nameLength;
                //    name = name.Substring(0, nameLength);
                //}
                int slashPos = 0;
                path.Clear();
                while (slashPos != -1 && slashPos < nameLength)
                {
                    bool isFile;
                    int  endOfPathName = name.IndexOf('/', slashPos);
                    if (endOfPathName == -1)
                    {
                        endOfPathName = nameLength;
                        isFile        = true;
                    }
                    else
                    {
                        isFile = false;
                    }
                    string partName;
                    if (isFile)
                    {
                        partName = slashPos == 0 ?
                                   name :
                                   name.Substring(slashPos, endOfPathName - slashPos);
                        tfinfo.ShortName = partName;
                        parent.AddFile(tfinfo);
                        break;
                    }
                    else
                    {
                        partName = name.Substring(slashPos, endOfPathName - slashPos);
                        path.Append(partName);
                        path.Append('/');
                        string            currentPath = path.ToString();
                        TreeDirectoryData wtDirectory;
                        if (!dirs.TryGetValue(currentPath, out wtDirectory))
                        {
                            wtDirectory = new TreeDirectoryData(currentPath, partName, parent, FileStatus.Cached, stagedStatus);
                            dirs.Add(currentPath, wtDirectory);
                            parent.AddDirectory(wtDirectory);
                        }
                        parent = wtDirectory;
                    }
                    slashPos = endOfPathName + 1;
                }
            }

            return(root);
        }
Exemplo n.º 7
0
 public static void UpdateTreeDirectory(TreeDirectory treeDirectory, TreeDirectoryData treeDirectoryData)
 {
     Verify.Argument.IsNotNull(treeDirectory, "treeDirectory");
     Verify.Argument.IsNotNull(treeDirectoryData, "treeDirectoryData");
 }
Exemplo n.º 8
0
 public void AddDirectory(TreeDirectoryData directory)
 {
     Directories.Add(directory);
 }
Exemplo n.º 9
0
 public static void UpdateTreeDirectory(TreeDirectory treeDirectory, TreeDirectoryData treeDirectoryData)
 {
     Verify.Argument.IsNotNull(treeDirectory, "treeDirectory");
     Verify.Argument.IsNotNull(treeDirectoryData, "treeDirectoryData");
 }
Exemplo n.º 10
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;
        }
Exemplo n.º 11
0
 public static void UpdateTreeDirectory(TreeDirectory treeDirectory, TreeDirectoryData treeDirectoryData)
 {
     Verify.Argument.IsNotNull(treeDirectory, nameof(treeDirectory));
     Verify.Argument.IsNotNull(treeDirectoryData, nameof(treeDirectoryData));
 }
Exemplo n.º 12
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
        }
Exemplo n.º 13
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;
        }
Exemplo n.º 14
0
        private static TreeDirectoryData BreakIntoTree(IDictionary<string, TreeFileData> files, StagedStatus stagedStatus)
        {
            var root = new TreeDirectoryData("", "", null, FileStatus.Cached, stagedStatus);
            var dirs = new Dictionary<string, TreeDirectoryData>();
            var path = new StringBuilder();

            foreach(var tfinfo in files.Values)
            {
                var parent = root;
                var name = tfinfo.Name;
                var nameLength = name.Length;
                //if(name.EndsWith("/"))
                //{
                //    --nameLength;
                //    name = name.Substring(0, nameLength);
                //}
                int slashPos = 0;
                path.Clear();
                while(slashPos != -1 && slashPos < nameLength)
                {
                    bool isFile;
                    int endOfPathName = name.IndexOf('/', slashPos);
                    if(endOfPathName == -1)
                    {
                        endOfPathName = nameLength;
                        isFile = true;
                    }
                    else
                    {
                        isFile = false;
                    }
                    string partName;
                    if(isFile)
                    {
                        partName = slashPos == 0 ?
                            name :
                            name.Substring(slashPos, endOfPathName - slashPos);
                        tfinfo.ShortName = partName;
                        parent.AddFile(tfinfo);
                        break;
                    }
                    else
                    {
                        partName = name.Substring(slashPos, endOfPathName - slashPos);
                        path.Append(partName);
                        path.Append('/');
                        string currentPath = path.ToString();
                        TreeDirectoryData wtDirectory;
                        if(!dirs.TryGetValue(currentPath, out wtDirectory))
                        {
                            wtDirectory = new TreeDirectoryData(currentPath, partName, parent, FileStatus.Cached, stagedStatus);
                            dirs.Add(currentPath, wtDirectory);
                            parent.AddDirectory(wtDirectory);
                        }
                        parent = wtDirectory;
                    }
                    slashPos = endOfPathName + 1;
                }
            }

            return root;
        }
Exemplo n.º 15
0
 public void AddDirectory(TreeDirectoryData directory)
 {
     _directories.Add(directory);
 }