public void CompareBothDirectoryWithSameContentWithSubFolders() { FolderComparer comparer = new FolderComparer(); var dirTemp = Directory.CreateDirectory("temp"); var dirA = Directory.CreateDirectory(Path.Combine(dirTemp.FullName, "A")); var dirB = Directory.CreateDirectory(Path.Combine(dirTemp.FullName, "B")); var dirASub = Directory.CreateDirectory(Path.Combine(dirA.FullName, "Folder")); var dirBSub = Directory.CreateDirectory(Path.Combine(dirB.FullName, "Folder")); File.WriteAllText(Path.Combine(dirASub.FullName, "testfile.txt"), "CompareBothDirectoryWithDifferentContent1"); File.WriteAllText(Path.Combine(dirBSub.FullName, "testfile.txt"), "CompareBothDirectoryWithDifferentContent1"); var result = comparer.Compare(dirA.FullName, dirB.FullName); dirTemp.Delete(true); Assert.AreEqual(result[0].FileDetails.Count, result[1].FileDetails.Count); Assert.IsTrue(result[0].FileDetails[0].ExistsBothFolder); Assert.IsTrue(result[1].FileDetails[0].ExistsBothFolder); Assert.IsFalse(result[0].FileDetails[0].HasSameContentWithAnotherFileName); Assert.IsFalse(result[1].FileDetails[0].HasSameContentWithAnotherFileName); Assert.IsTrue(result[0].FileDetails[0].IsContentSame); Assert.IsTrue(result[1].FileDetails[0].IsContentSame); Assert.IsFalse(result[0].FileDetails[0].IsDateModifiedSame); Assert.IsFalse(result[1].FileDetails[0].IsDateModifiedSame); Assert.IsTrue(result[0].FileDetails[0].IsFolder); Assert.IsTrue(result[1].FileDetails[0].IsFolder); }
/// <exclude /> public static void AddZip(string providerName, string parentPath, Stream compressedStream, bool recreateDirStructure, bool overwrite) { Verify.ArgumentNotNullOrEmpty(providerName, nameof(providerName)); Verify.ArgumentNotNullOrEmpty(parentPath, nameof(parentPath)); IList <IMediaFile> files; IList <IMediaFileFolder> folders; Extract(parentPath, compressedStream, out folders, out files); if (recreateDirStructure) { var folderComparer = new FolderComparer(); var currentDirs = DataFacade.GetData <IMediaFileFolder>().Where(x => x.Path.StartsWith(parentPath)); folders = folders.Except(currentDirs, folderComparer).ToList(); DataFacade.AddNew <IMediaFileFolder>(folders, providerName); AddFiles(providerName, files, overwrite); } else { foreach (IMediaFile file in files) { file.FolderPath = parentPath; } AddFiles(providerName, files, overwrite); } }
/// <exclude /> public static void AddZip(string providerName, string parentPath, Stream compressedStream, bool recreateDirStructure, bool overwrite) { if (string.IsNullOrEmpty(providerName)) { throw new ArgumentNullException("providerName"); } if (string.IsNullOrEmpty(parentPath)) { throw new ArgumentNullException("parentPath"); } IList <IMediaFile> files; IList <IMediaFileFolder> folders; Extract(parentPath, compressedStream, out folders, out files); if (recreateDirStructure) { FolderComparer folderComparer = new FolderComparer(); IEnumerable <IMediaFileFolder> currentDirs = DataFacade.GetData <IMediaFileFolder>().Where(x => x.Path.StartsWith(parentPath)); IEnumerable <IMediaFileFolder> intersection = currentDirs.Intersect(folders, folderComparer); folders = folders.Except(intersection, folderComparer).ToList(); DataFacade.AddNew <IMediaFileFolder>(folders, providerName); AddFiles(providerName, files, overwrite); } else { foreach (IMediaFile file in files) { file.FolderPath = parentPath; } AddFiles(providerName, files, overwrite); } }
protected FoldersModel GetFoldersModel() { var member = CurrentMember; if (member == null) { return(null); } // Get the folders and their counts. var folderData = new Dictionary <Guid, FolderDataModel>(); // Flag list. var flagList = _jobAdFlagListsQuery.GetFlagList(member); var count = _jobAdFlagListsQuery.GetFlaggedCount(member); folderData[flagList.Id] = new FolderDataModel { Count = count, CanRename = false }; // Folders. var folders = _jobAdFoldersQuery.GetFolders(member); var counts = _jobAdFoldersQuery.GetInFolderCounts(member); var lastUsedTimes = _jobAdFoldersQuery.GetLastUsedTimes(member); foreach (var folder in folders) { folderData[folder.Id] = new FolderDataModel { Count = GetCount(folder.Id, counts), CanRename = _jobAdFoldersCommand.CanRenameFolder(member, folder), }; } var comparer = new FolderComparer(lastUsedTimes); return(new FoldersModel { FlagList = flagList, MobileFolder = folders.Single(f => f.FolderType == FolderType.Mobile), PrivateFolders = folders.Where(f => f.FolderType == FolderType.Private).OrderBy(f => f, comparer).ToList(), FolderData = folderData, }); }
private static async Task UpdateApp(DesignHub ctx, AppPackage from, ApplicationModel localAppModel) { //TODO:考虑删除本地已签出的所有变更 //TODO:1.签出本地对应App的所有节点,包括模型根节点 var local = new AppPackage(); await ModelStore.LoadToAppPackage(localAppModel.Id, localAppModel.Name, local); var publish = new PublishPackage(); //----比对文件夹---- var folderComparer = new FolderComparer(); var newFolders = from.Folders.Except(local.Folders, folderComparer); foreach (var newFolder in newFolders) { newFolder.Import(); publish.Folders.Add(newFolder); } //var removedFolders = local.Folders.Except(from.Folders, folderComparer); //foreach (var removedFolder in removedFolders) //{ // removedFolder.Remove(); // publish.Folders.Add(removedFolder); //} var otherFolders = local.Folders.Intersect(from.Folders, folderComparer); foreach (var folder in otherFolders) { if (folder.UpdateFrom(from.Folders.Single(t => t.TargetModelType == folder.TargetModelType && t.Id == folder.Id))) { publish.Folders.Add(folder); } } //----比对模型---- var modelComparer = new ModelComparer(); var newModels = from.Models.Except(local.Models, modelComparer); foreach (var newModel in newModels) { newModel.Import(); publish.Models.Add(newModel); //导入相关代码及Assembly if (newModel.ModelType == ModelType.Service) { publish.SourceCodes.Add(newModel.Id, from.SourceCodes[newModel.Id]); var key = $"{from.Application.Name}.{newModel.Name}"; publish.ServiceAssemblies.Add(key, from.ServiceAssemblies[key]); } else if (newModel.ModelType == ModelType.View) { publish.SourceCodes.Add(newModel.Id, from.SourceCodes[newModel.Id]); var key = $"{from.Application.Name}.{newModel.Name}"; publish.ViewAssemblies.Add(key, from.ViewAssemblies[key]); } } //if (localAppModel.ID != SysGlobal.SysString) //注意:系统应用包不移除仅本地有的模型 //{ var removedModles = local.Models.Except(from.Models, modelComparer); foreach (var removedModel in removedModles) { removedModel.MarkDeleted(); publish.Models.Add(removedModel); //删除模型的相关代码组件等由PublishService处理,不用再加入 } //} var otherModels = local.Models.Intersect(from.Models, modelComparer); foreach (var model in otherModels) { if (model.UpdateFrom(from.Models.Single(t => t.ModelType == model.ModelType && t.Id == model.Id))) { publish.Models.Add(model); } if (model.ModelType == ModelType.Service) { publish.SourceCodes.Add(model.Id, from.SourceCodes[model.Id]); var key = $"{from.Application.Name}.{model.Name}"; publish.ServiceAssemblies.Add(key, from.ServiceAssemblies[key]); } else if (model.ModelType == ModelType.View) { publish.SourceCodes.Add(model.Id, from.SourceCodes[model.Id]); var key = $"{from.Application.Name}.{model.Name}"; publish.ViewAssemblies.Add(key, from.ViewAssemblies[key]); } } //发布变更的包 await PublishService.PublishAsync(ctx, publish, "Import"); }