internal async Task <PNResult <PNChannelGroupsAddChannelResult> > AddChannelsToChannelGroup(string[] channels, string nameSpace, string groupName, Dictionary <string, object> externalQueryParam)
        {
            if (channels == null || channels.Length == 0)
            {
                throw new ArgumentException("Missing channel(s)");
            }

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

            if (string.IsNullOrEmpty(groupName) || groupName.Trim().Length == 0)
            {
                throw new ArgumentException("Missing groupName");
            }
            PNResult <PNChannelGroupsAddChannelResult> ret = new PNResult <PNChannelGroupsAddChannelResult>();

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

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

            Uri request = urlBuilder.BuildAddChannelsToChannelGroupRequest("GET", "", channelsCommaDelimited, nameSpace, groupName, externalQueryParam);

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

            requestState.ResponseType      = PNOperationType.PNAddChannelsToGroupOperation;
            requestState.Channels          = new string[] { };
            requestState.ChannelGroups     = new[] { groupName };
            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);
                PNChannelGroupsAddChannelResult responseResult = responseBuilder.JsonToObject <PNChannelGroupsAddChannelResult>(resultList, true);
                if (responseResult != null)
                {
                    ret.Result = responseResult;
                }
            }

            return(ret);
        }
示例#2
0
        internal void AddChannelsToChannelGroup(string[] channels, string nameSpace, string groupName, Dictionary <string, object> externalQueryParam, PNCallback <PNChannelGroupsAddChannelResult> callback)
        {
            if (channels == null || channels.Length == 0)
            {
                throw new ArgumentException("Missing channel(s)");
            }

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

            if (string.IsNullOrEmpty(groupName) || groupName.Trim().Length == 0)
            {
                throw new ArgumentException("Missing groupName");
            }

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

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

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

            Uri request = urlBuilder.BuildAddChannelsToChannelGroupRequest(channelsCommaDelimited, nameSpace, groupName, externalQueryParam);

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

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

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

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