public ConnectionModelProxy GetConnectionDetails(ConnectionModelProxy connection) { var response = _client.Connections.Get(_connectionData.AzureRMGroupName, _connectionData.AzureAutomationAccount, connection.Name); if (response.Connection != null) { var connectionType = (Vendor.Azure.ConnectionType)connection.ConnectionType; foreach (var entry in response.Connection.Properties.FieldDefinitionValues) { var field = connectionType.ConnectionFields.FirstOrDefault(item => item.Name.Equals(entry.Key, StringComparison.InvariantCultureIgnoreCase)); var fieldValue = new Vendor.Azure.ConnectionFieldValue(); fieldValue.Connection = (Vendor.Azure.Connection)connection.Model; fieldValue.ConnectionFieldName = field.Name; fieldValue.ConnectionName = fieldValue.Connection.Name; fieldValue.ConnectionTypeName = connectionType.Name; fieldValue.IsEncrypted = field.IsEncrypted; fieldValue.IsOptional = field.IsOptional; fieldValue.Value = entry.Value; fieldValue.Type = field.Type; (connection.ConnectionFieldValues as List<Vendor.Azure.ConnectionFieldValue>).Add(fieldValue); } } return connection; }
public async Task<bool> SaveConnectionAsync(ConnectionModelProxy connection) { var connectionToSave = new ConnectionCreateOrUpdateParameters(); connectionToSave.Name = connection.Name; connectionToSave.Properties = new ConnectionCreateOrUpdateProperties(); connectionToSave.Properties.ConnectionType = new ConnectionTypeAssociationProperty(); var connectionType = (connection.ConnectionType as Vendor.Azure.ConnectionType); connectionToSave.Properties.ConnectionType.Name = connectionType.Name; connectionToSave.Properties.Description = connection.Description; var fieldValues = connection.ConnectionFieldValues as IList<Vendor.Azure.ConnectionFieldValue>; foreach (var key in fieldValues) { connectionToSave.Properties.FieldDefinitionValues.Add(key.ConnectionFieldName, key.Value); } var response = await _client.Connections.CreateOrUpdateAsync(_connectionData.AzureRMGroupName, _connectionData.AzureAutomationAccount, connectionToSave); if (response.StatusCode == System.Net.HttpStatusCode.InternalServerError) { _output.AppendLine("Unable to save the connection at the moment, please verify your connectivity and try again."); return false; } return true; }
public ConnectionModelProxy GetConnectionDetails(ConnectionModelProxy connection) { var connectionContent = SendRequest("connections/" + connection.Name, HttpMethod.Get); if (connectionContent.Length == 0) return null; dynamic connectionRaw = JObject.Parse(connectionContent); var connectionType = (ConnectionType)connection.ConnectionType; foreach (var entry in connectionRaw.properties.fieldDefinitionValues) { var field = connectionType.ConnectionFields.FirstOrDefault(item => item.Name.Equals(entry.Name, StringComparison.InvariantCultureIgnoreCase)); var fieldValue = new ConnectionFieldValue(); fieldValue.Connection = (Connection)connection.Model; fieldValue.ConnectionFieldName = field.Name; fieldValue.ConnectionName = fieldValue.Connection.Name; fieldValue.ConnectionTypeName = connectionType.Name; fieldValue.IsEncrypted = field.IsEncrypted; fieldValue.IsOptional = field.IsOptional; fieldValue.Value = entry.Value; fieldValue.Type = field.Type; (connection.ConnectionFieldValues as List<ConnectionFieldValue>).Add(fieldValue); } return connection; }
public async Task<bool> SaveConnectionAsync(ConnectionModelProxy connection) { var dict = new Dictionary<string, object>(); var properties = new Dictionary<string, object>(); properties.Add("description", connection.Description); var connectionType = new Dictionary<string, object>(); connectionType.Add("name", (connection.ConnectionType as ConnectionType).Name); properties.Add("connectionType", connectionType); var fieldDefinitionValues = new Dictionary<string, object>(); foreach (var field in (connection.ConnectionFieldValues as List<ConnectionFieldValue>)) { fieldDefinitionValues.Add(field.ConnectionFieldName, field.Value); } properties.Add("fieldDefinitionValues", fieldDefinitionValues); dict.Add("name", connection.Name); dict.Add("properties", properties); await SendRequestAsync("connections/" + connection.Name.ToUrlSafeString(), HttpMethod.Put, JsonConvert.SerializeObject(dict), "application/json"); return true; }
public Task<bool> SaveConnectionAsync(ConnectionModelProxy connection) { Logger.DebugFormat("SaveSmaConnection(...)"); var context = GetConnection(); var rawConnection = connection.Model as SMA.Connection; if (connection.ConnectionID == Guid.Empty) { context.AddToConnections(rawConnection); } else { var foundConnection = context.Connections.Where(s => s.ConnectionID == connection.ConnectionID).FirstOrDefault(); if (foundConnection == null) { // The connection doesn't exist // NOTE: This suggests that the connection may have been created in another // environment and then reconnected to another SMA instance. How should this be handled? context.AddToConnections(rawConnection); } foundConnection.Name = connection.Name; context.UpdateObject(foundConnection); } context.SaveChanges(); return new Task<bool>(() => { return true; }); }
public ConnectionModelProxy GetConnectionDetails(ConnectionModelProxy connection) { try { var context = GetConnection(); var conn = context.Connections.FirstOrDefault(item => item.ConnectionID.Equals(connection.ConnectionID)); if (conn == null) return null; foreach (var entry in conn.ConnectionFieldValues) { (connection.ConnectionFieldValues as List<ConnectionFieldValue>).Add(entry); } return connection; } catch (Exception ex) { throw new ApplicationException("Unable to retrieve connection details. Please refer to the output for more information.", ex); } }