public async Task<bool> SaveModuleAsync(ModuleModelProxy module) { var dict = new Dictionary<string, object>(); var properties = new Dictionary<string, object>(); var contentLink = new Dictionary<string, object>(); contentLink.Add("uri", module.ModuleUrl); contentLink.Add("version", module.ModuleVersion); properties.Add("contentLink", contentLink); dict.Add("properties", properties); await SendRequestAsync("modules/" + module.ModuleName.ToUrlSafeString(), HttpMethod.Put, JsonConvert.SerializeObject(dict), "application/json"); return true; }
public async Task<bool> SaveModuleAsync(ModuleModelProxy module) { var contentLink = new ContentLink(); contentLink.Uri = new Uri(module.ModuleUrl); contentLink.Version = module.ModuleVersion; var moduleToSave = new ModuleCreateOrUpdateParameters(); moduleToSave.Name = module.ModuleName; moduleToSave.Location = _connectionData.AzureRMLocation; moduleToSave.Properties = new ModuleCreateOrUpdateProperties(); moduleToSave.Properties.ContentLink = contentLink; var response = await _client.Modules.CreateOrUpdateAsync(_connectionData.AzureRMGroupName, _connectionData.AzureAutomationAccount, moduleToSave); if (response.StatusCode == System.Net.HttpStatusCode.InternalServerError) { _output.AppendLine("Unable to save the module at the moment, please verify your connectivity and try again."); return false; } return true; }
public Task<bool> SaveModuleAsync(ModuleModelProxy module) { Logger.DebugFormat("SaveSmaModule(...)"); var context = GetConnection(); var rawModule = module.Model as SMA.Module; if (module.ModuleID == Guid.Empty) { context.AddToModules(rawModule); } else { var foundModule = context.Modules.Where(s => s.ModuleID == module.ModuleID).FirstOrDefault(); if (foundModule == null) { // The module doesn't exist // NOTE: This suggests that the module may have been created in another // environment and then reconnected to another SMA instance. How should this be handled? context.AddToModules(rawModule); } foundModule.ModuleName = module.ModuleName; context.UpdateObject(foundModule); } context.SaveChanges(); return new Task<bool>(() => { return true; }); }