internal async Task <PNResult <PNChannelGroupsListAllResult> > GetAllChannelGroup(Dictionary <string, object> externalQueryParam)
        {
            PNResult <PNChannelGroupsListAllResult> ret = new PNResult <PNChannelGroupsListAllResult>();

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

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

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

            return(ret);
        }
        internal void RemoveChannelForDevice(string[] channels, PNPushType pushType, string pushToken, PNCallback <PNPushRemoveChannelResult> callback)
        {
            if (channels == null || channels.Length == 0 || channels[0] == null || channels[0].Trim().Length == 0)
            {
                throw new ArgumentException("Missing Channel");
            }

            if (pushToken == null)
            {
                throw new ArgumentException("Missing deviceId");
            }

            string channel = string.Join(",", channels.OrderBy(x => x).ToArray());

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

            urlBuilder.PubnubInstanceId = (PubnubInstance != null) ? PubnubInstance.InstanceId : "";
            Uri request = urlBuilder.BuildRemoveChannelPushRequest(channel, pushType, pushToken);

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

            requestState.Channels          = new [] { channel };
            requestState.ResponseType      = PNOperationType.PushRemove;
            requestState.PubnubCallback    = callback;
            requestState.Reconnect         = false;
            requestState.EndPointOperation = this;

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

            if (!string.IsNullOrEmpty(json))
            {
                List <object> result = ProcessJsonResponse <PNPushRemoveChannelResult>(requestState, json);
                ProcessResponseCallbacks(result, requestState);
            }
        }
Exemple #3
0
        private void GetSingleSpace(string spaceId, bool includeCustom, Dictionary <string, object> externalQueryParam, PNCallback <PNGetSpaceResult> callback)
        {
            if (callback == null)
            {
                throw new ArgumentException("Missing callback");
            }
            if (string.IsNullOrEmpty(spaceId))
            {
                throw new ArgumentException("Missing spaceId");
            }

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

            urlBuilder.PubnubInstanceId = (PubnubInstance != null) ? PubnubInstance.InstanceId : "";
            Uri request = urlBuilder.BuildGetSingleSpaceRequest(spaceId, includeCustom, externalQueryParam);

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

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

            string json = "";

            requestState.UsePostMethod = false;
            json = UrlProcessRequest <PNGetSpaceResult>(request, requestState, false);

            if (!string.IsNullOrEmpty(json))
            {
                List <object> result = ProcessJsonResponse <PNGetSpaceResult>(requestState, json);
                ProcessResponseCallbacks(result, requestState);
            }
        }
