Esempio n. 1
0
        private Dictionary <string, object> BuildFcmPayload(PNPushType pushType)
        {
            Dictionary <string, object> retFcmPayload = new Dictionary <string, object>();

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

            if (pushTitle != null)
            {
                fcmData.Add("summary", pushTitle);
            }


            Dictionary <string, object> customData = BuildCustomData(pushType);
            Dictionary <string, object> fcmPayload;

            if (customData != null)
            {
                fcmPayload = new Dictionary <string, object>(fcmData.Concat(customData).GroupBy(item => item.Key).ToDictionary(item => item.Key, item => item.First().Value));
            }
            else
            {
                fcmPayload = fcmData;
            }

            retFcmPayload.Add("data", fcmPayload);

            return(retFcmPayload);
        }
Esempio n. 2
0
        public void Async(Action <PNPushListProvisionsResult, PNStatus> callback)
        {
            this.Callback = callback;
            if (string.IsNullOrEmpty(DeviceIDForPush))
            {
                PNStatus pnStatus = base.CreateErrorResponseFromMessage("DeviceId is empty", null, PNStatusCategory.PNBadRequestCategory);
                Callback(null, pnStatus);

                return;
            }

            if (PushType.Equals(PNPushType.None))
            {
                #if (ENABLE_PUBNUB_LOGGING)
                this.PubNubInstance.PNLog.WriteToLog("PNPushType not selected, using GCM", PNLoggingMethod.LevelInfo);
                #endif
                PushType = PNPushType.GCM;
            }

            if (PushType.Equals(PNPushType.APNS2) && (string.IsNullOrEmpty(TopicForPush)))
            {
                PNStatus pnStatus = base.CreateErrorResponseFromMessage(CommonText.APNS2TopicEmpty, null, PNStatusCategory.PNBadRequestCategory);
                Callback(null, pnStatus);

                return;
            }

            base.Async(this);
        }
Esempio n. 3
0
        private Dictionary <string, object> BuildMpnsPayload(PNPushType pushType)
        {
            Dictionary <string, object> retMpnsPayload;

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

            if (pushTitle != null)
            {
                mpnsData.Add("title", pushTitle);
            }

            if (pushBadge > 0)
            {
                mpnsData.Add("count", pushBadge);
            }

            Dictionary <string, object> customData = BuildCustomData(pushType);

            if (customData != null)
            {
                retMpnsPayload = new Dictionary <string, object>(mpnsData.Concat(customData).GroupBy(item => item.Key).ToDictionary(item => item.Key, item => item.First().Value));
            }
            else
            {
                retMpnsPayload = mpnsData;
            }

            return(retMpnsPayload);
        }
