private void ExecSave(ACLOperation operation, KiiHttpClientFactory factory, KiiACLCallback <T, U> callback)
        {
            mParent.SaveParentIfNeeds();
            string requestUrl = Utils.Path(mParent.ParentUrl, "acl", mParent.ActionString, mSubject.Subject);

            KiiHttpClient client = GetHttpClient(factory, requestUrl, operation);

            if (client == null)
            {
                if (callback != null)
                {
                    callback(null, new InvalidOperationException("not grant/revoke request"));
                }
                return;
            }
            KiiCloudEngine.SetAuthBearer(client);

            // send request
            client.SendRequest((ApiResponse response, Exception e) =>
            {
                if (e != null)
                {
                    if (callback != null)
                    {
                        callback(null, e);
                    }
                    return;
                }
                if (callback != null)
                {
                    callback(this, null);
                }
            });
        }
 /// <summary>
 /// Save this ACL entry.
 /// </summary>
 /// <remarks>
 /// Saving this ACL entry throws <see cref="CloudException"/> if <see cref="KiiTopicACL"/> has been created with
 /// <see cref="KiiAnonymousUser"/> and <see cref="TopicAction"/>.
 /// <para>If operation is REVOKE and there is no entry in KiiCloud, KiiCloud will send error response.</para>
 /// </remarks>
 /// <param name='operation'>
 /// ACL operation. See <see cref="ACLOperation"/>
 /// </param>
 public void Save(ACLOperation operation)
 {
     ExecSave(operation, Kii.HttpClientFactory, (KiiACLEntry <T, U> entry, Exception e) =>
     {
         if (e != null)
         {
             throw e;
         }
     });
 }
        private KiiHttpClient GetHttpClient(KiiHttpClientFactory factory, string url, ACLOperation operation)
        {
            switch (operation)
            {
            case ACLOperation.GRANT:
                return(factory.Create(url, Kii.AppId, Kii.AppKey, KiiHttpMethod.PUT));

            case ACLOperation.REVOKE:
                return(factory.Create(url, Kii.AppId, Kii.AppKey, KiiHttpMethod.DELETE));

            default:
                return(null);
            }
        }
 /// <summary>
 /// Save this ACL entry.
 /// </summary>
 /// <remarks>
 /// Subscribe or send message to topic is not supported for <see cref="KiiAnonymousUser"/>.
 /// Saving this ACL entry throws <see cref="CloudException"/> if <see cref="KiiTopicACL"/> has been created with
 /// <see cref="KiiAnonymousUser"/> and <see cref="TopicAction"/>.
 /// <para>If operation is REVOKE and there is no entry in KiiCloud, KiiCloud will send error response.</para>
 /// </remarks>
 /// <param name='operation'>
 /// ACL operation. See <see cref="ACLOperation"/>
 /// </param>
 /// <param name='callback'>
 /// Callback.
 /// </param>
 public void Save(ACLOperation operation, KiiACLCallback <T, U> callback)
 {
     ExecSave(operation, Kii.AsyncHttpClientFactory, callback);
 }
Example #5
0
 public static ACLRuleOperationModel Create(List <ACLRoleModel> roles, ACLRule rule, ACLOperation operation, Type type)
 {
     return(new ACLRuleOperationModel
     {
         DisplayName = operation.Name,
         Key = operation.Key,
         Roles = roles.Select(role => ACLAvailableModel.Create(role, rule, operation.Name, type)).ToList()
     });
 }