Beispiel #1
0
 /// <summary>
 /// Initializes a new instance of the
 /// DataLakeAnalyticsAccountCreateOrUpdateParameters class with
 /// required arguments.
 /// </summary>
 public DataLakeAnalyticsAccountCreateOrUpdateParameters(DataLakeAnalyticsAccount dataLakeAnalyticsAccount)
     : this()
 {
     if (dataLakeAnalyticsAccount == null)
     {
         throw new ArgumentNullException("dataLakeAnalyticsAccount");
     }
     this.DataLakeAnalyticsAccount = dataLakeAnalyticsAccount;
 }
 /// <summary>
 /// Initializes a new instance of the
 /// DataLakeAnalyticsAccountCreateOrUpdateParameters class with
 /// required arguments.
 /// </summary>
 public DataLakeAnalyticsAccountCreateOrUpdateParameters(DataLakeAnalyticsAccount dataLakeAnalyticsAccount)
     : this()
 {
     if (dataLakeAnalyticsAccount == null)
     {
         throw new ArgumentNullException("dataLakeAnalyticsAccount");
     }
     this.DataLakeAnalyticsAccount = dataLakeAnalyticsAccount;
 }
        public DataLakeAnalyticsAccount CreateOrUpdateAccount(string resourceGroupName, string accountName,
            string location,
            DataLakeStoreAccountInfo defaultDataLakeStoreAccount = null,
            IList<DataLakeStoreAccountInfo> additionalDataLakeStoreAccounts = null,
            IList<StorageAccountInfo> additionalStorageAccounts = null,
            Hashtable customTags = null)
        {
            if (string.IsNullOrEmpty(resourceGroupName))
            {
                resourceGroupName = GetResourceGroupByAccountName(accountName);
            }

            var tags = TagsConversionHelper.CreateTagDictionary(customTags, true);

            var parameters = new DataLakeAnalyticsAccount
            {
                Name = accountName,
                Location = location,
                Tags = tags ?? new Dictionary<string, string>()
            };


            parameters.Properties = new DataLakeAnalyticsAccountProperties();

            if (defaultDataLakeStoreAccount != null)
            {
                parameters.Properties.DefaultDataLakeStoreAccount =
                    defaultDataLakeStoreAccount.Name;
            }

            if (additionalStorageAccounts != null && additionalStorageAccounts.Count > 0)
            {
                parameters.Properties.StorageAccounts = additionalStorageAccounts;
            }

            if (additionalDataLakeStoreAccounts != null && additionalDataLakeStoreAccounts.Count > 0)
            {
                if (defaultDataLakeStoreAccount != null)
                {
                    additionalDataLakeStoreAccounts.Add(defaultDataLakeStoreAccount);
                }

                parameters.Properties.DataLakeStoreAccounts = additionalDataLakeStoreAccounts;
            }
            else if (defaultDataLakeStoreAccount != null)
            {
                parameters.Properties.DataLakeStoreAccounts = new List<DataLakeStoreAccountInfo>
                {
                    defaultDataLakeStoreAccount
                };
            }

            var accountExists = false;
            try
            {
                if (GetAccount(resourceGroupName, accountName) != null)
                {
                    accountExists = true;
                }
            }
            catch
            {
                // intentionally empty since if there is any exception attempting to 
                // get the account we know it doesn't exist and we will attempt to create it fresh.
            }

            return accountExists
                ? _accountClient.Account.Update(resourceGroupName, accountName, parameters)
                : _accountClient.Account.Create(resourceGroupName, accountName, parameters);
        }