Exemple #4
0
        internal void DeleteMessage(string channel, long start, long end, PNCallback <PNDeleteMessageResult> callback)
        {
            if (string.IsNullOrEmpty(channel) || string.IsNullOrEmpty(channel.Trim()))
            {
                throw new ArgumentException("Missing Channel");
            }

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

            urlBuilder.PubnubInstanceId = (PubnubInstance != null) ? PubnubInstance.InstanceId : "";
            Uri request = urlBuilder.BuildDeleteMessageRequest(channel, start, end);

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

            requestState.Channels          = new string[] { channel };
            requestState.ResponseType      = PNOperationType.PNDeleteMessageOperation;
            requestState.PubnubCallback    = callback;
            requestState.Reconnect         = false;
            requestState.EndPointOperation = this;

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

            if (!string.IsNullOrEmpty(json))
            {
                //json = json.Replace("\"error\": False", "\"error\": false"); //THIS IS A HACK UNTIL IT IS FIXED AT SERVER
                List <object> result = ProcessJsonResponse <PNDeleteMessageResult>(requestState, json);
                ProcessResponseCallbacks(result, requestState);
            }
        }
        private async Task <PNResult <PNSetUuidMetadataResult> > SetUuidMetadata(string uuid, bool includeCustom, Dictionary <string, object> externalQueryParam)
        {
            if (string.IsNullOrEmpty(uuid))
            {
                uuid = config.Uuid;
            }
            PNResult <PNSetUuidMetadataResult> ret = new PNResult <PNSetUuidMetadataResult>();

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

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

            requestState.UsePatchMethod = true;

            Dictionary <string, object> messageEnvelope = new Dictionary <string, object>();

            messageEnvelope.Add("name", uuidName);
            if (uuidExternalId != null)
            {
                messageEnvelope.Add("externalId", uuidExternalId);
            }
            if (uuidProfileUrl != null)
            {
                messageEnvelope.Add("profileUrl", uuidProfileUrl);
            }
            if (uuidEmail != null)
            {
                messageEnvelope.Add("email", uuidEmail);
            }
            if (uuidCustom != null)
            {
                messageEnvelope.Add("custom", uuidCustom);
            }
            string patchMessage = jsonLibrary.SerializeToJsonString(messageEnvelope);

            byte[] patchData = Encoding.UTF8.GetBytes(patchMessage);

            IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null) ? PubnubInstance.InstanceId : "");
            Uri request = urlBuilder.BuildSetUuidMetadataRequest("PATCH", patchMessage, uuid, includeCustom, externalQueryParam);

            Tuple <string, PNStatus> JsonAndStatusTuple = await UrlProcessRequest(request, requestState, false, patchData).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);
                PNSetUuidMetadataResult responseResult  = responseBuilder.JsonToObject <PNSetUuidMetadataResult>(resultList, true);
                if (responseResult != null)
                {
                    ret.Result = responseResult;
                }
            }

            return(ret);
        }
        private void RemoveUuidMetadata(string uuid, Dictionary <string, object> externalQueryParam, PNCallback <PNRemoveUuidMetadataResult> callback)
        {
            if (string.IsNullOrEmpty(uuid))
            {
                uuid = config.Uuid;
            }

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

            Uri request = urlBuilder.BuildDeleteUuidMetadataRequest("DELETE", "", uuid, externalQueryParam);

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

            requestState.ResponseType      = PNOperationType.PNDeleteUuidMetadataOperation;
            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();
        }
        private void GetSingleChannelMetadata(string spaceId, bool includeCustom, Dictionary <string, object> externalQueryParam, PNCallback <PNGetChannelMetadataResult> callback)
        {
            IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null) ? PubnubInstance.InstanceId : "");

            Uri request = urlBuilder.BuildGetSingleChannelMetadataRequest("GET", "", spaceId, includeCustom, externalQueryParam);

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

            requestState.ResponseType      = PNOperationType.PNGetChannelMetadataOperation;
            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();
        }
        internal void MessageCounts(string[] channels, long[] timetokens, Dictionary <string, object> externalQueryParam, PNCallback <PNMessageCountResult> callback)
        {
            if (channels == null || channels.Length == 0)
            {
                throw new ArgumentException("Missing Channel");
            }

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

            Uri request = urlBuilder.BuildMessageCountsRequest("GET", "", channels, timetokens, externalQueryParam);

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

            requestState.Channels          = channels;
            requestState.ResponseType      = PNOperationType.PNMessageCountsOperation;
            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 <PNMessageCountResult>(requestState, json);
                    ProcessResponseCallbacks(result, requestState);
                }
            }, TaskContinuationOptions.ExecuteSynchronously).Wait();
        }
Exemple #9
0
        internal void History(string channel, long start, long end, int count, bool reverse, bool includeToken, PNCallback <PNHistoryResult> callback)
        {
            if (string.IsNullOrEmpty(channel) || string.IsNullOrEmpty(channel.Trim()))
            {
                throw new ArgumentException("Missing Channel");
            }

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

            urlBuilder.PubnubInstanceId = (PubnubInstance != null) ? PubnubInstance.InstanceId : "";
            Uri request = urlBuilder.BuildHistoryRequest(channel, start, end, count, reverse, includeToken);

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

            requestState.Channels          = new string[] { channel };
            requestState.ResponseType      = PNOperationType.PNHistoryOperation;
            requestState.PubnubCallback    = callback;
            requestState.Reconnect         = false;
            requestState.EndPointOperation = this;

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

            if (!string.IsNullOrEmpty(json))
            {
                List <object> result = ProcessJsonResponse <PNHistoryResult>(requestState, json);
                ProcessResponseCallbacks(result, requestState);
            }
        }
