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(); }); }
public CredentialViewModel(CredentialModelProxy credential) { model = credential;//new CredentialModelProxy(credential); if (credential.CredentialID == Guid.Empty) { UnsavedChanges = true; } Owner = credential.Context.Service; LongRunningOperation.Stop(); }
public ScheduleViewModel(ScheduleModelProxy schedule) { model = schedule; if (schedule.ScheduleID == Guid.Empty) { UnsavedChanges = true; } Owner = schedule.Context.Service; 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(); }); }
public ModuleViewModel(ModuleModelProxy module) { model = module; UnsavedChanges = true; Owner = module.Context.Service; if (module.ModuleName != null) { ModuleName = module.ModuleName; } else { ModuleName = string.Empty; } ModuleVersion = "1.0.0.0"; LongRunningOperation.Stop(); }
public VariableViewModel(VariableModelProxy variable) { model = variable; if (variable.VariableID == Guid.Empty) { UnsavedChanges = true; } if (variable.IsEncrypted) { value = "<Encrypted value>"; } else { value = JsonConverter.FromJson(variable.Value).ToString(); } Owner = variable.Context.Service; 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"); } }
public ConnectionViewModel(ConnectionModelProxy connection) { model = connection; if (connection != null && String.IsNullOrEmpty(connection.Name)) { UnsavedChanges = true; } Owner = connection.Context.Service; ConnectionTypes = new ObservableCollection <ConnectionTypeModelProxy>(); Parameters = new ObservableCollection <ConnectionViewParameter>(); Task.Run(() => { // We need to read the info from our backend again since we don't // get any property values when enumerating all connections try { if (connection.ConnectionType != null) { connection = connection.Context.Service.GetConnectionDetails(connection); } var result = Owner.GetConnectionTypes(); var connectionTypeNameProp = default(PropertyInfo); if (connection.ConnectionType != null) { connectionTypeNameProp = connection.ConnectionType.GetType().GetProperty("Name"); } var connectionTypeName = string.Empty; if (connectionTypeNameProp != null) { connectionTypeName = connectionTypeNameProp.GetValue(connection.ConnectionType).ToString(); } Execute.OnUIThread(() => { foreach (var type in result) { ConnectionTypes.Add(type); if (type.Name.Equals(connectionTypeName, StringComparison.InvariantCultureIgnoreCase)) { ConnectionType = type; } } if (Owner is AzureService && connection.ConnectionType != null) { var fields = (connection.ConnectionFieldValues as List <Vendor.Azure.ConnectionFieldValue>); if (fields.Count > 0) { Parameters.Clear(); foreach (var field in fields) { var paramName = field.ConnectionFieldName; if (field.IsEncrypted) { paramName = field.ConnectionFieldName + " (encrypted)"; } if (!field.IsOptional) { paramName += "*"; } Parameters.Add(new ConnectionViewParameter { DisplayName = paramName, Name = field.ConnectionFieldName, Value = field.Value }); } } } else if (Owner is SmaService && connection.ConnectionType != null) { var fields = (connection.ConnectionFieldValues as List <SMA.ConnectionFieldValue>); if (fields.Count > 0) { Parameters.Clear(); foreach (var field in fields) { var paramName = field.ConnectionFieldName; if (field.IsEncrypted) { paramName = field.ConnectionFieldName + " (encrypted)"; } if (field.IsOptional != null && field.IsOptional.HasValue && !field.IsOptional.Value) { paramName += "*"; } Parameters.Add(new ConnectionViewParameter { DisplayName = paramName, Name = field.ConnectionFieldName, Value = field.Value }); } } } LongRunningOperation.Stop(); }); } catch (ApplicationException ex) { LongRunningOperation.Stop(); GlobalExceptionHandler.Show(ex); } }); }
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)); } }
private void SubscribeToJob() { var job = default(JobModelProxy); Task.Run(() => { try { //AsyncExecution.Run(ThreadPriority.Normal, () => // Wait for the job ID to be set by our backend service while (_jobId == Guid.Empty) { if (_runbookViewModel.Runbook.JobID != null) { _jobId = _runbookViewModel.Runbook.JobID; } Thread.Sleep(1 * 1000); } if (_runbookViewModel.Runbook.JobID != null && _runbookViewModel.Runbook.JobID != Guid.Empty) { job = _backendService.GetJobDetails(_runbookViewModel.Runbook); } else if (_jobId != Guid.Empty) { job = _backendService.GetJobDetails(_jobId); } if (job != null) { Execute.OnUIThread(() => { foreach (var entry in job.Result) { Result.Add(entry); } JobStatus = job.JobStatus; NotifyOfPropertyChange(() => DisplayName); _propertyInfo = new ExecutionResultPropertyInfo(); _propertyInfo.JobID = (_jobId == null) ? Guid.Empty : (Guid)_jobId; _propertyInfo.RunbookID = (_runbookViewModel != null) ? ((RunbookModelProxy)_runbookViewModel.Model).RunbookID : Guid.Empty; _propertyInfo.RunbookName = (_runbookViewModel != null) ? ((RunbookModelProxy)_runbookViewModel.Model).RunbookName : "Unknown"; _propertyInfo.JobStatus = job.JobStatus; _propertyInfo.StartTime = job.StartTime; _propertyInfo.EndTime = job.EndTime; _propertyInfo.CreationTime = job.CreationTime; _propertyInfo.LastModifiedTime = job.LastModifiedTime; _propertyInfo.ErrorCount = job.ErrorCount; _propertyInfo.WarningCount = job.WarningCount; _propertyInfo.Exception = job.JobException; if (!string.IsNullOrEmpty(job.JobException)) { _output.AppendLine("Error when executing runbook:"); _output.AppendLine(job.JobException); _output.AppendLine(" "); } _inspectorTool.SelectedObject = _propertyInfo; }); } bool hasDisplayedException = false; while (!_completedExecutionStatus.Contains(job.JobStatus)) { job = _backendService.GetJobDetails(_runbookViewModel.Runbook); if (job != null) { Execute.OnUIThread(() => { JobStatus = job.JobStatus; NotifyOfPropertyChange(() => DisplayName); _propertyInfo.StartTime = job.StartTime; _propertyInfo.EndTime = job.EndTime; _propertyInfo.ErrorCount = job.ErrorCount; _propertyInfo.WarningCount = job.WarningCount; _propertyInfo.JobStatus = job.JobStatus; _propertyInfo.Exception = job.JobException; if (!String.IsNullOrEmpty(job.JobException) && !hasDisplayedException) { _output.AppendLine("Error when executing runbook:"); _output.AppendLine(job.JobException); _output.AppendLine(" "); hasDisplayedException = true; } _inspectorTool.SelectedObject = null; _inspectorTool.SelectedObject = _propertyInfo; foreach (var entry in job.Result) { Result.Add(entry); } }); } Thread.Sleep(5 * 1000); } // The job is completed _runbookViewModel.Runbook.JobID = Guid.Empty; LongRunningOperation.Stop(); } catch (Exception ex) { GlobalExceptionHandler.Show(ex); _runbookViewModel.Runbook.JobID = Guid.Empty; job.JobStatus = "Failed"; } }); if (job != null) { var output = IoC.Get <IOutput>(); output.AppendLine("Job executed with status: " + job.JobStatus); } }
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(); } }