Пример #1
0
        protected static void ExecuteFileAction(FileDestAction fileAction)
        {
            FileInfo srcFi  = fileAction.FileInfo;
            FileInfo destFi = new FileInfo(fileAction.DestFullName);

            switch (fileAction.Type)
            {
            case FileDestAction.ActionType.Copy:
                if (!srcFi.Exists || destFi.Exists)
                {
                    throw new InvalidOperationException();
                }
                Util.CommonUtil.Safe_CopyFileTo(fileAction.FileInfo, fileAction.DestFullName);
                break;

            case FileDestAction.ActionType.Move:
                if (!srcFi.Exists || destFi.Exists)
                {
                    throw new InvalidOperationException();
                }
                srcFi.MoveTo(destFi.FullName);
                break;

            case FileDestAction.ActionType.Delete:
                if (!srcFi.Exists)
                {
                    throw new InvalidOperationException();
                }
                srcFi.Delete();
                break;

            default:
                throw new InvalidOperationException();
            }
        }
Пример #2
0
        protected static void ValidateFileAction(FileDestAction fileDestAction)
        {
            FileInfo srcFi  = fileDestAction.FileInfo;
            FileInfo destFi = new FileInfo(fileDestAction.DestFullName);

            switch (fileDestAction.Type)
            {
            case FileDestAction.ActionType.Copy:
                if (!srcFi.Exists || destFi.Exists)
                {
                    throw new InvalidOperationException();
                }
                break;

            case FileDestAction.ActionType.Move:
                if (!srcFi.Exists || destFi.Exists)
                {
                    throw new InvalidOperationException();
                }
                break;

            case FileDestAction.ActionType.Delete:
                if (!srcFi.Exists)
                {
                    throw new InvalidOperationException();
                }
                break;

            default:
                throw new InvalidOperationException();
            }
        }
