示例#1
0
        async Task ICommandHandler <SaveCommandDefinition> .Run(Command command)
        {
            await Task.Run(delegate()
            {
                LongRunningOperation.Start();

                model.Value     = JsonConverter.ToJson(value);
                model.ViewModel = this;

                try {
                    Owner.Save(this, command);
                    Owner.Context.AddToVariables(model);
                }
                catch (ApplicationException ex)
                {
                    GlobalExceptionHandler.Show(ex);
                }

                // Update the UI to notify that the changes has been saved
                UnsavedChanges = false;
                NotifyOfPropertyChange(() => DisplayName);

                LongRunningOperation.Stop();
            });
        }
        async Task ICommandHandler <SaveCommandDefinition> .Run(Command command)
        {
            await Task.Run(delegate()
            {
                LongRunningOperation.Start();

                //model.Value = JsonConverter.ToJson(value);
                model.ViewModel      = this;
                model.Description    = Description;
                model.ConnectionType = ConnectionType.Model;

                foreach (var param in Parameters)
                {
                    (model.ConnectionFieldValues as List <Vendor.Azure.ConnectionFieldValue>).Add(new Vendor.Azure.ConnectionFieldValue
                    {
                        ConnectionFieldName = param.Name,
                        Value = param.Value
                    });
                }

                try
                {
                    var contextType = (model.Model as BackendConnection).IsAzure ? ContextType.Azure : ContextType.SMA;

                    if ((model.Model as BackendConnection).IsAzureRM)
                    {
                        contextType = ContextType.AzureRM;
                    }

                    model.Context = new BackendContext(contextType, model.Model as BackendConnection);
                    Owner.Save(this, command);
                    Owner.Context.AddToConnections(model);
                }
                catch (ApplicationException ex)
                {
                    GlobalExceptionHandler.Show(ex);
                }

                // Update the UI to notify that the changes has been saved
                UnsavedChanges = false;
                NotifyOfPropertyChange(() => DisplayName);

                LongRunningOperation.Stop();
            });
        }
        private async void CopyToClicked(object sender, EventArgs e)
        {
            var menuItem = (MenuItem)sender;

            if (menuItem == null || menuItem.Tag == null)
            {
                return;
            }

            var selectedItem = _view.SelectedObject;

            if (selectedItem == null)
            {
                return;
            }

            var tag           = selectedItem.Tag;
            var copyToService = ((menuItem.Tag as ResourceContainer).Tag as BackendContext);

            LongRunningOperation.Start();

            if (tag is RunbookModelProxy)
            {
                var runbook = (tag as RunbookModelProxy);
                var result  = await copyToService.Copy(runbook);

                if (!result)
                {
                    MessageBox.Show("You can only copy the resource between different accounts.", "Error");
                }

                LongRunningOperation.Stop();
            }
            else
            {
                MessageBox.Show("Sorry, currently only runbooks are supported in the copy feature.", "Currently in work");
            }
        }
示例#4
0
        public void Execute(object parameter)
        {
            var shell = IoC.Get <IShell>();

            if (parameter is ResourceContainer)
            {
                // This command has been called from the Environment Explorer tool
                var viewItem = (ResourceContainer)parameter;

                if (viewItem.Tag is IBackendContext)
                {
                    LongRunningOperation.Start();

                    shell.StatusBar.Items[0].Message = "Loading data from " + (viewItem.Tag as IBackendContext).Name + "...";
                    Task.Run(() => {
                        try
                        {
                            (viewItem.Tag as IBackendContext).Start();
                        }
                        catch (AggregateException ex)
                        {
                            Caliburn.Micro.Execute.OnUIThread(() =>
                            {
                                if (ex.InnerException != null)
                                {
                                    MessageBox.Show(ex.InnerException.Message, "Error");
                                }
                                else
                                {
                                    MessageBox.Show(ex.Message, "Error");
                                }

                                LongRunningOperation.Stop();
                            });
                        }
                    });

                    return;
                }

                if (!(viewItem.Tag is ModelProxyBase))
                {
                    return;
                }

                LongRunningOperation.Start();
                shell.StatusBar.Items[0].Message = "Loading " + viewItem.Title + "...";

                Task.Run(delegate()
                {
                    var viewModel = (ModelProxyBase)viewItem.Tag;

                    if (viewItem.Tag is RunbookModelProxy)
                    {
                        shell.OpenDocument(viewModel.GetViewModel <RunbookViewModel>());
                    }
                    else if (viewItem.Tag is VariableModelProxy)
                    {
                        shell.OpenDocument(viewModel.GetViewModel <VariableViewModel>());
                    }
                    else if (viewItem.Tag is CredentialModelProxy)
                    {
                        shell.OpenDocument(viewModel.GetViewModel <CredentialViewModel>());
                    }
                    else if (viewItem.Tag is ScheduleModelProxy)
                    {
                        shell.OpenDocument(viewModel.GetViewModel <ScheduleViewModel>());
                    }
                    else if (viewItem.Tag is ConnectionModelProxy)
                    {
                        shell.OpenDocument(viewModel.GetViewModel <ConnectionViewModel>());
                    }

                    shell.StatusBar.Items[0].Message = "";

                    CommandManager.InvalidateRequerySuggested();
                });
            }
            else if (parameter is JobModelProxy)
            {
                // This command has been called from our Job History view
                var jobProxy = (JobModelProxy)parameter;

                shell.OpenDocument(new ExecutionResultViewModel(jobProxy.BoundRunbookViewModel, jobProxy.JobID, false));
            }
        }
示例#5
0
        public void Execute(object parameter)
        {
            if (parameter == null)
            {
                return;
            }

            if (!(parameter is ResourceContainer))
            {
                return;
            }

            if (((ResourceContainer)parameter).Tag == null)
            {
                return;
            }

            var backendService      = ((parameter as ResourceContainer).Tag as ModelProxyBase).Context.Service;
            var environmentExplorer = IoC.Get <EnvironmentExplorerViewModel>();

            if (MessageBox.Show("Are you sure you want to delete the object? This cannot be reverted.", "Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
            {
                LongRunningOperation.Start();
                var item = (ModelProxyBase)(parameter as ResourceContainer).Tag;

                // Make sure that we remove the object from the context as well
                if (item is RunbookModelProxy)
                {
                    backendService.Context.Runbooks.Remove(parameter as ResourceContainer);
                }
                else if (item is ConnectionModelProxy)
                {
                    backendService.Context.Connections.Remove(parameter as ResourceContainer);
                }
                else if (item is ScheduleModelProxy)
                {
                    backendService.Context.Schedules.Remove(parameter as ResourceContainer);
                }
                else if (item is VariableModelProxy)
                {
                    backendService.Context.Variables.Remove(parameter as ResourceContainer);
                }
                else if (item is ModuleModelProxy)
                {
                    backendService.Context.Modules.Remove(parameter as ResourceContainer);
                }
                else if (item is CredentialModelProxy)
                {
                    backendService.Context.Credentials.Remove(parameter as ResourceContainer);
                }

                try {
                    if (backendService.Delete(item))
                    {
                        environmentExplorer.Delete(parameter as ResourceContainer);
                    }
                }
                catch (ApplicationException ex)
                {
                    GlobalExceptionHandler.Show(ex);
                }

                LongRunningOperation.Stop();
            }
        }