private static FileDestAction CreateFileDeleteAction(FileElm destFile) { return(new FileDestAction { Type = FileDestAction.ActionType.Delete, FileInfo = destFile.FileInfo, }); }
private FileDestAction CreateFileMoveAction(FileElm srcFile, FileElm destFile) { return(new FileDestAction { Type = FileDestAction.ActionType.Move, FileInfo = destFile.FileInfo, DestFullName = this._destMain.DI_main.FullName + srcFile.RelativeFullName, }); }
public bool CompareUniqueNums(FileElm fileElm) { this.PrepareUniqueNumsOnce(); fileElm.PrepareUniqueNumsOnce(); for (int i = 0; i < this._UniqueArr.Length; i++) { if (this._UniqueArr[i] != fileElm._UniqueArr[i]) { return(false); } } return(true); }
public void PrepareElements() { var t1 = DateTime.Now; for (int i = 0; i < FolderElm_List.Count; i++) { FolderElm folderElm = FolderElm_List[i]; if (folderElm.IncludeSubFolders) { DirectoryInfo[] di_List = null; try { di_List = folderElm.DirectoryInfo.GetDirectories( "*.*", SearchOption.TopDirectoryOnly); } catch { continue; } foreach (DirectoryInfo di in di_List) { FolderElm_List.Add(new FolderElm { DirectoryInfo = di, IncludeSubFolders = true, Parent = folderElm, }); } } } FileElm_List = new List <FileElm>(100000); foreach (FolderElm folderElm in FolderElm_List) { FileInfo[] fiColl = null; try { fiColl = folderElm.DirectoryInfo.GetFiles( "*.*", SearchOption.TopDirectoryOnly); } catch { continue; } foreach (FileInfo fi in fiColl) { FileElm fiElm = new FileElm { FileInfo = fi, ParentFolder = folderElm, }; FileElm_List.Add(fiElm); } } var t2 = DateTime.Now; var ts = t2.Subtract(t1); //var l1 = FileElm_List.Select(x => x.FileInfo.Length).ToList(); //FileElm_List.OrderBy(x => x.FileInfo.Length) //l1.Sort(); //Sort(x => x.FileInfo.Length); //this.FileElm_List.Sort((x, y) => x.DateModified < y.DateModified); this.FileElm_List.Sort(FileElm.SortComparison); //this.FileElm_List.Sort((x, y) => //{ // long longVal1; // longVal1 = x.Size - y.Size; // if (longVal1 > 0) // return (int)1; // else if (longVal1 < 0) // return (int)-1; // int intVal1 = x.DateModified.CompareTo(y.DateModified); // return intVal1; //}); var list11 = this.FileElm_List.Select(x => new { x.Size, x.DateModified, x.Name, }).ToList(); int a; for (int i = 1; i < this.FileElm_List.Count; i++) { var e1 = this.FileElm_List[i]; var e2 = this.FileElm_List[i - 1]; //var c1 = FileElm.SortComparison(e1, e2); //if (c1 == 0) //{ // a = 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; }