Пример #3
0
        private void CreateDestPlan()
        {
            #region Folder stuff.

            List <FolderDestAction> list_FolderDestActions = new List <FolderDestAction>();

            foreach (FolderElm folderElm in this._srcMain.FolderElm_List)
            {
                if (folderElm.RelativePath == "\\")
                {
                    continue;
                }

                var di_Dest = new DirectoryInfo(this._destMain.DI_main.FullName + folderElm.RelativePath);
                if (di_Dest.Exists)
                {
                    continue;
                }

                var folderAction = new FolderDestAction
                {
                    DestFullName = di_Dest.FullName,
                    Type         = FolderDestAction.ActionType.Create,
                };
                list_FolderDestActions.Add(folderAction);
            }

            foreach (FolderElm folderElm in this._destMain.FolderElm_List)
            {
                if (folderElm.RelativePath == "\\")
                {
                    continue;
                }

                var di_Src = new DirectoryInfo(this._srcMain.DI_main.FullName + folderElm.RelativePath);
                if (di_Src.Exists)
                {
                    continue;
                }

                var folderAction = new FolderDestAction
                {
                    DestFullName = this._destMain.DI_main.FullName + folderElm.RelativePath,
                    Type         = FolderDestAction.ActionType.Delete,
                };
                list_FolderDestActions.Add(folderAction);
            }

            #endregion


            #region File stuff.

            List <FileDestAction> list_FileDestActions = new List <FileDestAction>();

            var srcFiles  = this._srcMain.FileElm_List;
            var destFiles = this._destMain.FileElm_List;

            var tmpIdx = 100;
            var dif1   = FileElm.BasicComparison(srcFiles[0 + tmpIdx], srcFiles[1 + tmpIdx]); //  -1
            var dif2   = FileElm.BasicComparison(srcFiles[1 + tmpIdx], srcFiles[2 + tmpIdx]); //  -1
            var dif_2  = FileElm.BasicComparison(srcFiles[2 + tmpIdx], srcFiles[1 + tmpIdx]); //  1

            var list_srcBasicEquals  = new List <FileElm>();
            var list_destBasicEquals = new List <FileElm>();

            int srcIdx  = 0;
            int destIdx = 0;
            while (srcIdx != srcFiles.Count() || destIdx != destFiles.Count())
            {
                if (srcIdx != srcFiles.Count() && destIdx == destFiles.Count())
                {
                    var            srcFile    = srcFiles[srcIdx];
                    FileDestAction fileAction = CreateFileCopyAction(srcFile);
                    list_FileDestActions.Add(fileAction);
                    srcIdx++;
                    continue;
                }
                else if (srcIdx == srcFiles.Count() && destIdx != destFiles.Count())
                {
                    var            destFile   = destFiles[destIdx];
                    FileDestAction fileAction = CreateFileDeleteAction(destFile);
                    list_FileDestActions.Add(fileAction);
                    destIdx++;
                    continue;
                }
                else
                {
                    var srcFile  = srcFiles[srcIdx];
                    var destFile = destFiles[destIdx];

                    if (srcFile.RelativeFullName == "\\IbsHaythamMagdiTask.v12.suo")
                    {
                        srcIdx = srcIdx;
                    }

                    var basicComp = FileElm.BasicComparison(srcFile, destFile);

                    if (basicComp == 0)
                    {
                        var srcIdx_2  = srcIdx;
                        var destIdx_2 = destIdx;

                        list_destBasicEquals.Clear();
                        list_srcBasicEquals.Clear();

                        ////  tmp
                        //list_srcBasicEquals = list_destBasicEquals;

                        var basicComp_2  = basicComp;
                        var fullNameComp = FileElm.FullNameComparison(srcFile, destFile);
                        //for (int k = destIdx; k < destFiles.Count && fullNameComp != 0 && basicComp_2 == 0; k++)
                        for (destIdx_2 = destIdx; destIdx_2 < destFiles.Count && basicComp_2 == 0; destIdx_2++)
                        {
                            list_destBasicEquals.Add(destFiles[destIdx_2]);

                            //fullNameComp = FileElm.FullNameComparison(srcFile, destFiles[destIdx_2]);
                            basicComp_2 = FileElm.BasicComparison(srcFile, destFiles[destIdx_2]);
                        }

                        basicComp_2  = basicComp;
                        fullNameComp = FileElm.FullNameComparison(srcFile, destFile);
                        for (srcIdx_2 = destIdx; srcIdx_2 < srcFiles.Count && basicComp_2 == 0; srcIdx_2++)
                        {
                            list_destBasicEquals.Add(srcFiles[srcIdx_2]);

                            //fullNameComp = FileElm.FullNameComparison(srcFiles[srcIdx_2], destFile);
                            basicComp_2 = FileElm.BasicComparison(srcFiles[srcIdx_2], destFile);

                            //throw new NotImplementedException();
                        }


                        var list_all = list_srcBasicEquals.Select(x => new
                        {
                            FileElm = x,
                            From    = 'S',
                        }).ToList();

                        list_all.AddRange(list_destBasicEquals.Select(x => new
                        {
                            FileElm = x,
                            From    = 'D',
                        }));

                        list_all.Sort((x, y) =>
                        {
                            return(FileElm.FullNameComparison(x.FileElm, y.FileElm));
                        });

                        for (int k = 0; k < list_all.Count(); k++)
                        {
                        }

                        throw new NotImplementedException();


                        if (srcFile.RelativeFullName != destFile.RelativeFullName)
                        {
                            FileDestAction fileAction = CreateFileMoveAction(srcFile, destFile);
                            list_FileDestActions.Add(fileAction);
                        }

                        srcIdx++;
                        destIdx++;
                        continue;
                    }
                    else if (basicComp < 0)
                    {
                        FileDestAction fileAction = CreateFileCopyAction(srcFile);
                        list_FileDestActions.Add(fileAction);
                        srcIdx++;
                        continue;
                    }
                    else if (basicComp > 0)
                    {
                        FileDestAction fileAction = CreateFileDeleteAction(destFile);
                        list_FileDestActions.Add(fileAction);
                        destIdx++;
                        continue;
                    }
                }
            }

            var destPlan = new DestPlan
            {
                FolderDestActions = list_FolderDestActions,
                FileDestActions   = list_FileDestActions,
            };

            #endregion

            _destPlan = destPlan;
        }