Esempio n. 1
0
        private async Task <PNResult <PNMembershipsResult> > GetMembershipsList(string uuid, PNPageObject page, int limit, bool includeCount, string includeOptions, string filter, List <string> sort, Dictionary <string, object> externalQueryParam)
        {
            PNResult <PNMembershipsResult> ret = new PNResult <PNMembershipsResult>();

            if (string.IsNullOrEmpty(uuid))
            {
                uuid = config.Uuid;
            }

            PNPageObject internalPage;

            if (page == null)
            {
                internalPage = new PNPageObject();
            }
            else
            {
                internalPage = page;
            }

            IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null) ? PubnubInstance.InstanceId : "");

            Uri request = urlBuilder.BuildGetAllMembershipsRequest("GET", "", uuid, internalPage.Next, internalPage.Prev, limit, includeCount, includeOptions, filter, sort, externalQueryParam);

            RequestState <PNMembershipsResult> requestState = new RequestState <PNMembershipsResult>();

            requestState.ResponseType      = PNOperationType.PNGetMembershipsOperation;
            requestState.Reconnect         = false;
            requestState.EndPointOperation = this;

            requestState.UsePostMethod = false;
            Tuple <string, PNStatus> JsonAndStatusTuple = await UrlProcessRequest(request, requestState, false).ConfigureAwait(false);

            ret.Status = JsonAndStatusTuple.Item2;
            string json = JsonAndStatusTuple.Item1;

            if (!string.IsNullOrEmpty(json))
            {
                List <object>       resultList      = ProcessJsonResponse(requestState, json);
                ResponseBuilder     responseBuilder = new ResponseBuilder(config, jsonLibrary, pubnubLog);
                PNMembershipsResult responseResult  = responseBuilder.JsonToObject <PNMembershipsResult>(resultList, true);
                if (responseResult != null)
                {
                    ret.Result = responseResult;
                }
            }

            return(ret);
        }
