private void DoMigrate(IServerConnection source, IServerConnection target, string resourceId, string[] dependentResourceIds, bool overwrite) { var diag = new ProgressDialog(); diag.CancelAbortsThread = true; var method = new ProgressDialog.DoBackgroundWork((worker, e, args) => { var src = (IServerConnection)args[0]; var dst = (IServerConnection)args[1]; var resId = (string)args[2]; var dependents = (string[])args[3]; var overwriteExisting = (bool)args[4]; var cb = new LengthyOperationProgressCallBack((sender, cbe) => { worker.ReportProgress(cbe.Progress, cbe.StatusMessage); }); var migrator = new ResourceMigrator(source, target); migrator.MigrateResource(resId, dependentResourceIds, overwriteExisting, cb); return true; }); diag.RunOperationAsync(Workbench.Instance, method, source, target, resourceId, dependentResourceIds, overwrite); }
internal string[] CopyResourcesToFolder(RepositoryHandle[] data, string targetConnectionName, string folderId) { string rootSourceParent = GetCommonParent(data); //There is an implicit assumption here that all items dropped come from the same connection var sourceConn = data.First().Connection; var targetConn = _connManager.GetConnection(targetConnectionName); var migrator = new ResourceMigrator(sourceConn, targetConn); //Collect all source ids var sourceIds = new List<string>(); foreach (var resId in data.Select(x => x.ResourceId.ToString())) { if (ResourceIdentifier.IsFolderResource(resId)) sourceIds.AddRange(GetFullResourceList(sourceConn, resId)); else sourceIds.Add(resId); } var targets = new List<string>(); foreach (var resId in sourceIds) { var dstId = resId.Replace(rootSourceParent, folderId); System.Diagnostics.Trace.TraceInformation("{0} => {1}", resId, dstId); //NOXLATE targets.Add(dstId); } bool overwrite = true; var existing = new List<string>(); foreach (var resId in targets) { if (targetConn.ResourceService.ResourceExists(resId)) { existing.Add(resId); } } if (existing.Count > 0) overwrite = MessageService.AskQuestion(string.Format(Strings.PromptOverwriteOnTargetConnection, existing.Count)); var wb = Workbench.Instance; var dlg = new ProgressDialog(); var worker = new ProgressDialog.DoBackgroundWork((w, evt, args) => { LengthyOperationProgressCallBack cb = (s, cbe) => { w.ReportProgress(cbe.Progress, cbe.StatusMessage); }; return migrator.CopyResources(sourceIds.ToArray(), targets.ToArray(), overwrite, new RebaseOptions(rootSourceParent, folderId), cb); }); var result = (string[])dlg.RunOperationAsync(wb, worker); RefreshModel(targetConn.DisplayName, folderId); ExpandNode(targetConn.DisplayName, folderId); return result; }
private static int DoMigrate(OSGeo.MapGuide.MaestroAPI.IServerConnection source, OSGeo.MapGuide.MaestroAPI.IServerConnection target, CopyMoveToServerDialog migrate) { var diag = new ProgressDialog(); diag.CancelAbortsThread = true; var method = new ProgressDialog.DoBackgroundWork((worker, e, args) => { var src = (IServerConnection)args[0]; var dst = (IServerConnection)args[1]; var ids = (string[])args[2]; var folder = (string)args[3]; var overwrite = (bool)args[4]; var act = (MigrationAction)args[5]; var cb = new LengthyOperationProgressCallBack((sender, cbe) => { worker.ReportProgress(cbe.Progress, cbe.StatusMessage); }); var migrator = new ResourceMigrator(source, target); int affected = 0; switch (act) { case MigrationAction.Copy: affected = migrator.CopyResources(ids, folder, overwrite, cb); break; case MigrationAction.Move: affected = migrator.MoveResources(ids, folder, overwrite, cb); break; } return affected; }); return (int)diag.RunOperationAsync(Workbench.Instance, method, source, target, migrate.SourceResourceIds, migrate.TargetFolder, migrate.OverwriteResources, migrate.SelectedAction); }