protected override void ProcessRecord()
        {
            DataLakeStoreAccount defaultAccount = null;
            if (!string.IsNullOrEmpty(DefaultDataLakeStore))
            {
                defaultAccount = new DataLakeStoreAccount
                {
                    Name = DefaultDataLakeStore
                };
            }

            WriteObject(DataLakeAnalyticsClient.CreateOrUpdateAccount(ResourceGroupName, Name, null, defaultAccount,
                    null, null, Tags));
        }
        public override void ExecuteCmdlet()
        {
            DataLakeStoreAccount defaultAccount = null;
            if (!string.IsNullOrEmpty(DefaultDataLakeStore))
            {
                defaultAccount = new DataLakeStoreAccount
                {
                    Name = DefaultDataLakeStore
                };
            }

            WriteObject(DataLakeAnalyticsClient.CreateOrUpdateAccount(ResourceGroupName, Name, null, defaultAccount,
                    null, null, Tags));
        }
        public override void ExecuteCmdlet()
        {
            if (ParameterSetName.Equals(BlobParameterSetName, StringComparison.InvariantCultureIgnoreCase))
            {
                var toAdd = new StorageAccount
                {
                    Name = Blob,
                    Properties = new StorageAccountProperties
                    {
                        AccessKey = AccessKey
                    }
                };

                DataLakeAnalyticsClient.AddStorageAccount(ResourceGroupName, Account, toAdd);
            }
            else
            {
                var toAdd = new DataLakeStoreAccount
                {
                    Name = DataLakeStore
                };

                DataLakeAnalyticsClient.AddDataLakeStoreAccount(ResourceGroupName, Account, toAdd);

                if (Default)
                {
                    DataLakeAnalyticsClient.SetDefaultDataLakeStoreAccount(ResourceGroupName, Account, toAdd);
                }
            }
        }
        protected override void ProcessRecord()
        {
            try
            {
                if (DataLakeAnalyticsClient.GetAcount(ResourceGroupName, Name) != null)
                {
                    throw new CloudException(string.Format(Resources.DataLakeAnalyticsAccountExists, Name));
                }
            }
            catch (CloudException ex)
            {
                if (ex.Error != null && !string.IsNullOrEmpty(ex.Error.Code) && ex.Error.Code == "ResourceNotFound" ||
                    ex.Message.Contains("ResourceNotFound"))
                {
                    // account does not exists so go ahead and create one
                }
                else if (ex.Error != null && !string.IsNullOrEmpty(ex.Error.Code) &&
                         ex.Error.Code == "ResourceGroupNotFound" || ex.Message.Contains("ResourceGroupNotFound"))
                {
                    // resource group not found, let create throw error don't throw from here
                }
                else
                {
                    // all other exceptions should be thrown
                    throw;
                }
            }

            var defaultStorage = new DataLakeStoreAccount
            {
                Name = DefaultDataLakeStore
            };

            WriteObject(DataLakeAnalyticsClient.CreateOrUpdateAccount(ResourceGroupName, Name, Location, defaultStorage,
                customTags: Tags));
        }
        protected override void ProcessRecord()
        {
            if (ParameterSetName.Equals(BlobParameterSetName, StringComparison.InvariantCultureIgnoreCase))
            {
                var toAdd = new StorageAccount
                {
                    Name = Blob,
                    Properties = new StorageAccountProperties
                    {
                        AccessKey = AccessKey
                    }
                };

                DataLakeAnalyticsClient.SetStorageAccount(ResourceGroupName, Account, toAdd);
            }
            else if (Default)
            {
                var toAdd = new DataLakeStoreAccount
                {
                    Name = DataLakeStore
                };

                DataLakeAnalyticsClient.SetDefaultDataLakeStoreAccount(ResourceGroupName, Account, toAdd);
            }
            else
            {
                WriteWarning(Resources.InvalidDataLakeStoreAccountModificationAttempt);
            }
        }
        public DataLakeAnalyticsAccount CreateOrUpdateAccount(string resourceGroupName, string accountName,
            string location,
            DataLakeStoreAccount defaultDataLakeStoreAccount = null,
            IList<DataLakeStoreAccount> additionalDataLakeStoreAccounts = null,
            IList<StorageAccount> additionalStorageAccounts = null,
            Hashtable[] customTags = null)
        {
            if (string.IsNullOrEmpty(resourceGroupName))
            {
                resourceGroupName = GetResourceGroupByAccountName(accountName);
            }

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

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


            parameters.DataLakeAnalyticsAccount.Properties = new DataLakeAnalyticsAccountProperties();

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

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

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

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

            var accountExists = false;
            try
            {
                if (GetAcount(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.
            }

            var response = accountExists
                ? _accountClient.DataLakeAnalyticsAccount.Update(resourceGroupName, parameters)
                : _accountClient.DataLakeAnalyticsAccount.Create(resourceGroupName, parameters);

            if (response.Status != OperationStatus.Succeeded)
            {
                throw new CloudException(string.Format(Properties.Resources.LongRunningOperationFailed,
                    response.Error.Code, response.Error.Message));
            }

            return
                _accountClient.DataLakeAnalyticsAccount.Get(resourceGroupName, parameters.DataLakeAnalyticsAccount.Name)
                    .DataLakeAnalyticsAccount;
        }
        public void SetDefaultDataLakeStoreAccount(string resourceGroupName, string accountName,
            DataLakeStoreAccount storageToSet)
        {
            if (string.IsNullOrEmpty(resourceGroupName))
            {
                resourceGroupName = GetResourceGroupByAccountName(accountName);
            }

            var account = GetAcount(resourceGroupName, accountName);
            account.Properties.DefaultDataLakeStoreAccount = storageToSet.Name;

            if (
                !account.Properties.DataLakeStoreAccounts.Any(
                    acct => acct.Name.Equals(storageToSet.Name, StringComparison.InvariantCultureIgnoreCase)))
            {
                _accountClient.DataLakeAnalyticsAccount.AddDataLakeStoreAccount(resourceGroupName, accountName,
                    storageToSet.Name, null);
            }

            // null out values that cannot be updated
            account.Properties.DataLakeStoreAccounts = null;
            account.Properties.StorageAccounts = null;

            var updateParams = new DataLakeAnalyticsAccountCreateOrUpdateParameters
            {
                DataLakeAnalyticsAccount = account
            };

            _accountClient.DataLakeAnalyticsAccount.Update(resourceGroupName, updateParams);
        }
        public void AddDataLakeStoreAccount(string resourceGroupName, string accountName,
            DataLakeStoreAccount storageToAdd)
        {
            if (string.IsNullOrEmpty(resourceGroupName))
            {
                resourceGroupName = GetResourceGroupByAccountName(accountName);
            }

            var storageParams = new AddDataLakeStoreParameters
            {
                Properties = storageToAdd.Properties
            };

            _accountClient.DataLakeAnalyticsAccount.AddDataLakeStoreAccount(resourceGroupName, accountName,
                storageToAdd.Name, storageParams);
        }