public async Task<bool> SaveVariableAsync(VariableModelProxy variable) { var dict = new Dictionary<string, object>(); var properties = new Dictionary<string, object>(); properties.Add("isEncrypted", variable.IsEncrypted); properties.Add("value", variable.Value); dict.Add("properties", properties); if (variable.VariableID == Guid.Empty) { // New variable await SendRequestAsync("variables/" + variable.Name.ToUrlSafeString(), HttpMethod.Put, JsonConvert.SerializeObject(dict), "application/json"); } else { await SendRequestAsync("variables/" + variable.Name.ToUrlSafeString(), new HttpMethod("PATCH"), JsonConvert.SerializeObject(dict), "application/json"); } return true; }
public async Task<bool> SaveVariableAsync(VariableModelProxy variable) { var variableToSave = new VariableCreateOrUpdateParameters(); variableToSave.Name = variable.Name; variableToSave.Properties = new VariableCreateOrUpdateProperties(); variableToSave.Properties.IsEncrypted = variable.IsEncrypted; variableToSave.Properties.Value = variable.Value; var response = await _client.Variables.CreateOrUpdateAsync(_connectionData.AzureRMGroupName, _connectionData.AzureAutomationAccount, variableToSave); if (response.StatusCode == System.Net.HttpStatusCode.InternalServerError) { _output.AppendLine("Unable to save the variable at the moment, please verify your connectivity and try again."); return false; } return true; }
public Task<bool> SaveVariableAsync(VariableModelProxy variable)//(OrchestratorApi context, IViewModel instance) { var context = GetConnection(); Logger.DebugFormat("SaveSmaVariable(...)"); var rawVariable = variable.Model as SMA.Variable; if (variable.VariableID == Guid.Empty) { context.AddToVariables(rawVariable); } else { var foundVariable = context.Variables.Where(v => v.VariableID == variable.VariableID).FirstOrDefault(); if (foundVariable == null) { // The variable doesn't exist // NOTE: This suggests that the variable may be created in another // environment and then reconnected to another SMA instance. How should this be handled? context.AddToVariables(rawVariable); } foundVariable.Name = variable.Name; if (!foundVariable.IsEncrypted) { foundVariable.Value = variable.Value; foundVariable.IsEncrypted = variable.IsEncrypted; } context.UpdateObject(foundVariable); } context.SaveChanges(); return new Task<bool>(() => { return true; }); }