/// <summary>
 /// Create a connection.  (see
 /// http://aka.ms/azureautomationsdk/connectionoperations for more
 /// information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Automation.IConnectionOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group
 /// </param>
 /// <param name='automationAccount'>
 /// Required. The automation account name.
 /// </param>
 /// <param name='parameters'>
 /// Required. The parameters supplied to the create or update
 /// connection operation.
 /// </param>
 /// <returns>
 /// The response model for the create or update connection operation.
 /// </returns>
 public static ConnectionCreateOrUpdateResponse CreateOrUpdate(this IConnectionOperations operations, string resourceGroupName, string automationAccount, ConnectionCreateOrUpdateParameters parameters)
 {
     return Task.Factory.StartNew((object s) => 
     {
         return ((IConnectionOperations)s).CreateOrUpdateAsync(resourceGroupName, automationAccount, parameters);
     }
     , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult();
 }
 /// <summary>
 /// Create a connection.  (see
 /// http://aka.ms/azureautomationsdk/connectionoperations for more
 /// information)
 /// </summary>
 /// <param name='operations'>
 /// Reference to the
 /// Microsoft.Azure.Management.Automation.IConnectionOperations.
 /// </param>
 /// <param name='resourceGroupName'>
 /// Required. The name of the resource group
 /// </param>
 /// <param name='automationAccount'>
 /// Required. The automation account name.
 /// </param>
 /// <param name='parameters'>
 /// Required. The parameters supplied to the create or update
 /// connection operation.
 /// </param>
 /// <returns>
 /// The response model for the create or update connection operation.
 /// </returns>
 public static Task<ConnectionCreateOrUpdateResponse> CreateOrUpdateAsync(this IConnectionOperations operations, string resourceGroupName, string automationAccount, ConnectionCreateOrUpdateParameters parameters)
 {
     return operations.CreateOrUpdateAsync(resourceGroupName, automationAccount, parameters, CancellationToken.None);
 }
        public Connection CreateConnection(string resourceGroupName, string automationAccountName, string name, string connectionTypeName,
            IDictionary connectionFieldValues,
            string description)
        {
            var connectionModel = this.TryGetConnectionModel(resourceGroupName, automationAccountName, name);
            if (connectionModel != null)
            {
                throw new ResourceCommonException(typeof (Connection),
                    string.Format(CultureInfo.CurrentCulture, Resources.ConnectionAlreadyExists, name));
            }

            var ccprop = new ConnectionCreateOrUpdateProperties()
            {
                Description = description,
                ConnectionType = new ConnectionTypeAssociationProperty() {Name = connectionTypeName},
                FieldDefinitionValues =
                    connectionFieldValues.Cast<DictionaryEntry>()
                        .ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value.ToString())
            };

            var ccparam = new ConnectionCreateOrUpdateParameters() {Name = name, Properties = ccprop};

            var connection =
                this.automationManagementClient.Connections.CreateOrUpdate(resourceGroupName, automationAccountName, ccparam).Connection;

            return new Connection(resourceGroupName, automationAccountName, connection);
        }
Beispiel #4
0
        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;
        }