Exemple #10
0
        internal void WhereNow(string uuid, PNCallback <PNWhereNowResult> callback)
        {
            if (jsonLibrary == null)
            {
                throw new NullReferenceException("Missing Json Pluggable Library for Pubnub Instance");
            }

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

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

            urlBuilder.PubnubInstanceId = (PubnubInstance != null) ? PubnubInstance.InstanceId : "";
            Uri request = urlBuilder.BuildWhereNowRequest(uuid);

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

            requestState.Channels          = new string[] { uuid };
            requestState.ResponseType      = PNOperationType.PNWhereNowOperation;
            requestState.PubnubCallback    = callback;
            requestState.Reconnect         = false;
            requestState.EndPointOperation = this;

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

            if (!string.IsNullOrEmpty(json))
            {
                List <object> result = ProcessJsonResponse <PNWhereNowResult>(requestState, json);
                ProcessResponseCallbacks(result, requestState);
            }
        }
        private void GenerateFileUploadUrl(Dictionary <string, object> externalQueryParam, PNCallback <PNGenerateFileUploadUrlResult> callback)
        {
            RequestState <PNGenerateFileUploadUrlResult> requestState = new RequestState <PNGenerateFileUploadUrlResult>();

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

            requestState.UsePostMethod = true;

            Dictionary <string, object> messageEnvelope = new Dictionary <string, object>();

            if (!string.IsNullOrEmpty(sendFileName))
            {
                messageEnvelope.Add("name", sendFileName);
            }
            string postMessage = jsonLibrary.SerializeToJsonString(messageEnvelope);

            byte[] postData = Encoding.UTF8.GetBytes(postMessage);

            IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null) ? PubnubInstance.InstanceId : "");
            Uri request = urlBuilder.BuildGenerateFileUploadUrlRequest("POST", postMessage, this.channelName, externalQueryParam);

            UrlProcessRequest(request, requestState, false, postData).ContinueWith(r =>
            {
                string json = r.Result.Item1;
                if (!string.IsNullOrEmpty(json))
                {
                    List <object> result = ProcessJsonResponse(requestState, json);
                    ProcessResponseCallbacks(result, requestState);
                }
            }, TaskContinuationOptions.ExecuteSynchronously).Wait();
        }
Exemple #12
0
        private void ProcessListFilesRequest(Dictionary <string, object> externalQueryParam, PNCallback <PNListFilesResult> callback)
        {
            IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null) ? PubnubInstance.InstanceId : "");

            Uri request = urlBuilder.BuildListFilesReqest("GET", "", this.channelName, this.limitFileCount, this.nextFileBatchToken, externalQueryParam, PNOperationType.PNListFilesOperation);

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

            requestState.ResponseType      = PNOperationType.PNListFilesOperation;
            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();
        }
        internal void GetChannelsForDevice(PNPushType pushType, string pushToken, PushEnvironment environment, string deviceTopic, Dictionary <string, object> externalQueryParam, PNCallback <PNPushListProvisionsResult> callback)
        {
            if (pushToken == null)
            {
                throw new ArgumentException("Missing Uri");
            }

            if (pushType == PNPushType.APNS2 && string.IsNullOrEmpty(deviceTopic))
            {
                throw new ArgumentException("Missing Topic");
            }

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

            Uri request = urlBuilder.BuildGetChannelsPushRequest("GET", "", pushType, pushToken, environment, deviceTopic, externalQueryParam);

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

            requestState.ResponseType      = PNOperationType.PushGet;
            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();
        }
        internal void DeleteMessage(string channel, long start, long end, Dictionary <string, object> externalQueryParam, PNCallback <PNDeleteMessageResult> callback)
        {
            if (string.IsNullOrEmpty(channel) || string.IsNullOrEmpty(channel.Trim()))
            {
                throw new ArgumentException("Missing Channel");
            }

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

            urlBuilder.PubnubInstanceId = (PubnubInstance != null) ? PubnubInstance.InstanceId : "";
            Uri request = urlBuilder.BuildDeleteMessageRequest(channel, start, end, externalQueryParam);

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

            requestState.Channels          = new [] { channel };
            requestState.ResponseType      = PNOperationType.PNDeleteMessageOperation;
            requestState.PubnubCallback    = callback;
            requestState.Reconnect         = false;
            requestState.EndPointOperation = this;

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

            if (!string.IsNullOrEmpty(json))
            {
                List <object> result = ProcessJsonResponse <PNDeleteMessageResult>(requestState, json);
                ProcessResponseCallbacks(result, requestState);
            }
        }
Exemple #15
0
        internal void History(PNCallback <PNHistoryResult> callback)
        {
            if (string.IsNullOrEmpty(this.channelName) || string.IsNullOrEmpty(this.channelName.Trim()))
            {
                throw new ArgumentException("Missing Channel");
            }

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

            Uri request = urlBuilder.BuildHistoryRequest("GET", "", this.channelName, this.startTimetoken, this.endTimetoken, this.historyCount, this.reverseOption, this.includeTimetokenOption, this.withMetaOption, this.queryParam);

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

            requestState.Channels          = new [] { this.channelName };
            requestState.ResponseType      = PNOperationType.PNHistoryOperation;
            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();
        }