Esempio n. 4
0
 void RemoveAllPushNotificationsFromChannels(PubNub pubnub, string deviceId, PNPushType pnPushType)
 {
     pubnub.RemoveAllPushNotifications().DeviceID(deviceId).PushType(pnPushType).Async((result, status) => {
         Debug.Log("in RemoveAllPushNotificationsFromChannels");
         if (status.Error)
         {
             Debug.Log(string.Format("In Example, RemoveAllPushNotificationsFromChannels Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category));
         }
         else
         {
             Debug.Log(string.Format("DateTime {0}, In RemoveAllPushNotificationsFromChannels, result: {1}", DateTime.UtcNow, result.Message));
             Display(string.Format("RemoveAllPushNotificationsFromChannels: {0}", result.Message));
         }
     });
     pubnub.RemoveAllPushNotifications().DeviceID(deviceId).PushType(PNPushType.APNS2).Topic("a").Async((result, status) => {
         Debug.Log("in RemoveAllPushNotificationsFromChannels");
         if (status.Error)
         {
             Debug.Log(string.Format("In Example, RemoveAllPushNotificationsFromChannels Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category));
         }
         else
         {
             Debug.Log(string.Format("DateTime {0}, In RemoveAllPushNotificationsFromChannels, result: {1}", DateTime.UtcNow, result.Message));
             Display(string.Format("RemoveAllPushNotificationsFromChannels: {0}", result.Message));
         }
     });
 }
Esempio n. 5
0
 void AuditPushChannelProvisions(PubNub pubnub, string deviceId, PNPushType pnPushType)
 {
     pubnub.AuditPushChannelProvisions().DeviceID(deviceId).PushType(pnPushType).Async((result, status) => {
         Debug.Log("in AuditPushChannelProvisions");
         if (status.Error)
         {
             Debug.Log(string.Format("In Example, AuditPushChannelProvisions Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category));
         }
         else
         {
             Debug.Log(string.Format("DateTime {0}, In AuditPushChannelProvisions, result: {1}", DateTime.UtcNow, (result.Channels != null)?string.Join(",", result.Channels.ToArray()):""));
             Display(string.Format("AuditPushChannelProvisions: {0}", (result.Channels != null)?string.Join(",", result.Channels.ToArray()):""));
         }
     });
     pubnub.AuditPushChannelProvisions().DeviceID(deviceId).PushType(pnPushType).PushType(PNPushType.APNS2).Topic("a").Async((result, status) => {
         Debug.Log("in AuditPushChannelProvisions");
         if (status.Error)
         {
             Debug.Log(string.Format("In Example, AuditPushChannelProvisions Error: {0} {1} {2}", status.StatusCode, status.ErrorData, status.Category));
         }
         else
         {
             Debug.Log(string.Format("DateTime {0}, In AuditPushChannelProvisions, result: {1}", DateTime.UtcNow, (result.Channels != null)?string.Join(",", result.Channels.ToArray()):""));
             Display(string.Format("AuditPushChannelProvisions: {0}", (result.Channels != null)?string.Join(",", result.Channels.ToArray()):""));
         }
     });
 }
        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);
            }
        }
        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 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);
            }
        }
Esempio n. 9
0
        public void Async(Action <PNPushAddChannelResult, PNStatus> callback)
        {
            this.Callback = callback;
            if ((ChannelsToUse == null) || ((ChannelsToUse != null) && (ChannelsToUse.Count <= 0)))
            {
                PNStatus pnStatus = base.CreateErrorResponseFromMessage("ChannelsToAdd null or empty", null, PNStatusCategory.PNBadRequestCategory);
                Callback(null, pnStatus);

                return;
            }

            if (string.IsNullOrEmpty(DeviceIDForPush))
            {
                PNStatus pnStatus = base.CreateErrorResponseFromMessage("DeviceId is empty", null, PNStatusCategory.PNBadRequestCategory);
                Callback(null, pnStatus);

                return;
            }

            if (PushType.Equals(PNPushType.None))
            {
                #if (ENABLE_PUBNUB_LOGGING)
                this.PubNubInstance.PNLog.WriteToLog("PNPushType not selected, using GCM", PNLoggingMethod.LevelInfo);
                #endif
                PushType = PNPushType.GCM;
            }
            base.Async(this);
        }
Esempio n. 10
0
        private Dictionary <string, object> BuildApnsPayload(PNPushType pushType)
        {
            Dictionary <string, object> retApsPayload;
            Dictionary <string, object> apnsPayload = new Dictionary <string, object>();

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

            if (pushTitle != null && pushBody != null)
            {
                Dictionary <string, object> alertDic = new Dictionary <string, object>();
                alertDic.Add("title", pushTitle);
                alertDic.Add("body", pushBody);

                apsData.Add("alert", alertDic);
            }
            else if (pushTitle != null)
            {
                apsData.Add("alert", pushTitle);
            }

            if (pushBadge > 0)
            {
                apsData.Add("badge", pushBadge);
            }

            if (pushSound != null)
            {
                apsData.Add("sound", pushSound);
            }


            apnsPayload.Add("aps", apsData);

            Dictionary <string, object> customData = BuildCustomData(pushType);

            if (customData != null)
            {
                retApsPayload = new Dictionary <string, object>(apnsPayload.Concat(customData).GroupBy(item => item.Key).ToDictionary(item => item.Key, item => item.First().Value));
            }
            else
            {
                retApsPayload = apnsPayload;
            }

            return(retApsPayload);
        }