Esempio n. 2
0
        private void GetMembershipsList(string uuid, PNPageObject page, int limit, bool includeCount, string includeOptions, string filter, List <string> sort, Dictionary <string, object> externalQueryParam, PNCallback <PNMembershipsResult> callback)
        {
            if (string.IsNullOrEmpty(uuid))
            {
                uuid = config.Uuid;
            }

            PNPageObject internalPage;

            if (page == null)
            {
                internalPage = new PNPageObject();
            }
            else
            {
                internalPage = page;
            }

            IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null) ? PubnubInstance.InstanceId : "");

            Uri request = urlBuilder.BuildGetAllMembershipsRequest("GET", "", uuid, internalPage.Next, internalPage.Prev, limit, includeCount, includeOptions, filter, sort, externalQueryParam);

            RequestState <PNMembershipsResult> requestState = new RequestState <PNMembershipsResult>();

            requestState.ResponseType      = PNOperationType.PNGetMembershipsOperation;
            requestState.PubnubCallback    = callback;
            requestState.Reconnect         = false;
            requestState.EndPointOperation = this;

            requestState.UsePostMethod = false;
            UrlProcessRequest(request, requestState, false).ContinueWith(r =>
            {
                string json = r.Result.Item1;
                if (!string.IsNullOrEmpty(json))
                {
                    List <object> result = ProcessJsonResponse(requestState, json);
                    ProcessResponseCallbacks(result, requestState);
                }
                else
                {
                    if (r.Result.Item2 != null)
                    {
                        callback.OnResponse(null, r.Result.Item2);
                    }
                }
            }, TaskContinuationOptions.ExecuteSynchronously).Wait();
        }
 public ManageChannelMembersOperation Page(PNPageObject pageObject)
 {
     this.page = pageObject;
     return(this);
 }
        private async Task <PNResult <PNChannelMembersResult> > ProcessMembersOperationRequest(string channel, List <PNChannelMember> setMemberList, List <string> removeMemberList, PNPageObject page, int limit, bool includeCount, string includeOptions, List <string> sort, Dictionary <string, object> externalQueryParam)
        {
            PNResult <PNChannelMembersResult> ret = new PNResult <PNChannelMembersResult>();

            if (string.IsNullOrEmpty(channel) || string.IsNullOrEmpty(channel.Trim()))
            {
                PNStatus errStatus = new PNStatus {
                    Error = true, ErrorData = new PNErrorData("Missing Channel", new ArgumentException("Missing Channel"))
                };
                ret.Status = errStatus;
                return(ret);
            }

            if (string.IsNullOrEmpty(config.SubscribeKey) || string.IsNullOrEmpty(config.SubscribeKey.Trim()) || config.SubscribeKey.Length <= 0)
            {
                PNStatus errStatus = new PNStatus {
                    Error = true, ErrorData = new PNErrorData("Invalid Subscribe key", new ArgumentException("Invalid Subscribe key"))
                };
                ret.Status = errStatus;
                return(ret);
            }

            PNPageObject internalPage;

            if (page == null)
            {
                internalPage = new PNPageObject();
            }
            else
            {
                internalPage = page;
            }

            RequestState <PNChannelMembersResult> requestState = new RequestState <PNChannelMembersResult>();

            requestState.ResponseType      = PNOperationType.PNManageChannelMembersOperation;
            requestState.Reconnect         = false;
            requestState.EndPointOperation = this;

            requestState.UsePatchMethod = true;
            requestState.UsePatchMethod = true;
            Dictionary <string, object> messageEnvelope = new Dictionary <string, object>();

            if (setMemberList != null)
            {
                List <Dictionary <string, object> > setMemberFormatList = new List <Dictionary <string, object> >();
                for (int index = 0; index < setMemberList.Count; index++)
                {
                    Dictionary <string, object> currentMemberFormat = new Dictionary <string, object>();
                    currentMemberFormat.Add("uuid", new Dictionary <string, string> {
                        { "id", setMemberList[index].Uuid }
                    });
                    if (setMemberList[index].Custom != null)
                    {
                        currentMemberFormat.Add("custom", setMemberList[index].Custom);
                    }
                    setMemberFormatList.Add(currentMemberFormat);
                }
                if (setMemberFormatList.Count > 0)
                {
                    messageEnvelope.Add("set", setMemberFormatList);
                }
            }
            if (removeMemberList != null)
            {
                List <Dictionary <string, Dictionary <string, string> > > removeMemberFormatList = new List <Dictionary <string, Dictionary <string, string> > >();
                for (int index = 0; index < removeMemberList.Count; index++)
                {
                    Dictionary <string, Dictionary <string, string> > currentMemberFormat = new Dictionary <string, Dictionary <string, string> >();
                    if (!string.IsNullOrEmpty(removeMemberList[index]))
                    {
                        currentMemberFormat.Add("uuid", new Dictionary <string, string> {
                            { "id", removeMemberList[index] }
                        });
                        removeMemberFormatList.Add(currentMemberFormat);
                    }
                }
                if (removeMemberFormatList.Count > 0)
                {
                    messageEnvelope.Add("delete", removeMemberFormatList);
                }
            }
            string patchMessage = jsonLibrary.SerializeToJsonString(messageEnvelope);

            IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null) ? PubnubInstance.InstanceId : "");
            Uri request = urlBuilder.BuildMemberAddUpdateRemoveChannelRequest("PATCH", patchMessage, channel, internalPage.Next, internalPage.Prev, limit, includeCount, includeOptions, sort, externalQueryParam);

            Tuple <string, PNStatus> JsonAndStatusTuple = await UrlProcessRequest(request, requestState, false, patchMessage).ConfigureAwait(false);

            ret.Status = JsonAndStatusTuple.Item2;
            string json = JsonAndStatusTuple.Item1;

            if (!string.IsNullOrEmpty(json))
            {
                List <object>          resultList      = ProcessJsonResponse(requestState, json);
                ResponseBuilder        responseBuilder = new ResponseBuilder(config, jsonLibrary, pubnubLog);
                PNChannelMembersResult responseResult  = responseBuilder.JsonToObject <PNChannelMembersResult>(resultList, true);
                if (responseResult != null)
                {
                    ret.Result = responseResult;
                }
            }

            return(ret);
        }
        private void ProcessMembersOperationRequest(string spaceId, List <PNChannelMember> setMemberList, List <string> removeMemberList, PNPageObject page, int limit, bool includeCount, string includeOptions, List <string> sort, Dictionary <string, object> externalQueryParam, PNCallback <PNChannelMembersResult> callback)
        {
            PNPageObject internalPage;

            if (page == null)
            {
                internalPage = new PNPageObject();
            }
            else
            {
                internalPage = page;
            }

            RequestState <PNChannelMembersResult> requestState = new RequestState <PNChannelMembersResult>();

            requestState.ResponseType      = PNOperationType.PNManageChannelMembersOperation;
            requestState.PubnubCallback    = callback;
            requestState.Reconnect         = false;
            requestState.EndPointOperation = this;

            requestState.UsePatchMethod = true;
            Dictionary <string, object> messageEnvelope = new Dictionary <string, object>();

            if (setMemberList != null)
            {
                List <Dictionary <string, object> > setMemberFormatList = new List <Dictionary <string, object> >();
                for (int index = 0; index < setMemberList.Count; index++)
                {
                    Dictionary <string, object> currentMemberFormat = new Dictionary <string, object>();
                    currentMemberFormat.Add("uuid", new Dictionary <string, string> {
                        { "id", setMemberList[index].Uuid }
                    });
                    if (setMemberList[index].Custom != null)
                    {
                        currentMemberFormat.Add("custom", setMemberList[index].Custom);
                    }
                    setMemberFormatList.Add(currentMemberFormat);
                }
                if (setMemberFormatList.Count > 0)
                {
                    messageEnvelope.Add("set", setMemberFormatList);
                }
            }
            if (removeMemberList != null)
            {
                List <Dictionary <string, Dictionary <string, string> > > removeMemberFormatList = new List <Dictionary <string, Dictionary <string, string> > >();
                for (int index = 0; index < removeMemberList.Count; index++)
                {
                    Dictionary <string, Dictionary <string, string> > currentMemberFormat = new Dictionary <string, Dictionary <string, string> >();
                    if (!string.IsNullOrEmpty(removeMemberList[index]))
                    {
                        currentMemberFormat.Add("uuid", new Dictionary <string, string> {
                            { "id", removeMemberList[index] }
                        });
                        removeMemberFormatList.Add(currentMemberFormat);
                    }
                }
                if (removeMemberFormatList.Count > 0)
                {
                    messageEnvelope.Add("delete", removeMemberFormatList);
                }
            }
            string patchMessage = jsonLibrary.SerializeToJsonString(messageEnvelope);

            IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null) ? PubnubInstance.InstanceId : "");
            Uri request = urlBuilder.BuildMemberAddUpdateRemoveChannelRequest("PATCH", patchMessage, spaceId, internalPage.Next, internalPage.Prev, limit, includeCount, includeOptions, sort, externalQueryParam);

            UrlProcessRequest(request, requestState, false, patchMessage).ContinueWith(r =>
            {
                string json = r.Result.Item1;
                if (!string.IsNullOrEmpty(json))
                {
                    List <object> result = ProcessJsonResponse(requestState, json);
                    ProcessResponseCallbacks(result, requestState);
                }
                else
                {
                    if (r.Result.Item2 != null)
                    {
                        callback.OnResponse(null, r.Result.Item2);
                    }
                }
            }, TaskContinuationOptions.ExecuteSynchronously).Wait();
        }
Esempio n. 6
0
 public GetAllUuidMetadataOperation Page(PNPageObject pageObject)
 {
     this.page = pageObject;
     return(this);
 }
Esempio n. 7
0
 public RemoveMembershipsOperation Page(PNPageObject pageObject)
 {
     this.page = pageObject;
     return(this);
 }