Ejemplo n.º 1
0
        private void AddFilePairWithCheck(FilePairAction filePairAction)
        {
            //bool filePairAddedAlready = false;

            //foreach (var entry in actionList)
            //{
            //    if (filePairAction.File1 == entry.File1
            //        &&
            //        filePairAction.File2 == entry.File2)
            //    {
            //        filePairAddedAlready = true;
            //        break;
            //    }

            //}

            //if (filePairAddedAlready)
            //{
            //    string mes = "The actions list already contains this file combination:\n" +
            //                 "\t source file:      " + filePairAction.File1.fullPath + "\n" +
            //                 "\t destination file: " + filePairAction.File2.fullPath;

            //    throw new Exception(mes);
            //}
            _actionList.Add(filePairAction);
        }
Ejemplo n.º 2
0
        private void AddMoveAction(KeyValuePair <FileExtended, FileExtended> filePair)
        {
            var file1 = filePair.Key;
            var file2 = filePair.Value;

            if (file1 != null && file2 != null)
            {
                if (file1.RelativePath != file2.RelativePath)
                {
                    FilePairAction filePairAction = new FilePairAction(filePair.Key, filePair.Value);
                    filePairAction.ActionType = ActionType.Move;

                    DateTime lastWriteDate1 = DateTime.Parse(file1.lastWriteDateTime, CultureInfo.InvariantCulture);
                    DateTime lastWriteDate2 = DateTime.Parse(file2.lastWriteDateTime, CultureInfo.InvariantCulture);

                    if (lastWriteDate1.Date == lastWriteDate2.Date
                        &&
                        lastWriteDate1.TimeOfDay == lastWriteDate2.TimeOfDay)
                    {
                        filePairAction.ActionDirection = Direction.SourceToDestination;
                    }
                    else
                    {
                        filePairAction.ActionDirection = lastWriteDate1 < lastWriteDate2
                            ? Direction.DestinationToSource
                            : Direction.SourceToDestination;
                    }

                    AddFilePairWithCheck(filePairAction);
                }
            }
        }
Ejemplo n.º 3
0
        private void AddUpdateAction(KeyValuePair <FileExtended, FileExtended> filePair)
        {
            var file1 = filePair.Key;
            var file2 = filePair.Value;

            if (file1 != null && file2 != null)
            {
                // Action = Update
                DateTime file1LastUpdatedOn = DateTime.Parse(file1.lastWriteDateTime, CultureInfo.InvariantCulture);
                DateTime file2LastUpdatedOn = DateTime.Parse(file2.lastWriteDateTime, CultureInfo.InvariantCulture);
                if (file1LastUpdatedOn.Date != file2LastUpdatedOn.Date ||
                    file1LastUpdatedOn.TimeOfDay != file2LastUpdatedOn.TimeOfDay)
                {
                    FilePairAction filePairAction = new FilePairAction(filePair.Key, filePair.Value)
                    {
                        ActionType = ActionType.Update
                    };
                    if (file1LastUpdatedOn > file2LastUpdatedOn)
                    {
                        filePairAction.ActionDirection = file1.fileType == FileType.Source
                            ? Direction.SourceToDestination
                            : Direction.DestinationToSource;
                    }
                    else
                    {
                        filePairAction.ActionDirection = file1.fileType == FileType.Source
                            ? Direction.DestinationToSource
                            : Direction.SourceToDestination;
                    }

                    AddFilePairWithCheck(filePairAction);
                }
            }
        }
Ejemplo n.º 4
0
        public void AppendActionListWithDeleteRenameMove(FileExtended firstFileExtended, FileExtended secondFileExtended,
                                                         CsvRow row)
        {
            var filePairAction = new FilePairAction(firstFileExtended, secondFileExtended);



            FileExtended sourceFile = WorkingWithFiles.GetSourceAndDestFile(firstFileExtended, secondFileExtended)[FileType.Source];
            FileExtended destFile   = WorkingWithFiles.GetSourceAndDestFile(firstFileExtended, secondFileExtended)[FileType.Destination];

            // handle deletions
            bool deletion = IdentifyDeletion(sourceFile, destFile, filePairAction);

            if (deletion)
            {
                //_actionList.Add(filePairAction);
                return;
            }

            // handle renaming and moving
            var oldFirstFileType     = (FileType)Enum.Parse(typeof(FileType), row[0]);
            var oldFirstBasePath     = row[1];
            var oldFirstFileFullPath = row[2];
            var oldFirstFileId       = row[3];
            var oldFirstFile         = new FileExtended(oldFirstFileType, oldFirstBasePath, oldFirstFileFullPath, oldFirstFileId);

            var oldSecondFileType     = (FileType)Enum.Parse(typeof(FileType), row[4]);
            var oldSecondBasePath     = row[5];
            var oldSecondFileFullPath = row[6];
            var oldSecondFileId       = row[7];
            var oldSecondFile         = new FileExtended(oldSecondFileType, oldSecondBasePath, oldSecondFileFullPath,
                                                         oldSecondFileId);

            var oldSourceFile = oldFirstFileType == FileType.Source ? oldFirstFile : oldSecondFile;
            var oldDestFile   = oldSecondFileType == FileType.Destination ? oldSecondFile : oldFirstFile;


            IdentifyRenameMove(sourceFile, oldSourceFile, destFile, oldDestFile, filePairAction);
            if (filePairAction.ActionType == ActionType.RenameMove
                ||
                filePairAction.ActionType == ActionType.Rename
                ||
                filePairAction.ActionType == ActionType.Move
                // ||
                //filePairAction.ActionType == ActionType.Delete
                )
            {
                AddFilePairWithCheck(filePairAction);
            }
        }