Esempio n. 11
0
        private Dictionary <string, object> BuildCustomData(PNPushType pushType)
        {
            Dictionary <string, object> ret = null;

            if (pushCustomData != null && pushCustomData.Count > 0 && pushCustomData.ContainsKey(pushType))
            {
                ret = new Dictionary <string, object>();

                Dictionary <string, object> pushSpecificCustomData = pushCustomData[pushType];
                foreach (KeyValuePair <string, object> kvp in pushSpecificCustomData)
                {
                    ret.Add(kvp.Key, kvp.Value);
                }
            }

            return(ret);
        }
Esempio n. 12
0
        public static Uri BuildGetChannelsPushRequest(PNPushType pushType, string pushToken, PubNubUnity pnInstance, Dictionary <string, string> queryParams)
        {
            StringBuilder parameterBuilder = new StringBuilder();

            parameterBuilder.AppendFormat("?type={0}", pushType.ToString().ToLowerInvariant());

            // Build URL
            List <string> url = new List <string>();

            url.Add("v1");
            url.Add("push");
            url.Add("sub-key");
            url.Add(pnInstance.PNConfig.SubscribeKey);
            url.Add("devices");
            url.Add(pushToken);

            return(BuildRestApiRequest <Uri>(url, PNOperationType.PNPushNotificationEnabledChannelsOperation, parameterBuilder.ToString(), pnInstance, queryParams));
        }
Esempio n. 13
0
        public static Uri BuildRemoveChannelPushRequest(string channel, PNPushType pushType, string pushToken, PubNubUnity pnInstance, Dictionary <string, string> queryParams)
        {
            StringBuilder parameterBuilder = new StringBuilder();

            parameterBuilder.AppendFormat("?remove={0}", Utility.EncodeUricomponent(channel, PNOperationType.PNRemoveChannelsFromGroupOperation, true, false));
            parameterBuilder.AppendFormat("&type={0}", pushType.ToString().ToLowerInvariant());

            // Build URL
            List <string> url = new List <string>();

            url.Add("v1");
            url.Add("push");
            url.Add("sub-key");
            url.Add(pnInstance.PNConfig.SubscribeKey);
            url.Add("devices");
            url.Add(pushToken);

            return(BuildRestApiRequest <Uri>(url, PNOperationType.PNRemoveChannelsFromGroupOperation, parameterBuilder.ToString(), pnInstance, queryParams));
        }
Esempio n. 14
0
        public static Uri BuildRegisterDevicePushRequest(string channel, PNPushType pushType, string pushToken, PubNubUnity pnInstance)
        {
            StringBuilder parameterBuilder = new StringBuilder();

            parameterBuilder.AppendFormat("?add={0}", Utility.EncodeUricomponent(channel, PNOperationType.PNAddPushNotificationsOnChannelsOperation, true, false));
            parameterBuilder.AppendFormat("&type={0}", pushType.ToString().ToLowerInvariant());

            // Build URL
            List <string> url = new List <string>();

            url.Add("v1");
            url.Add("push");
            url.Add("sub-key");
            url.Add(pnInstance.PNConfig.SubscribeKey);
            url.Add("devices");
            url.Add(pushToken);

            return(BuildRestApiRequest <Uri>(url, PNOperationType.PNAddPushNotificationsOnChannelsOperation, parameterBuilder.ToString(), pnInstance));
        }
Esempio n. 15
0
        public static Uri BuildUnregisterDevicePushRequest(PNPushType pushType, string pushToken, PubNubUnity pnInstance)
        {
            StringBuilder parameterBuilder = new StringBuilder();

            parameterBuilder.AppendFormat("?type={0}", pushType.ToString().ToLowerInvariant());

            // Build URL
            List <string> url = new List <string>();

            url.Add("v1");
            url.Add("push");
            url.Add("sub-key");
            url.Add(pnInstance.PNConfig.SubscribeKey);
            url.Add("devices");
            url.Add(pushToken);
            url.Add("remove");

            return(BuildRestApiRequest <Uri>(url, PNOperationType.PNRemoveAllPushNotificationsOperation, parameterBuilder.ToString(), pnInstance));
        }
