internal string CreateAzureTableStoredAccessPolicy(IStorageTableManagement localChannel, string tableName, string policyName, DateTime?startTime, DateTime?expiryTime, string permission)
        {
            if (!NameUtil.IsValidStoredAccessPolicyName(policyName))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.InvalidAccessPolicyName, policyName));
            }

            //Get existing permissions
            CloudTable       table            = localChannel.GetTableReference(tableName);
            TablePermissions tablePermissions = localChannel.GetTablePermissions(table, null, TableOperationContext);

            //Add new policy
            if (tablePermissions.SharedAccessPolicies.Keys.Contains(policyName))
            {
                throw new ResourceAlreadyExistException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyAlreadyExists, policyName));
            }

            SharedAccessTablePolicy policy = new SharedAccessTablePolicy();

            AccessPolicyHelper.SetupAccessPolicy <SharedAccessTablePolicy>(policy, startTime, expiryTime, permission);
            tablePermissions.SharedAccessPolicies.Add(policyName, policy);

            //Set permissions back to table
            localChannel.SetTablePermissions(table, tablePermissions, null, TableOperationContext);
            return(policyName);
        }
        internal string SetAzureTableStoredAccessPolicy(IStorageTableManagement localChannel, string tableName, string policyName, DateTime?startTime, DateTime?expiryTime, string permission, bool noStartTime, bool noExpiryTime)
        {
            DateTime?startTimeToSet  = startTime;
            DateTime?expiryTimetoSet = expiryTime;

            //Get existing permissions
            CloudTable       table            = localChannel.GetTableReference(Table);
            TablePermissions tablePermissions = localChannel.GetTablePermissions(table);

            //Set the policy with new value
            if (!tablePermissions.SharedAccessPolicies.Keys.Contains(policyName))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName));
            }

            SharedAccessTablePolicy policy = tablePermissions.SharedAccessPolicies[policyName];

            AccessPolicyHelper.SetupAccessPolicy <SharedAccessTablePolicy>(policy, startTime, expiryTime, permission, noStartTime, noExpiryTime);
            tablePermissions.SharedAccessPolicies[policyName] = policy;

            //Set permission back to table
            localChannel.SetTablePermissions(table, tablePermissions);
            WriteObject(AccessPolicyHelper.ConstructPolicyOutputPSObject <SharedAccessTablePolicy>(tablePermissions.SharedAccessPolicies, policyName));
            return(policyName);
        }
        internal bool RemoveAzureTableStoredAccessPolicy(IStorageTableManagement localChannel, string tableName, string policyName)
        {
            bool   success = false;
            string result  = string.Empty;

            //Get existing permissions
            CloudTable       table            = localChannel.GetTableReference(tableName);
            TablePermissions tablePermissions = localChannel.GetTablePermissions(table);

            //remove the specified policy
            if (!tablePermissions.SharedAccessPolicies.Keys.Contains(policyName))
            {
                throw new ResourceNotFoundException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName));
            }

            if (this.Force || ConfirmRemove(policyName))
            {
                tablePermissions.SharedAccessPolicies.Remove(policyName);
                localChannel.SetTablePermissions(table, tablePermissions);
                success = true;
            }

            return(success);
        }
        internal bool RemoveAzureTableStoredAccessPolicy(IStorageTableManagement localChannel, string tableName, string policyName)
        {
            bool success = false;
            string result = string.Empty;

            //Get existing permissions
            CloudTable table = localChannel.GetTableReference(tableName);
            TablePermissions tablePermissions = localChannel.GetTablePermissions(table);

            //remove the specified policy
            if (!tablePermissions.SharedAccessPolicies.Keys.Contains(policyName))
            {
                throw new ResourceNotFoundException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName));
            }

            if (ShouldProcess(policyName, "Remove policy"))
            {
                tablePermissions.SharedAccessPolicies.Remove(policyName);
                localChannel.SetTablePermissions(table, tablePermissions);
                success = true;
            }

            return success;
        }
        internal string SetAzureTableStoredAccessPolicy(IStorageTableManagement localChannel, string tableName, string policyName, DateTime? startTime, DateTime? expiryTime, string permission, bool noStartTime, bool noExpiryTime)
        {
            DateTime? startTimeToSet = startTime;
            DateTime? expiryTimetoSet = expiryTime;

            //Get existing permissions
            CloudTable table = localChannel.GetTableReference(Table);
            TablePermissions tablePermissions = localChannel.GetTablePermissions(table);

            //Set the policy with new value
            if (!tablePermissions.SharedAccessPolicies.Keys.Contains(policyName))
            {
                throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.PolicyNotFound, policyName));
            }

            SharedAccessTablePolicy policy = tablePermissions.SharedAccessPolicies[policyName];
            AccessPolicyHelper.SetupAccessPolicy<SharedAccessTablePolicy>(policy, startTime, expiryTime, permission, noStartTime, noExpiryTime);
            tablePermissions.SharedAccessPolicies[policyName] = policy;

            //Set permission back to table
            localChannel.SetTablePermissions(table, tablePermissions);
            WriteObject(AccessPolicyHelper.ConstructPolicyOutputPSObject<SharedAccessTablePolicy>(tablePermissions.SharedAccessPolicies, policyName));
            return policyName;
        }
        internal string CreateAzureTableStoredAccessPolicy(IStorageTableManagement localChannel, string tableName, string policyName, DateTime? startTime, DateTime? expiryTime, string permission)
        {

            if (!NameUtil.IsValidStoredAccessPolicyName(policyName))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, Resources.InvalidAccessPolicyName, policyName));
            }

            //Get existing permissions
            CloudTable table = localChannel.GetTableReference(tableName);
            TablePermissions tablePermissions = localChannel.GetTablePermissions(table);

            //Add new policy
            if (tablePermissions.SharedAccessPolicies.Keys.Contains(policyName))
            {
                throw new ResourceAlreadyExistException(String.Format(CultureInfo.CurrentCulture, Resources.PolicyAlreadyExists, policyName));
            }

            SharedAccessTablePolicy policy = new SharedAccessTablePolicy();
            AccessPolicyHelper.SetupAccessPolicy<SharedAccessTablePolicy>(policy, startTime, expiryTime, permission);
            tablePermissions.SharedAccessPolicies.Add(policyName, policy);

            //Set permissions back to table
            localChannel.SetTablePermissions(table, tablePermissions);
            return policyName;
        }