Beispiel #1
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);
        }
Beispiel #2
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
        }
Beispiel #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;
        }
Beispiel #4
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
        }