Esempio n. 16
0
        internal void RegisterDevice(string[] channels, PNPushType pushType, string pushToken, PushEnvironment environment, string deviceTopic, Dictionary <string, object> externalQueryParam, PNCallback <PNPushAddChannelResult> 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");
            }

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

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

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

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

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

            requestState.Channels          = new [] { channel };
            requestState.ResponseType      = PNOperationType.PushRegister;
            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();
        }
Esempio n. 17
0
        Uri IUrlRequestBuilder.BuildGetChannelsPushRequest(PNPushType pushType, string pushToken)
        {
            PNOperationType currentType = PNOperationType.PushGet;

            List <string> url = new List <string>();

            url.Add("v1");
            url.Add("push");
            url.Add("sub-key");
            url.Add(pubnubConfig.SubscribeKey);
            url.Add("devices");
            url.Add(pushToken.ToString());

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

            requestQueryStringParams.Add("type", pushType.ToString().ToLower());

            string queryString = BuildQueryString(currentType, url, requestQueryStringParams);
            string queryParams = string.Format("?{0}", queryString);

            return(BuildRestApiRequest <Uri>(url, currentType, queryParams));
        }
Esempio n. 18
0
        Uri IUrlRequestBuilder.BuildRemoveChannelPushRequest(string channel, PNPushType pushType, string pushToken)
        {
            PNOperationType currentType = PNOperationType.PushRemove;

            List <string> url = new List <string>();

            url.Add("v1");
            url.Add("push");
            url.Add("sub-key");
            url.Add(pubnubConfig.SubscribeKey);
            url.Add("devices");
            url.Add(pushToken.ToString());

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

            requestQueryStringParams.Add("type", pushType.ToString().ToLower());
            requestQueryStringParams.Add("remove", new UriUtil().EncodeUriComponent(channel, currentType, true, false, false));

            string queryString = BuildQueryString(currentType, url, requestQueryStringParams);
            string queryParams = string.Format("?{0}", queryString);

            return(BuildRestApiRequest <Uri>(url, currentType, queryParams));
        }
 public void TestBuildGetChannelsPushRequestCommon(bool ssl, string authKey, string pushToken, PNPushType pushType)
 {
     TestBuildGetChannelsPushRequestCommon(ssl, authKey, pushToken, pushType, false);
 }
 public ListPushProvisionsBuilder PushType(PNPushType pnPushType)
 {
     pubBuilder.PushType = pnPushType;
     return(this);
 }
 public RemovePushChannelOperation PushType(PNPushType pushType)
 {
     this.pubnubPushType = pushType;
     return(this);
 }
Esempio n. 22
0
 public AddChannelsToPushBuilder PushType(PNPushType pnPushType)
 {
     pubBuilder.PushType = pnPushType;
     return(this);
 }
        internal async Task <PNResult <PNPushListProvisionsResult> > GetChannelsForDevice(PNPushType pushType, string pushToken, PushEnvironment environment, string deviceTopic, Dictionary <string, object> externalQueryParam)
        {
            if (pushToken == null)
            {
                throw new ArgumentException("Missing Uri");
            }

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

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

            return(ret);
        }
