/// <summary>
 /// Set up access policy permission
 /// </summary>
 /// <param name="policy">SharedAccessFilePolicy object</param>
 /// <param name="permission">Permission</param>
 internal void SetupAccessPolicyPermission(SharedAccessFilePolicy policy, string permission)
 {
     if (string.IsNullOrEmpty(permission))
     {
         return;
     }
     permission         = permission.ToLower(CultureInfo.CurrentCulture);
     policy.Permissions = SharedAccessFilePolicy.PermissionsFromString(permission);
 }
Exemple #2
0
 internal static void SetupAccessPolicyPermission <T>(T policy, string permission)
 {
     //set permission as none if passed-in value is empty
     if (permission == null)
     {
         return;
     }
     if (string.IsNullOrEmpty(permission))
     {
         if (typeof(T) == typeof(SharedAccessTablePolicy))
         {
             ((SharedAccessTablePolicy)(Object)policy).Permissions = SharedAccessTablePermissions.None;
         }
         else if (typeof(T) == typeof(SharedAccessFilePolicy))
         {
             ((SharedAccessFilePolicy)(Object)policy).Permissions = SharedAccessFilePermissions.None;
         }
         else if (typeof(T) == typeof(SharedAccessBlobPolicy))
         {
             ((SharedAccessBlobPolicy)(Object)policy).Permissions = SharedAccessBlobPermissions.None;
         }
         else if ((typeof(T) == typeof(SharedAccessQueuePolicy)))
         {
             ((SharedAccessQueuePolicy)(Object)policy).Permissions = SharedAccessQueuePermissions.None;
         }
         else
         {
             throw new ArgumentException(Resources.InvalidAccessPolicyType);
         }
         return;
     }
     permission = permission.ToLower(CultureInfo.InvariantCulture);
     try
     {
         if (typeof(T) == typeof(SharedAccessTablePolicy))
         {
             //PowerShell will convert q to r in genreate table SAS. Add this to avoid regression
             string convertedPermission = permission.Replace('q', 'r');
             ((SharedAccessTablePolicy)(Object)policy).Permissions = SharedAccessTablePolicy.PermissionsFromString(convertedPermission);
         }
         else if (typeof(T) == typeof(SharedAccessFilePolicy))
         {
             ((SharedAccessFilePolicy)(Object)policy).Permissions = SharedAccessFilePolicy.PermissionsFromString(permission);
         }
         else if (typeof(T) == typeof(SharedAccessBlobPolicy))
         {
             ((SharedAccessBlobPolicy)(Object)policy).Permissions = SharedAccessBlobPolicy.PermissionsFromString(permission);
         }
         else if ((typeof(T) == typeof(SharedAccessQueuePolicy)))
         {
             ((SharedAccessQueuePolicy)(Object)policy).Permissions = SharedAccessQueuePolicy.PermissionsFromString(permission);
         }
         else
         {
             throw new ArgumentException(Resources.InvalidAccessPolicyType);
         }
     }
     catch (System.ArgumentOutOfRangeException)
     {
         throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, Resources.InvalidAccessPermission, permission));
     }
 }