Exemple #16
0
        internal void GetChannelsForChannelGroup(string groupName, Dictionary <string, object> externalQueryParam, PNCallback <PNChannelGroupsAllChannelsResult> callback)
        {
            if (string.IsNullOrEmpty(groupName) || groupName.Trim().Length == 0)
            {
                throw new ArgumentException("Missing groupName");
            }

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

            Uri request = urlBuilder.BuildGetChannelsForChannelGroupRequest("GET", "", null, groupName, false, externalQueryParam);

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

            requestState.ResponseType      = PNOperationType.ChannelGroupGet;
            requestState.ChannelGroups     = new [] { groupName };
            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();
        }
Exemple #17
0
        internal void HereNow(string[] channels, string[] channelGroups, bool showUUIDList, bool includeUserState, Dictionary <string, object> externalQueryParam, PNCallback <PNHereNowResult> callback)
        {
            IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null) ? PubnubInstance.InstanceId : "");

            Uri request = urlBuilder.BuildHereNowRequest("GET", "", channels, channelGroups, showUUIDList, includeUserState, externalQueryParam);

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

            requestState.Channels          = channels;
            requestState.ChannelGroups     = channelGroups;
            requestState.ResponseType      = PNOperationType.PNHereNowOperation;
            requestState.Reconnect         = false;
            requestState.PubnubCallback    = callback;
            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();
        }
Exemple #18
0
        internal void History(string channel, long start, long end, int count, bool reverse, bool includeToken, bool includeMeta, Dictionary <string, object> externalQueryParam, PNCallback <PNHistoryResult> callback)
        {
            if (string.IsNullOrEmpty(channel) || string.IsNullOrEmpty(channel.Trim()))
            {
                throw new ArgumentException("Missing Channel");
            }

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

            Uri request = urlBuilder.BuildHistoryRequest("GET", "", channel, start, end, count, reverse, includeToken, includeMeta, externalQueryParam);

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

            requestState.Channels          = new [] { channel };
            requestState.ResponseType      = PNOperationType.PNHistoryOperation;
            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();
        }
Exemple #19
0
        internal void AuditAccess(string channel, string channelGroup, string[] authKeys, PNCallback <PNAccessManagerAuditResult> callback)
        {
            if (string.IsNullOrEmpty(config.SecretKey) || string.IsNullOrEmpty(config.SecretKey.Trim()) || config.SecretKey.Length <= 0)
            {
                throw new MissingMemberException("Invalid secret key");
            }

            string authKeysCommaDelimited = (authKeys != null && authKeys.Length > 0) ? string.Join(",", authKeys.OrderBy(x => x).ToArray()) : "";

            IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit);
            Uri request = urlBuilder.BuildAuditAccessRequest(channel, channelGroup, authKeysCommaDelimited);

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

            if (!string.IsNullOrEmpty(channel))
            {
                requestState.Channels = new string[] { channel };
            }
            if (!string.IsNullOrEmpty(channelGroup))
            {
                requestState.ChannelGroups = new string[] { channelGroup };
            }
            requestState.ResponseType      = PNOperationType.PNAccessManagerAudit;
            requestState.PubnubCallback    = callback;
            requestState.Reconnect         = false;
            requestState.EndPointOperation = this;

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

            if (!string.IsNullOrEmpty(json))
            {
                List <object> result = ProcessJsonResponse <PNAccessManagerAuditResult>(requestState, json);
                ProcessResponseCallbacks(result, requestState);
            }
        }
        internal void GetChannelsForDevice(PNPushType pushType, string pushToken, Dictionary <string, object> externalQueryParam, PNCallback <PNPushListProvisionsResult> callback)
        {
            if (pushToken == null)
            {
                throw new ArgumentException("Missing Uri");
            }

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

            urlBuilder.PubnubInstanceId = (PubnubInstance != null) ? PubnubInstance.InstanceId : "";
            Uri request = urlBuilder.BuildGetChannelsPushRequest(pushType, pushToken, externalQueryParam);

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

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

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

            if (!string.IsNullOrEmpty(json))
            {
                List <object> result = ProcessJsonResponse <PNPushListProvisionsResult>(requestState, json);
                ProcessResponseCallbacks(result, requestState);
            }
        }
