Ejemplo n.º 1
0
        public override void Run()
        {
            var wb  = Workbench.Instance;
            var svc = ServiceRegistry.GetService <ServerConnectionManager>();
            var exp = wb.ActiveSiteExplorer;

            if (exp.SelectedItems.Length > 0)
            {
                var source = svc.GetConnection(exp.ConnectionName);
                var login  = new LoginDialog();
                if (login.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    var target  = login.Connection;
                    var migrate = new CopyMoveToServerDialog(source, target);

                    var srcIds = new List <string>();
                    foreach (var item in exp.SelectedItems)
                    {
                        srcIds.Add(item.ResourceId);
                    }

                    migrate.SourceResourceIds = srcIds.ToArray();

                    if (migrate.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                    {
                        int affected = DoMigrate(source, target, migrate);
                        MessageService.ShowMessage(string.Format(Strings.ItemsMigrated, affected));
                        if (affected > 0 && migrate.SelectedAction == MigrationAction.Move)
                        {
                            var parent = exp.SelectedItems[0].Parent;
                            if (parent != null)
                            {
                                exp.RefreshModel(source.DisplayName, parent.ResourceId);
                            }
                            else
                            {
                                exp.RefreshModel(source.DisplayName, StringConstants.RootIdentifier);
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
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));
        }