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);
        }
Beispiel #2
0
        private void OnExecute(object sender, EventArgs e)
        {
            var pdlg = new ProgressDialog();

            pdlg.CancelAbortsThread = true;

            var worker = new ProgressDialog.DoBackgroundWork(ExecuteLoadProcedure);

            try
            {
                _ed.SyncSessionCopy();
                var result = pdlg.RunOperationAsync(this.ParentForm, worker, _ed, _lp);
                MessageBox.Show(Strings.OperationCompleted);
                _ed.RequestRefresh(_lp.SubType.RootPath);

                //Load procedure may have modified this resource as part of executioin
                _ed.SyncSessionCopy();
                //HACK: Force dirty state as successful execution writes some extra XML content to the resource
                _ed.MarkDirty();
            }
            catch (CancelException)
            {
                MessageBox.Show(Strings.OperationCancelled);
            }
        }
Beispiel #3
0
        private void DoSymbolExtraction(IServerConnection conn, string symbolLib, IEnumerable <string> symbols, string targetFolder)
        {
            var wb     = Workbench.Instance;
            var list   = new List <string>(symbols);
            var diag   = new ProgressDialog();
            var worker = new ProgressDialog.DoBackgroundWork(SymbolExtractionWorker);

            diag.RunOperationAsync(wb, worker, conn, symbolLib, list, targetFolder);
        }
Beispiel #4
0
        private void DoUpdateConfiguration(string[] toAdd, string[] toRemove, bool isAlias)
        {
            if (_conf == null)
            {
                BuildDefaultDocument();
            }

            var pdlg = new ProgressDialog();

            pdlg.CancelAbortsThread = true;
            var worker = new ProgressDialog.DoBackgroundWork(UpdateConfigurationDocument);
            var result = (UpdateConfigResult)pdlg.RunOperationAsync(null, worker, _conf, _service.CurrentConnection, toAdd, toRemove, isAlias);

            if (result.Added.Count > 0 || result.Removed.Count > 0)
            {
                _fs.SetConfigurationContent(_service.CurrentConnection, _conf.ToXml());
                List <ListViewItem> remove = new List <ListViewItem>();
                foreach (ListViewItem lvi in lstView.Items)
                {
                    if (result.Removed.Contains(lvi.Text))
                    {
                        remove.Add(lvi);
                    }
                }
                foreach (var added in result.Added)
                {
                    string dir      = null;
                    string fileName = null;
                    if (isAlias)
                    {
                        dir      = added.Substring(0, added.LastIndexOf("\\"));  //NOXLATE
                        fileName = added.Substring(added.LastIndexOf("\\") + 1); //NOXLATE
                    }
                    else
                    {
                        dir      = Path.GetDirectoryName(added);
                        fileName = Path.GetFileName(added);
                    }

                    foreach (var loc in _conf.RasterLocations)
                    {
                        if (loc.Location == dir)
                        {
                            foreach (var item in loc.Items)
                            {
                                if (item.FileName == fileName)
                                {
                                    AddRasterItem(dir, item);
                                }
                            }
                        }
                    }
                }
                OnResourceChanged();
            }
        }
        private static void DoRepointResource(Workbench wb, IServerConnection conn, ResourceIdentifier resId)
        {
            var diag = new RepointerDialog(resId, conn);

            if (diag.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                string srcId = diag.Source;
                string dstId = diag.Target;

                var deps = diag.Dependents;

                ProgressDialog.DoBackgroundWork worker = (wk, e, args) =>
                {
                    int updated = 0;
                    int total   = deps.Count;
                    wk.ReportProgress(0, Strings.ProgressUpdatingReferences);
                    foreach (var dep in deps)
                    {
                        using (var stream = conn.ResourceService.GetResourceXmlData(dep))
                        {
                            XmlDocument doc = new XmlDocument();
                            doc.Load(stream);
                            bool changed = Utility.ReplaceResourceIds(doc, srcId, dstId);
                            if (changed)
                            {
                                using (var ms = new MemoryStream())
                                {
                                    doc.Save(ms);
                                    ms.Position = 0L; //Rewind
                                    conn.ResourceService.SetResourceXmlData(dep, ms);
                                }
                                updated++;
                                wk.ReportProgress((updated / total) * 100);
                            }
                        }
                    }
                    return(updated);
                };
                var prd    = new ProgressDialog();
                int result = (int)prd.RunOperationAsync(wb, worker);
                MessageService.ShowMessage(string.Format(Strings.ResourcesRepointed, result, dstId));
            }
        }