Exemple #21
0
        internal void DeleteChannelGroup(string groupName, Dictionary <string, object> externalQueryParam, PNCallback <PNChannelGroupsDeleteGroupResult> callback)
        {
            if (string.IsNullOrEmpty(groupName) || groupName.Trim().Length == 0)
            {
                throw new ArgumentException("Missing groupName");
            }

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

            urlBuilder.PubnubInstanceId = (PubnubInstance != null) ? PubnubInstance.InstanceId : "";

            Uri request = urlBuilder.BuildRemoveChannelsFromChannelGroupRequest(null, "", groupName, externalQueryParam);

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

            requestState.ResponseType      = PNOperationType.PNRemoveGroupOperation;
            requestState.Channels          = new string[] { };
            requestState.ChannelGroups     = new [] { groupName };
            requestState.PubnubCallback    = callback;
            requestState.Reconnect         = false;
            requestState.EndPointOperation = this;

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

            if (!string.IsNullOrEmpty(json))
            {
                List <object> result = ProcessJsonResponse <PNChannelGroupsDeleteGroupResult>(requestState, json);
                ProcessResponseCallbacks(result, requestState);
            }
        }
Exemple #22
0
        internal void GetChannelsForChannelGroup(string groupName, PNCallback <PNChannelGroupsAllChannelsResult> callback)
        {
            if (string.IsNullOrEmpty(groupName) || groupName.Trim().Length == 0)
            {
                throw new ArgumentException("Missing groupName");
            }

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

            urlBuilder.PubnubInstanceId = (PubnubInstance != null) ? PubnubInstance.InstanceId : "";

            Uri request = urlBuilder.BuildGetChannelsForChannelGroupRequest(null, groupName, false);

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

            requestState.ResponseType      = PNOperationType.ChannelGroupGet;
            requestState.ChannelGroups     = new string[] { groupName };
            requestState.PubnubCallback    = callback;
            requestState.Reconnect         = false;
            requestState.EndPointOperation = this;

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

            if (!string.IsNullOrEmpty(json))
            {
                List <object> result = ProcessJsonResponse <PNChannelGroupsAllChannelsResult>(requestState, json);
                ProcessResponseCallbacks(result, requestState);
            }
        }
Exemple #23
0
        private void Publish(string channel, object message, bool storeInHistory, int ttl, Dictionary <string, object> metaData, Dictionary <string, object> externalQueryParam, PNCallback <PNPublishResult> callback)
        {
            if (string.IsNullOrEmpty(channel) || string.IsNullOrEmpty(channel.Trim()) || message == null)
            {
                PNStatus status = new PNStatus();
                status.Error     = true;
                status.ErrorData = new PNErrorData("Missing Channel or Message", new ArgumentException("Missing Channel or Message"));
                callback.OnResponse(null, status);
                return;
            }

            if (string.IsNullOrEmpty(config.PublishKey) || string.IsNullOrEmpty(config.PublishKey.Trim()) || config.PublishKey.Length <= 0)
            {
                PNStatus status = new PNStatus();
                status.Error     = true;
                status.ErrorData = new PNErrorData("Invalid publish key", new MissingMemberException("Invalid publish key"));
                callback.OnResponse(null, status);
                return;
            }

            if (callback == null)
            {
                return;
            }

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

            urlBuilder.PubnubInstanceId = (PubnubInstance != null) ? PubnubInstance.InstanceId : "";
            Uri request = urlBuilder.BuildPublishRequest(channel, message, storeInHistory, ttl, metaData, httpPost, null, externalQueryParam);

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

            requestState.Channels          = new [] { channel };
            requestState.ResponseType      = PNOperationType.PNPublishOperation;
            requestState.PubnubCallback    = callback;
            requestState.Reconnect         = false;
            requestState.EndPointOperation = this;

            string json = "";

            if (this.httpPost)
            {
                requestState.UsePostMethod = true;
                string postMessage = JsonEncodePublishMsg(message);
                json = UrlProcessRequest <PNPublishResult>(request, requestState, false, postMessage);
            }
            else
            {
                json = UrlProcessRequest <PNPublishResult>(request, requestState, false);
            }

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

            CleanUp();
        }
        private async Task <PNResult <PNDeleteFileResult> > ProcessDeleteFileRequest(Dictionary <string, object> externalQueryParam)
        {
            PNResult <PNDeleteFileResult> ret = new PNResult <PNDeleteFileResult>();

            if (string.IsNullOrEmpty(this.channelName))
            {
                PNStatus errStatus = new PNStatus {
                    Error = true, ErrorData = new PNErrorData("Invalid Channel name", new ArgumentException("Invalid Channel name"))
                };
                ret.Status = errStatus;
                return(ret);
            }
            if (string.IsNullOrEmpty(this.currentFileId))
            {
                PNStatus errStatus = new PNStatus {
                    Error = true, ErrorData = new PNErrorData("Missing File Id", new ArgumentException("Missing File Id"))
                };
                ret.Status = errStatus;
                return(ret);
            }

            if (string.IsNullOrEmpty(this.currentFileName))
            {
                PNStatus errStatus = new PNStatus {
                    Error = true, ErrorData = new PNErrorData("Invalid file name", new ArgumentException("Invalid file name"))
                };
                ret.Status = errStatus;
                return(ret);
            }

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

            Uri request = urlBuilder.BuildGetFileUrlOrDeleteReqest("DELETE", "", this.channelName, this.currentFileId, this.currentFileName, externalQueryParam, PNOperationType.PNFileUrlOperation);

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

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

            return(ret);
        }
