Example #1
0
        internal async Task <PNResult <PNGetStateResult> > GetUserState(string[] channels, string[] channelGroups, string uuid, Dictionary <string, object> externalQueryParam)
        {
            if ((channels == null && channelGroups == null) ||
                (channels != null && channelGroups != null && channels.Length == 0 && channelGroups.Length == 0))
            {
                throw new ArgumentException("Either Channel Or Channel Group or Both should be provided");
            }
            PNResult <PNGetStateResult> ret = new PNResult <PNGetStateResult>();

            string internalUuid;

            if (string.IsNullOrEmpty(uuid) || uuid.Trim().Length == 0)
            {
                internalUuid = config.Uuid;
            }
            else
            {
                internalUuid = uuid;
            }

            string channelsCommaDelimited      = (channels != null && channels.Length > 0) ? string.Join(",", channels.OrderBy(x => x).ToArray()) : "";
            string channelGroupsCommaDelimited = (channelGroups != null && channelGroups.Length > 0) ? string.Join(",", channelGroups.OrderBy(x => x).ToArray()) : "";

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

            Uri request = urlBuilder.BuildGetUserStateRequest("GET", "", channelsCommaDelimited, channelGroupsCommaDelimited, internalUuid, externalQueryParam);

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

            requestState.Channels          = channels;
            requestState.ChannelGroups     = channelGroups;
            requestState.ResponseType      = PNOperationType.PNGetStateOperation;
            requestState.Reconnect         = false;
            requestState.EndPointOperation = this;

            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);
                PNGetStateResult responseResult  = responseBuilder.JsonToObject <PNGetStateResult>(resultList, true);
                if (responseResult != null)
                {
                    ret.Result = responseResult;
                }
            }

            return(ret);
        }
Example #2
0
        internal void GetUserState(string[] channels, string[] channelGroups, string uuid, Dictionary <string, object> externalQueryParam, PNCallback <PNGetStateResult> callback)
        {
            if ((channels == null && channelGroups == null) ||
                (channels != null && channelGroups != null && channels.Length == 0 && channelGroups.Length == 0))
            {
                throw new ArgumentException("Either Channel Or Channel Group or Both should be provided");
            }
            string internalUuid;

            if (string.IsNullOrEmpty(uuid) || uuid.Trim().Length == 0)
            {
                internalUuid = config.Uuid;
            }
            else
            {
                internalUuid = uuid;
            }

            string channelsCommaDelimited      = (channels != null && channels.Length > 0) ? string.Join(",", channels.OrderBy(x => x).ToArray()) : "";
            string channelGroupsCommaDelimited = (channelGroups != null && channelGroups.Length > 0) ? string.Join(",", channelGroups.OrderBy(x => x).ToArray()) : "";

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

            Uri request = urlBuilder.BuildGetUserStateRequest("GET", "", channelsCommaDelimited, channelGroupsCommaDelimited, internalUuid, externalQueryParam);

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

            requestState.Channels          = channels;
            requestState.ChannelGroups     = channelGroups;
            requestState.ResponseType      = PNOperationType.PNGetStateOperation;
            requestState.PubnubCallback    = callback;
            requestState.Reconnect         = false;
            requestState.EndPointOperation = this;

            UrlProcessRequest(request, requestState, false).ContinueWith(r =>
            {
                string json = r.Result.Item1;
                if (!string.IsNullOrEmpty(json))
                {
                    List <object> result = ProcessJsonResponse(requestState, json);
                    ProcessResponseCallbacks(result, requestState);
                }
            }, TaskContinuationOptions.ExecuteSynchronously).Wait();
        }
Example #3
0
        internal void GetUserState(string[] channels, string[] channelGroups, string uuid, PNCallback <PNGetStateResult> callback)
        {
            if ((channels == null && channelGroups == null) ||
                (channels != null && channelGroups != null && channels.Length == 0 && channelGroups.Length == 0))
            {
                throw new ArgumentException("Either Channel Or Channel Group or Both should be provided");
            }
            if ((channels == null && channelGroups != null) || (channels.Length == 0 && channelGroups.Length == 0))
            {
                throw new ArgumentException("Either Channel Or Channel Group or Both should be provided.");
            }

            if (string.IsNullOrEmpty(uuid) || uuid.Trim().Length == 0)
            {
                uuid = config.Uuid;
            }

            string channelsCommaDelimited      = (channels != null && channels.Length > 0) ? string.Join(",", channels.OrderBy(x => x).ToArray()) : "";
            string channelGroupsCommaDelimited = (channelGroups != null && channelGroups.Length > 0) ? string.Join(",", channelGroups.OrderBy(x => x).ToArray()) : "";

            IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog);

            urlBuilder.PubnubInstanceId = (PubnubInstance != null) ? PubnubInstance.InstanceId : "";
            Uri request = urlBuilder.BuildGetUserStateRequest(channelsCommaDelimited, channelGroupsCommaDelimited, uuid);

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

            requestState.Channels          = channels;
            requestState.ChannelGroups     = channelGroups;
            requestState.ResponseType      = PNOperationType.PNGetStateOperation;
            requestState.PubnubCallback    = callback;
            requestState.Reconnect         = false;
            requestState.EndPointOperation = this;

            string json = UrlProcessRequest <PNGetStateResult>(request, requestState, false);

            if (!string.IsNullOrEmpty(json))
            {
                List <object> result = ProcessJsonResponse <PNGetStateResult>(requestState, json);
                ProcessResponseCallbacks(result, requestState);
            }
        }