Beispiel #6
0
        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));
        }
Beispiel #7
0
        private void DoUpdateConfiguration(string[] toAdd, string[] toRemove, bool isAlias)
        {
            if (_conf == null)
                BuildDefaultDocument();

            var pdlg = new ProgressDialog();
            pdlg.CancelAbortsThread = true;
            var worker = new ProgressDialog.DoBackgroundWork(UpdateConfigurationDocument);
            var result = (UpdateConfigResult)pdlg.RunOperationAsync(null, worker, _conf, _fs.CurrentConnection, toAdd, toRemove, isAlias);
            if (result.Added.Count > 0 || result.Removed.Count > 0)
            {
                _fs.SetConfigurationContent(_conf.ToXml());
                List<ListViewItem> remove = new List<ListViewItem>();
                foreach (ListViewItem lvi in lstView.Items)
                {
                    if (result.Removed.Contains(lvi.Text))
                        remove.Add(lvi);
                }
                foreach (var added in result.Added)
                {
                    string dir = null;
                    string fileName = null;
                    if (isAlias)
                    {
                        dir = added.Substring(0, added.LastIndexOf("\\")); //NOXLATE
                        fileName = added.Substring(added.LastIndexOf("\\") + 1); //NOXLATE
                    }
                    else
                    {
                        dir = Path.GetDirectoryName(added);
                        fileName = Path.GetFileName(added);
                    }

                    foreach (var loc in _conf.RasterLocations)
                    {
                        if (loc.Location == dir)
                        {
                            foreach (var item in loc.Items)
                            {
                                if (item.FileName == fileName)
                                {
                                    AddRasterItem(dir, item);
                                }
                            }
                        }
                    }
                }
                OnResourceChanged();
            }
        }
Beispiel #8
0
        private string[] MoveResourcesWithinConnection(string connectionName, ICollection<string> resIds, string folderId)
        {
            var wb = Workbench.Instance;
            var notMovedToTarget = new List<string>();
            var notMovedFromSource = new List<string>();
            var omgr = ServiceRegistry.GetService<OpenResourceManager>();
            var conn = _connManager.GetConnection(connectionName);

            var dlg = new ProgressDialog();
            var worker = new ProgressDialog.DoBackgroundWork((w, e, args) =>
            {
                LengthyOperationProgressCallBack cb = (sender, cbe) =>
                {
                    w.ReportProgress(cbe.Progress, cbe.StatusMessage);
                };

                var f = (string)args[0];
                var resourceIds = (ICollection<string>)args[1];

                foreach (var r in resourceIds)
                {
                    if (ResourceIdentifier.IsFolderResource(r))
                    {
                        //IMPORTANT: We need to tweak the target resource id
                        //otherwise the content *inside* the source folder is
                        //moved instead of the folder itself!
                        var rid = new ResourceIdentifier(r);
                        var target = folderId + rid.Name + "/"; //NOXLATE
                        conn.ResourceService.MoveResourceWithReferences(r, target, null, cb);
                    }
                    else
                    {
                        var rid = new ResourceIdentifier(r);
                        var target = folderId + rid.Name + "." + rid.Extension; //NOXLATE
                        if (omgr.IsOpen(r, conn))
                        {
                            notMovedFromSource.Add(r);
                            continue;
                        }

                        if (!omgr.IsOpen(target, conn))
                            conn.ResourceService.MoveResourceWithReferences(r, target, null, cb);
                        else
                            notMovedToTarget.Add(r);
                    }
                }

                //Collect affected folders and refresh them
                Dictionary<string, string> folders = new Dictionary<string, string>();
                folders.Add(folderId, folderId);
                foreach (var n in resourceIds)
                {
                    var ri = new ResourceIdentifier(n);
                    var parent = ri.ParentFolder;
                    if (parent != null && !folders.ContainsKey(parent))
                        folders.Add(parent, parent);
                }

                return folders.Keys;
            });

            var affectedFolders = (IEnumerable<string>)dlg.RunOperationAsync(wb, worker, folderId, resIds);

            if (notMovedToTarget.Count > 0 || notMovedFromSource.Count > 0)
            {
                MessageService.ShowMessage(string.Format(
                    Strings.NotCopiedOrMovedDueToOpenEditors,
                    Environment.NewLine + string.Join(Environment.NewLine, notMovedToTarget.ToArray()) + Environment.NewLine,
                    Environment.NewLine + string.Join(Environment.NewLine, notMovedFromSource.ToArray()) + Environment.NewLine));
            }

            return new List<string>(affectedFolders).ToArray();
        }