Exemple #25
0
        internal void GrantAccess(string[] channels, string[] channelGroups, string[] authKeys, bool read, bool write, bool manage, long ttl, PNCallback <PNAccessManagerGrantResult> callback)
        {
            if (string.IsNullOrEmpty(config.SecretKey) || string.IsNullOrEmpty(config.SecretKey.Trim()) || config.SecretKey.Length <= 0)
            {
                throw new MissingMemberException("Invalid secret key");
            }

            if ((channels == null && channelGroups == null) ||
                (channels != null && channelGroups != null && channels.Length == 0 && channelGroups.Length == 0))
            {
                throw new MissingMemberException("Invalid Channels/ChannelGroups");
            }

            List <string> channelList      = new List <string>();
            List <string> channelGroupList = new List <string>();
            List <string> authList         = new List <string>();

            if (channels != null && channels.Length > 0)
            {
                channelList = new List <string>(channels);
                channelList = channelList.Where(ch => !string.IsNullOrEmpty(ch) && ch.Trim().Length > 0).Distinct <string>().ToList();
            }

            if (channelGroups != null && channelGroups.Length > 0)
            {
                channelGroupList = new List <string>(channelGroups);
                channelGroupList = channelGroupList.Where(cg => !string.IsNullOrEmpty(cg) && cg.Trim().Length > 0).Distinct <string>().ToList();
            }

            if (authKeys != null && authKeys.Length > 0)
            {
                authList = new List <string>(authKeys);
                authList = authList.Where(auth => !string.IsNullOrEmpty(auth) && auth.Trim().Length > 0).Distinct <string>().ToList();
            }

            string channelsCommaDelimited      = string.Join(",", channelList.ToArray().OrderBy(x => x).ToArray());
            string channelGroupsCommaDelimited = string.Join(",", channelGroupList.ToArray().OrderBy(x => x).ToArray());
            string authKeysCommaDelimited      = string.Join(",", authList.ToArray().OrderBy(x => x).ToArray());

            IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit);
            Uri request = urlBuilder.BuildGrantAccessRequest(channelsCommaDelimited, channelGroupsCommaDelimited, authKeysCommaDelimited, read, write, manage, ttl);

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

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

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

            if (!string.IsNullOrEmpty(json))
            {
                List <object> result = ProcessJsonResponse <PNAccessManagerGrantResult>(requestState, json);
                ProcessResponseCallbacks(result, requestState);
            }
        }