Esempio n. 24
0
        private void txtPush2_Click(object sender, EventArgs e)
        {
            frmPush      pushForm = new frmPush();
            DialogResult result   = pushForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                string     requesttype = pushForm.PushRequestType;
                PNPushType pushType    = PNPushType.GCM;
                switch (pushForm.PushServiceType.ToLower())
                {
                case "gcm":
                    pushType = PNPushType.GCM;
                    break;

                case "apns":
                    pushType = PNPushType.APNS;
                    break;

                default:
                    break;
                }
                switch (requesttype.ToLower())
                {
                case "add":
                    pubnub[1].AddPushNotificationsOnChannels().Channels(pushForm.ChannelName.Split(','))
                    .PushType(pushType)
                    .DeviceId(pushForm.DeviceId)
                    .Async(new PNPushAddChannelResultExt(
                               (r, s) => {
                        Invoke(new Action(() => {
                            if (r != null)
                            {
                                lvResults2.Items.Add(pubnub[1].JsonPluggableLibrary.SerializeToJsonString(r));
                            }
                            else if (s != null)
                            {
                                lvResults2.Items.Add(pubnub[1].JsonPluggableLibrary.SerializeToJsonString(s));
                            }
                        }));
                    }));
                    break;

                case "list":
                    pubnub[1].AuditPushChannelProvisions()
                    .PushType(pushType)
                    .DeviceId(pushForm.DeviceId)
                    .Async(new PNPushListProvisionsResultExt(
                               (r, s) => {
                        Invoke(new Action(() => {
                            if (r != null)
                            {
                                lvResults2.Items.Add(pubnub[1].JsonPluggableLibrary.SerializeToJsonString(r));
                            }
                            else if (s != null)
                            {
                                lvResults2.Items.Add(pubnub[1].JsonPluggableLibrary.SerializeToJsonString(s));
                            }
                        }));
                    }));
                    break;

                case "remove":
                    pubnub[1].RemovePushNotificationsFromChannels()
                    .Channels(pushForm.ChannelName.Split(','))
                    .PushType(pushType)
                    .DeviceId(pushForm.DeviceId)
                    .Async(new PNPushRemoveChannelResultExt(
                               (r, s) => {
                        Invoke(new Action(() => {
                            if (r != null)
                            {
                                lvResults2.Items.Add(pubnub[1].JsonPluggableLibrary.SerializeToJsonString(r));
                            }
                            else if (s != null)
                            {
                                lvResults2.Items.Add(pubnub[1].JsonPluggableLibrary.SerializeToJsonString(s));
                            }
                        }));
                    }));
                    break;

                default:
                    break;
                }
            }
        }
Esempio n. 25
0
        internal async Task <PNResult <PNPushAddChannelResult> > RegisterDevice(string[] channels, PNPushType pushType, string pushToken, PushEnvironment environment, string deviceTopic, Dictionary <string, object> externalQueryParam)
        {
            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");
            }

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

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

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

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

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

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

            return(ret);
        }
Esempio n. 26
0
 public RemoveAllPushChannelsForDeviceBuilder PushType(PNPushType pnPushType)
 {
     pubBuilder.PushType = pnPushType;
     return(this);
 }
        public void TestBuildRegisterDevicePushRequestCommon(bool ssl, string authKey, string pushToken, PNPushType pushType, bool sendQueryParams)
        {
            string channel = "push_channel";
            string uuid    = "customuuid";
            Dictionary <string, string> queryParams = new Dictionary <string, string>();
            string queryParamString = "";

            if (sendQueryParams)
            {
                queryParams.Add("d", "f");
                queryParamString = "&d=f";
            }
            else
            {
                queryParams = null;
            }


            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.Secure           = ssl;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            pnConfiguration.UUID             = uuid;
            pnConfiguration.AuthKey          = authKey;

            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pnConfiguration.AuthKey);
            }

            Uri uri = BuildRequests.BuildRegisterDevicePushRequest(channel, pushType, pushToken, pnUnity, queryParams);

            //[1, "Modified Channels"]
            //https://ps.pndsn.com/v1/push/sub-key/demo-36/devices/pushToken?add=push_channel&type=apns&uuid=customuuid&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            string expected = string.Format("http{0}://{1}/v1/push/sub-key/{2}/devices/{3}?add={4}&type={5}&uuid={6}{7}&pnsdk={8}{9}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, pushToken,
                                            Utility.EncodeUricomponent(channel, PNOperationType.PNAddPushNotificationsOnChannelsOperation, true, false), pushType.ToString().ToLower(),
                                            uuid, authKeyString,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNAddPushNotificationsOnChannelsOperation, false, true),
                                            queryParamString
                                            );
            string received = uri.OriginalString;

            UnityEngine.Debug.Log("exp:" + expected);
            UnityEngine.Debug.Log(received);
            EditorCommon.LogAndCompare(expected, received);
        }