Beispiel #9
0
        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 string[] MoveResourcesWithinConnection(string connectionName, ICollection <string> resIds, string folderId)
        {
            var wb = Workbench.Instance;
            var notMovedToTarget   = new List <string>();
            var notMovedFromSource = new List <string>();
            var omgr = ServiceRegistry.GetService <OpenResourceManager>();
            var conn = _connManager.GetConnection(connectionName);

            var dlg    = new ProgressDialog();
            var worker = new ProgressDialog.DoBackgroundWork((w, e, args) =>
            {
                LengthyOperationProgressCallBack cb = (sender, cbe) =>
                {
                    w.ReportProgress(cbe.Progress, cbe.StatusMessage);
                };

                var f           = (string)args[0];
                var resourceIds = (ICollection <string>)args[1];

                foreach (var r in resourceIds)
                {
                    if (ResourceIdentifier.IsFolderResource(r))
                    {
                        //IMPORTANT: We need to tweak the target resource id
                        //otherwise the content *inside* the source folder is
                        //moved instead of the folder itself!
                        var rid    = new ResourceIdentifier(r);
                        var target = $"{folderId + rid.Name}/"; //NOXLATE
                        conn.ResourceService.MoveResourceWithReferences(r, target, null, cb);
                    }
                    else
                    {
                        var rid    = new ResourceIdentifier(r);
                        var target = $"{folderId + rid.Name}.{rid.Extension}"; //NOXLATE
                        if (omgr.IsOpen(r, conn))
                        {
                            notMovedFromSource.Add(r);
                            continue;
                        }

                        if (!omgr.IsOpen(target, conn))
                        {
                            conn.ResourceService.MoveResourceWithReferences(r, target, null, cb);
                        }
                        else
                        {
                            notMovedToTarget.Add(r);
                        }
                    }
                }

                //Collect affected folders and refresh them
                Dictionary <string, string> folders = new Dictionary <string, string>();
                folders.Add(folderId, folderId);
                foreach (var n in resourceIds)
                {
                    var ri     = new ResourceIdentifier(n);
                    var parent = ri.ParentFolder;
                    if (parent != null && !folders.ContainsKey(parent))
                    {
                        folders.Add(parent, parent);
                    }
                }

                return(folders.Keys);
            });

            var affectedFolders = (IEnumerable <string>)dlg.RunOperationAsync(wb, worker, folderId, resIds);

            if (notMovedToTarget.Count > 0 || notMovedFromSource.Count > 0)
            {
                MessageService.ShowMessage(string.Format(
                                               Strings.NotCopiedOrMovedDueToOpenEditors,
                                               Environment.NewLine + string.Join(Environment.NewLine, notMovedToTarget.ToArray()) + Environment.NewLine,
                                               Environment.NewLine + string.Join(Environment.NewLine, notMovedFromSource.ToArray()) + Environment.NewLine));
            }

            return(new List <string>(affectedFolders).ToArray());
        }
        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($"{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);
        }
Beispiel #13
0
        void OnExecute(object sender, EventArgs e)
        {
            var pdlg = new ProgressDialog();
            pdlg.CancelAbortsThread = true;

            var worker = new ProgressDialog.DoBackgroundWork(ExecuteLoadProcedure);
            try
            {
                _ed.SyncSessionCopy();
                var result = pdlg.RunOperationAsync(this.ParentForm, worker, _ed, _lp);
                MessageBox.Show(Strings.OperationCompleted);
                _ed.RequestRefresh(_lp.SubType.RootPath);

                //Load procedure may have modified this resource as part of executioin
                _ed.SyncSessionCopy();
                //HACK: Force dirty state as successful execution writes some extra XML content to the resource
                _ed.MarkDirty();
            }
            catch (CancelException)
            {
                MessageBox.Show(Strings.OperationCancelled);
            }
        }
Beispiel #14
0
        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);
        }