Exemple #26
0
        private void SharedSetUserState(string[] channels, string[] channelGroups, string uuid, string jsonChannelUserState, string jsonChannelGroupUserState, Dictionary <string, object> externalQueryParam, PNCallback <PNSetStateResult> callback)
        {
            List <string> channelList;
            List <string> channelGroupList;
            string        currentUuid = uuid;

            string[] channelArray = null;
            if (channels != null && channels.Length > 0)
            {
                channelList  = new List <string>(channels);
                channelList  = channelList.Where(ch => !string.IsNullOrEmpty(ch) && ch.Trim().Length > 0).Distinct <string>().ToList();
                channelArray = channelList.ToArray();
            }

            string[] channelGroupsArray = null;
            if (channelGroups != null && channelGroups.Length > 0)
            {
                channelGroupList   = new List <string>(channelGroups);
                channelGroupList   = channelGroupList.Where(cg => !string.IsNullOrEmpty(cg) && cg.Trim().Length > 0).Distinct <string>().ToList();
                channelGroupsArray = channelGroupList.ToArray();
            }

            string commaDelimitedChannels      = (channelArray != null && channelArray.Length > 0) ? string.Join(",", channelArray.OrderBy(x => x).ToArray()) : "";
            string commaDelimitedChannelGroups = (channelGroupsArray != null && channelGroupsArray.Length > 0) ? string.Join(",", channelGroupsArray.OrderBy(x => x).ToArray()) : "";

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

            string jsonUserState = GetJsonSharedSetUserStateInternal(channels, channelGroups, jsonChannelUserState, jsonChannelGroupUserState);

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

            Uri request = urlBuilder.BuildSetUserStateRequest("GET", "", commaDelimitedChannels, commaDelimitedChannelGroups, currentUuid, jsonUserState, externalQueryParam);

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

            requestState.Channels          = channelArray;
            requestState.ChannelGroups     = channelGroupsArray;
            requestState.ResponseType      = PNOperationType.PNSetStateOperation;
            requestState.PubnubCallback    = callback;
            requestState.Reconnect         = false;
            requestState.EndPointOperation = this;

            //Set TerminateSubRequest to true to bounce the long-polling subscribe requests to update user state
            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();
        }
        private async Task <PNResult <PNAddMessageActionResult> > Publish(string channel, long messageTimetoken, PNMessageAction messageAction, Dictionary <string, object> externalQueryParam)
        {
            PNResult <PNAddMessageActionResult> ret = new PNResult <PNAddMessageActionResult>();

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

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

            string requestMethodName = "POST";
            string postMessage       = jsonLibrary.SerializeToJsonString(messageAction);

            byte[]             postData   = Encoding.UTF8.GetBytes(postMessage);
            IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null) ? PubnubInstance.InstanceId : "");

            Uri request = urlBuilder.BuildAddMessageActionRequest(requestMethodName, postMessage, channel, messageTimetoken, externalQueryParam);

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

            requestState.Channels          = new[] { channel };
            requestState.ResponseType      = PNOperationType.PNAddMessageActionOperation;
            requestState.Reconnect         = false;
            requestState.EndPointOperation = this;
            requestState.UsePostMethod     = true;

            Tuple <string, PNStatus> JsonAndStatusTuple = await UrlProcessRequest(request, requestState, false, postData).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);
                PNAddMessageActionResult responseResult  = responseBuilder.JsonToObject <PNAddMessageActionResult>(resultList, true);
                if (responseResult != null)
                {
                    ret.Result = responseResult;
                }
            }

            return(ret);
        }
        private void SetUuidMetadata(string uuid, bool includeCustom, Dictionary <string, object> externalQueryParam, PNCallback <PNSetUuidMetadataResult> callback)
        {
            if (string.IsNullOrEmpty(uuid))
            {
                uuid = config.Uuid;
            }

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

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

            requestState.UsePatchMethod = true;

            Dictionary <string, object> messageEnvelope = new Dictionary <string, object>();

            if (uuidName != null)
            {
                messageEnvelope.Add("name", uuidName);
            }
            if (uuidExternalId != null)
            {
                messageEnvelope.Add("externalId", uuidExternalId);
            }
            if (uuidProfileUrl != null)
            {
                messageEnvelope.Add("profileUrl", uuidProfileUrl);
            }
            if (uuidEmail != null)
            {
                messageEnvelope.Add("email", uuidEmail);
            }
            if (uuidCustom != null)
            {
                messageEnvelope.Add("custom", uuidCustom);
            }
            string patchMessage = jsonLibrary.SerializeToJsonString(messageEnvelope);

            byte[] patchData = Encoding.UTF8.GetBytes(patchMessage);

            IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null) ? PubnubInstance.InstanceId : "");
            Uri request = urlBuilder.BuildSetUuidMetadataRequest("PATCH", patchMessage, uuid, includeCustom, externalQueryParam);

            UrlProcessRequest(request, requestState, false, patchData).ContinueWith(r =>
            {
                string json = r.Result.Item1;
                if (!string.IsNullOrEmpty(json))
                {
                    List <object> result = ProcessJsonResponse(requestState, json);
                    ProcessResponseCallbacks(result, requestState);
                }
            }, TaskContinuationOptions.ExecuteSynchronously).Wait();
        }
