/// <summary> /// Initializes a new instance of the /// ConnectionCreateOrUpdateParameters class with required arguments. /// </summary> public ConnectionCreateOrUpdateParameters(string name, ConnectionCreateOrUpdateProperties properties) : this() { if (name == null) { throw new ArgumentNullException("name"); } if (properties == null) { throw new ArgumentNullException("properties"); } this.Name = name; this.Properties = properties; }
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); }
public static async Task UploadToCloud(ICollection<AutomationAsset> assetsToUpload, AutomationManagementClient automationApi, string resourceGroupName, string automationAccountName) { var jss = new JavaScriptSerializer(); foreach (var assetToUpload in assetsToUpload) { CancellationTokenSource cts = new CancellationTokenSource(); cts.CancelAfter(TIMEOUT_MS); if (assetToUpload is AutomationVariable) { var asset = (AutomationVariable)assetToUpload; var properties = new VariableCreateOrUpdateProperties(); properties.IsEncrypted = asset.Encrypted; var stringBuilder = new StringBuilder(); jss.Serialize(asset.getValue(), stringBuilder); properties.Value = stringBuilder.ToString(); await automationApi.Variables.CreateOrUpdateAsync(resourceGroupName, automationAccountName, new VariableCreateOrUpdateParameters(asset.Name, properties), cts.Token); } else if(assetToUpload is AutomationCredential) { var asset = (AutomationCredential)assetToUpload; var properties = new CredentialCreateOrUpdateProperties(); properties.UserName = asset.getUsername(); properties.Password = asset.getPassword(); await automationApi.PsCredentials.CreateOrUpdateAsync(resourceGroupName, automationAccountName, new CredentialCreateOrUpdateParameters(asset.Name, properties), cts.Token); } else if (assetToUpload is AutomationConnection) { var asset = (AutomationConnection)assetToUpload; var properties = new ConnectionCreateOrUpdateProperties(); var connectionFieldsAsJson = new Dictionary<string, string>(); foreach(KeyValuePair<string, object> field in asset.getFields()) { connectionFieldsAsJson.Add(field.Key, field.Value.ToString()); } properties.FieldDefinitionValues = connectionFieldsAsJson; properties.ConnectionType = new ConnectionTypeAssociationProperty(); properties.ConnectionType.Name = asset.ConnectionType; await automationApi.Connections.CreateOrUpdateAsync(resourceGroupName, automationAccountName, new ConnectionCreateOrUpdateParameters(asset.Name, properties), cts.Token); } // TODO: implement certificates } }
public static async Task UploadToCloud(ICollection<AutomationAsset> assetsToUpload, AutomationManagementClient automationApi, string resourceGroupName, string automationAccountName) { var jss = new JavaScriptSerializer(); foreach (var assetToUpload in assetsToUpload) { CancellationTokenSource cts = new CancellationTokenSource(); cts.CancelAfter(TIMEOUT_MS); if (assetToUpload is AutomationVariable) { var asset = (AutomationVariable)assetToUpload; var properties = new VariableCreateOrUpdateProperties(); properties.IsEncrypted = asset.Encrypted; var stringBuilder = new StringBuilder(); jss.Serialize(asset.getValue(), stringBuilder); properties.Value = stringBuilder.ToString(); await automationApi.Variables.CreateOrUpdateAsync(resourceGroupName, automationAccountName, new VariableCreateOrUpdateParameters(asset.Name, properties), cts.Token); } else if(assetToUpload is AutomationCredential) { var asset = (AutomationCredential)assetToUpload; var properties = new CredentialCreateOrUpdateProperties(); properties.UserName = asset.getUsername(); properties.Password = asset.getPassword(); await automationApi.PsCredentials.CreateOrUpdateAsync(resourceGroupName, automationAccountName, new CredentialCreateOrUpdateParameters(asset.Name, properties), cts.Token); } else if (assetToUpload is AutomationConnection) { var asset = (AutomationConnection)assetToUpload; var properties = new ConnectionCreateOrUpdateProperties(); var connectionFieldsAsJson = new Dictionary<string, string>(); foreach(KeyValuePair<string, object> field in asset.getFields()) { connectionFieldsAsJson.Add(field.Key, field.Value.ToString()); } properties.FieldDefinitionValues = connectionFieldsAsJson; properties.ConnectionType = new ConnectionTypeAssociationProperty(); properties.ConnectionType.Name = asset.ConnectionType; await automationApi.Connections.CreateOrUpdateAsync(resourceGroupName, automationAccountName, new ConnectionCreateOrUpdateParameters(asset.Name, properties), cts.Token); } else if (assetToUpload is AutomationCertificate) { var asset = (AutomationCertificate)assetToUpload; var cert = (asset.getPassword() == null) ? new X509Certificate2(asset.getCertPath(), String.Empty, X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet) : new X509Certificate2(asset.getCertPath(), asset.getPassword(), X509KeyStorageFlags.Exportable | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.MachineKeySet); var properties = new CertificateCreateOrUpdateProperties() { Base64Value = Convert.ToBase64String(cert.Export(X509ContentType.Pkcs12)), Thumbprint = cert.Thumbprint, IsExportable = asset.getExportable() }; await automationApi.Certificates.CreateOrUpdateAsync(resourceGroupName, automationAccountName, new CertificateCreateOrUpdateParameters(asset.Name, properties), cts.Token); } } }