Esempio n. 28
0
 public RemoveChannelsFromPushBuilder PushType(PNPushType pnPushType)
 {
     pubBuilder.PushType = pnPushType;
     return(this);
 }
 public void TestBuildRegisterDevicePushRequestCommon(bool ssl, string authKey, string pushToken, PNPushType pushType)
 {
     TestBuildRegisterDevicePushRequestCommon(ssl, authKey, pushToken, pushType, false);
 }
Esempio n. 30
0
        public void BuildUnregisterDevicePushRequestCommon(bool ssl, string authKey, string pushToken, PNPushType pushType, bool sendQueryParams, bool withAPNS2, bool withEnvProd, bool withTopic)
        {
            string uuid = "customuuid";
            Dictionary <string, string> queryParams = new Dictionary <string, string>();
            string queryParamString = "";

            if (sendQueryParams)
            {
                queryParams.Add("d", "f");
                queryParamString = "&d=f";
            }
            else
            {
                queryParams = null;
            }

            PNConfiguration pnConfiguration = new PNConfiguration();

            pnConfiguration.Origin           = EditorCommon.Origin;
            pnConfiguration.SubscribeKey     = EditorCommon.SubscribeKey;
            pnConfiguration.PublishKey       = EditorCommon.PublishKey;
            pnConfiguration.Secure           = ssl;
            pnConfiguration.CipherKey        = "enigma";
            pnConfiguration.LogVerbosity     = PNLogVerbosity.BODY;
            pnConfiguration.PresenceTimeout  = 60;
            pnConfiguration.PresenceInterval = 30;
            pnConfiguration.UUID             = uuid;
            pnConfiguration.AuthKey          = authKey;

            PubNubUnity pnUnity = new PubNubUnity(pnConfiguration, null, null);

            string authKeyString = "";

            if (!string.IsNullOrEmpty(authKey))
            {
                authKeyString = string.Format("&auth={0}", pnConfiguration.AuthKey);
            }

            Uri uri = BuildRequests.BuildRemoveAllDevicePushRequest(pushType, pushToken, pnUnity, queryParams);

            if (withAPNS2)
            {
                uri = BuildRequests.BuildRemoveAllDevicePushRequest(pushType, pushToken, pnUnity, queryParams, (withTopic)?"topic":"", (withEnvProd)?PNPushEnvironment.Production: PNPushEnvironment.Development);
            }

            //[1, "Removed Device"]
            //https://ps.pndsn.com/v1/push/sub-key/demo-36/devices/pushToken/remove?type=wns&uuid=customuuid&auth=authKey&pnsdk=PubNub-CSharp-UnityIOS/3.6.9.0
            string expected = string.Format("http{0}://{1}/{9}/push/sub-key/{2}/{10}/{3}/remove?type={4}{12}{11}&uuid={5}{6}&pnsdk={7}{8}",
                                            ssl?"s":"", pnConfiguration.Origin, EditorCommon.SubscribeKey, pushToken,
                                            pushType.ToString().ToLower(),
                                            uuid, authKeyString,
                                            Utility.EncodeUricomponent(pnUnity.Version, PNOperationType.PNRemoveAllPushNotificationsOperation, false, true),
                                            queryParamString,
                                            (withAPNS2)?"v2":"v1",
                                            (withAPNS2)?"devices-apns2":"devices",
                                            (withAPNS2)?((withEnvProd)?"&environment=production":"&environment=development"):"",
                                            (withAPNS2)?((withTopic)?"&topic=topic":""):""
                                            );
            string received = uri.OriginalString;

            UnityEngine.Debug.Log("exp:" + expected);
            UnityEngine.Debug.Log(received);
            EditorCommon.LogAndCompare(expected, received);
        }