Exemple #29
0
        private void Fire(string channel, object message, bool storeInHistory, int ttl, Dictionary <string, object> metaData, Dictionary <string, object> externalQueryParam, PNCallback <PNPublishResult> callback)
        {
            if (string.IsNullOrEmpty(channel) || string.IsNullOrEmpty(channel.Trim()) || message == null)
            {
                throw new ArgumentException("Missing Channel or Message");
            }

            if (string.IsNullOrEmpty(config.PublishKey) || string.IsNullOrEmpty(config.PublishKey.Trim()) || config.PublishKey.Length <= 0)
            {
                throw new MissingMemberException("Invalid publish key");
            }

            if (callback == null)
            {
                throw new ArgumentException("Missing userCallback");
            }

            Dictionary <string, string> urlParam = new Dictionary <string, string>();

            urlParam.Add("norep", "true");

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

            urlBuilder.PubnubInstanceId = (PubnubInstance != null) ? PubnubInstance.InstanceId : "";
            Uri request = urlBuilder.BuildPublishRequest(channel, message, storeInHistory, ttl, metaData, httpPost, urlParam, externalQueryParam);

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

            requestState.Channels          = new [] { channel };
            requestState.ResponseType      = PNOperationType.PNFireOperation;
            requestState.PubnubCallback    = callback;
            requestState.Reconnect         = false;
            requestState.EndPointOperation = this;

            string json = "";

            if (this.httpPost)
            {
                requestState.UsePostMethod = true;
                Dictionary <string, object> messageEnvelope = new Dictionary <string, object>();
                messageEnvelope.Add("message", message);
                string postMessage = jsonLibrary.SerializeToJsonString(messageEnvelope);
                json = UrlProcessRequest <PNPublishResult>(request, requestState, false, postMessage);
            }
            else
            {
                json = UrlProcessRequest <PNPublishResult>(request, requestState, false);
            }

            if (!string.IsNullOrEmpty(json))
            {
                List <object> result = ProcessJsonResponse <PNPublishResult>(requestState, json);
                ProcessResponseCallbacks(result, requestState);
            }
        }
Exemple #30
0
        internal void GrantAccess(string[] channels, string[] channelGroups, string[] authKeys, bool read, bool write, bool delete, bool manage, long ttl, Dictionary <string, object> externalQueryParam, PNCallback <PNAccessManagerGrantResult> callback)
        {
            if (string.IsNullOrEmpty(config.SecretKey) || string.IsNullOrEmpty(config.SecretKey.Trim()) || config.SecretKey.Length <= 0)
            {
                throw new MissingMemberException("Invalid secret key");
            }

            List <string> channelList      = new List <string>();
            List <string> channelGroupList = new List <string>();
            List <string> authList         = new List <string>();

            if (channels != null && channels.Length > 0)
            {
                channelList = new List <string>(channels);
                channelList = channelList.Where(ch => !string.IsNullOrEmpty(ch) && ch.Trim().Length > 0).Distinct <string>().ToList();
            }

            if (channelGroups != null && channelGroups.Length > 0)
            {
                channelGroupList = new List <string>(channelGroups);
                channelGroupList = channelGroupList.Where(cg => !string.IsNullOrEmpty(cg) && cg.Trim().Length > 0).Distinct <string>().ToList();
            }

            if (authKeys != null && authKeys.Length > 0)
            {
                authList = new List <string>(authKeys);
                authList = authList.Where(auth => !string.IsNullOrEmpty(auth) && auth.Trim().Length > 0).Distinct <string>().ToList();
            }

            string channelsCommaDelimited      = string.Join(",", channelList.ToArray().OrderBy(x => x).ToArray());
            string channelGroupsCommaDelimited = string.Join(",", channelGroupList.ToArray().OrderBy(x => x).ToArray());
            string authKeysCommaDelimited      = string.Join(",", authList.ToArray().OrderBy(x => x).ToArray());

            IUrlRequestBuilder urlBuilder = new UrlRequestBuilder(config, jsonLibrary, unit, pubnubLog, pubnubTelemetryMgr, (PubnubInstance != null) ? PubnubInstance.InstanceId : "");
            Uri request = urlBuilder.BuildGrantV2AccessRequest("GET", "", channelsCommaDelimited, channelGroupsCommaDelimited, authKeysCommaDelimited, read, write, delete, manage, ttl, externalQueryParam);

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

            requestState.Channels          = channels;
            requestState.ChannelGroups     = channelGroups;
            requestState.ResponseType      = PNOperationType.PNAccessManagerGrant;
            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();
        }