Ejemplo n.º 5
0
        private bool AddCreateAction(KeyValuePair <FileExtended, FileExtended> filePair)
        {
            bool create = false;

            if (filePair.Value == null)
            {
                create = true;
                FilePairAction filePairAction = new FilePairAction(filePair.Key, filePair.Value);
                filePairAction.ActionType      = ActionType.Create;
                filePairAction.ActionDirection = filePairAction.File1.fileType == FileType.Source ?
                                                 Direction.SourceToDestination : Direction.DestinationToSource;

                AddFilePairWithCheck(filePairAction);
            }

            return(create);
        }
Ejemplo n.º 6
0
        private bool IdentifyDeletion(FileExtended sourceFile, FileExtended destFile,
                                      FilePairAction filePairAction)
        {
            bool res = false;

            if (sourceFile == null && destFile != null)
            {
                //filePairAction.ActionType = ActionType.Delete;
                //filePairAction.ActionDirection = Direction.SourceToDestination;
                res = true;
            }
            else if (sourceFile != null && destFile == null)
            {
                //filePairAction.ActionType = ActionType.Delete;
                //filePairAction.ActionDirection = Direction.DestinationToSource;
                res = true;
            }
            return(res);
        }
Ejemplo n.º 7
0
        private void IdentifyRenameMove(FileExtended sourceFile, FileExtended oldSourceFile,
                                        FileExtended destFile, FileExtended oldDestFile,
                                        FilePairAction filePairAction)
        {
            string sourceName         = Path.GetFileName(sourceFile.fullPath);
            string sourceDirectory    = Path.GetDirectoryName(sourceFile.fullPath);
            string oldSourceName      = Path.GetFileName(oldSourceFile.fullPath);
            string oldSourceDirectory = Path.GetDirectoryName(oldSourceFile.fullPath);

            string destName         = Path.GetFileName(destFile.fullPath);
            string destDirectory    = Path.GetDirectoryName(destFile.fullPath);
            string oldDestName      = Path.GetFileName(oldDestFile.fullPath);
            string oldDestDirectory = Path.GetDirectoryName(oldDestFile.fullPath);

            // identify RenameMove
            if (
                (sourceName != oldSourceName || destName != oldDestName)
                &&
                (sourceDirectory != oldSourceDirectory || destDirectory != oldDestDirectory)
                &&
                !(sourceName == destName && sourceFile.RelativePath == destFile.RelativePath)
                )

            {
                filePairAction.ActionType = ActionType.RenameMove;

                if (sourceFile.fullPath != oldSourceFile.fullPath
                    &&
                    destFile.fullPath == oldDestFile.fullPath)
                {
                    filePairAction.ActionDirection = Direction.SourceToDestination;
                }
                else if (sourceFile.fullPath == oldSourceFile.fullPath
                         &&
                         destFile.fullPath != oldDestFile.fullPath)
                {
                    filePairAction.ActionDirection = Direction.DestinationToSource;
                }
                else if (sourceFile.fullPath != oldSourceFile.fullPath
                         &&
                         destFile.fullPath != oldDestFile.fullPath)
                {
                    filePairAction.ActionDirection = Direction.Unknown;
                }

                return;
            }

            // identify Rename
            if (
                (sourceName != oldSourceName || destName != oldDestName)
                &&
                (sourceName != destName)
                )
            {
                filePairAction.ActionType = ActionType.Rename;

                if (sourceName != oldSourceName &&
                    destName == oldDestName)
                {
                    filePairAction.ActionDirection = Direction.SourceToDestination;
                }
                else if (sourceName == oldSourceName &&
                         destName != oldDestName)
                {
                    filePairAction.ActionDirection = Direction.DestinationToSource;
                }
                else if (sourceName != oldSourceName &&
                         destName != oldDestName)
                {
                    filePairAction.ActionDirection = Direction.Unknown;
                }
                return;
            }

            // identify Move
            if (
                (sourceDirectory != oldSourceDirectory || destDirectory != oldDestDirectory)
                &&
                sourceFile.RelativePath != destFile.RelativePath
                )
            {
                filePairAction.ActionType = ActionType.Move;

                if (sourceDirectory != oldSourceDirectory &&
                    destDirectory == oldDestDirectory)
                {
                    filePairAction.ActionDirection = Direction.SourceToDestination;
                }
                else if (sourceDirectory == oldSourceDirectory &&
                         destDirectory != oldDestDirectory)
                {
                    filePairAction.ActionDirection = Direction.DestinationToSource;
                }
                else if (sourceDirectory != oldSourceDirectory &&
                         destDirectory != oldDestDirectory)
                {
                    filePairAction.ActionDirection = Direction.Unknown;
                }
            }
        }