Example #1
0
        public FolderSet(InputData input)
        {
            var folderWorker = new FolderWorker();

            foreach (var path in input.FoldersPaths)
            {
                var folderPair = new FolderPair(folderWorker.LoadSerializedFolder(path), folderWorker.LoadFolder(path));
                FolderList.Add(folderPair);
            }

            NoDeleteFlag = input.NoDeleteFlag;
            Loglevel     = input.LogLevel;
        }
        private Dictionary <string, string> FindNewFiles(FolderPair folderPair, Dictionary <string, string> addDictionary)
        {
            var newFolder = folderPair.New;
            var oldFolder = folderPair.Old;

            foreach (var newFile in newFolder.FilesList)
            {
                var oldFile = GetItemByPath(oldFolder, newFile.Path);

                if (oldFile == null && !addDictionary.ContainsKey(newFile.Path))
                {
                    addDictionary.Add(newFile.Path, newFolder.Path);
                }
            }

            return(addDictionary);
        }
        private Dictionary <string, string> FindDeleteFiles(FolderPair folderPair, Dictionary <string, string> deleteDictionary)
        {
            var newFolder = folderPair.New;
            var oldFolder = folderPair.Old;

            foreach (var oldFile in oldFolder.FilesList)
            {
                var newFile = GetItemByPath(newFolder, oldFile.Path);

                if (newFile == null && !deleteDictionary.ContainsKey(oldFile.Path))
                {
                    deleteDictionary.Add(oldFile.Path, oldFolder.Path);
                }
            }

            return(deleteDictionary);
        }
        private Dictionary <string, string> FindUpdateFiles(FolderPair folderPair, Dictionary <string, string> updateDictionary)
        {
            var newFolder = folderPair.New;
            var oldFolder = folderPair.Old;

            foreach (var newFile in newFolder.FilesList)
            {
                var oldFile = GetItemByPath(oldFolder, newFile.Path);

                if (oldFile == null)
                {
                    continue;
                }

                bool haveDifferentContent = (newFile.Hash != oldFile.Hash);

                if (haveDifferentContent && !updateDictionary.ContainsKey(newFile.Path) && !_deleteDictionary.ContainsKey(newFile.Path))
                {
                    updateDictionary.Add(newFile.Path, newFolder.Path);
                }
            }

            return(updateDictionary);
        }