コード例 #1
0
        /// <summary>
        /// For Pushing Notifications
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public PushNotificationResponse PushNotification(PushNotificationRequest request)
        {
            PushNotificationResponse response = new PushNotificationResponse();

            pushNotificationRepository.PushNotifications(request.PushNotification);
            return(response);
        }
コード例 #2
0
ファイル: PushManager.cs プロジェクト: moljac/shiny
        public void Start()
        {
            OS.Current.SetLogLevel(this.config.LogLevel, this.config.VisualLogLevel);
            OS.Current
            .StartInit(this.config.AppId)
            .HandleNotificationOpened(async x =>
            {
                var notification = ToNotification(x.notification?.payload);
                var pr           = new PushNotificationResponse(notification, x.action?.actionID, null);
                await this.container.OnEntry(pr).ConfigureAwait(false);
            })
            .HandleNotificationReceived(async x =>
            {
                // silence onesignal notification
                x.silentNotification = true;

                // could also build channel here
                var notification = ToNotification(x.payload);
                var pn           = new PushNotification(notification.Payload, notification);
                await this.container.OnReceived(pn).ConfigureAwait(false);
            })
            .Settings(new Dictionary <string, bool>
            {
                { IOSSettings.kOSSettingsKeyAutoPrompt, config.iOSAutoPrompt },
                { IOSSettings.kOSSettingsKeyInAppLaunchURL, config.iOSInAppLaunchURL }
            })
            .InFocusDisplaying(this.config.InFocusDisplay)
            .EndInit();
        }
コード例 #3
0
        public HttpResponseMessage PushNotificationDetails(PushNotification ViewModel)
        {
            ViewModel.CreatedDate = DateTime.Now.ToUniversalTime();
            PushNotificationResponse response = new PushNotificationResponse();

            try
            {
                response = pushNotificationService.PushNotification(new PushNotificationRequest()
                {
                    PushNotification = ViewModel
                });
            }
            catch (Exception ex)
            {
                response.Message = ex.Message;
            }

            return(Request.BuildResponse(response));
        }
コード例 #4
0
ファイル: Form1.cs プロジェクト: huyqta/GetzTool
        public async Task SendIOSPushNotify(PushNotificationObject pushObject)
        {
            resultPush = "";
            //Task<string> getStringTask = client.GetStringAsync("start");
            PushNotificationResponse response = new PushNotificationResponse();
            WebClient wc1      = new WebClient();
            var       onlCert1 = wc1.DownloadData(pushObject.FileP12Name);
            // Configuration (NOTE: .pfx can also be used here)
            var config = new ApnsConfiguration(ApnsConfiguration.ApnsServerEnvironment.Production,
                                               onlCert1, pushObject.FileP12Password);

            // Create a new broker
            var apnsBroker = new ApnsServiceBroker(config);

            // Wire up events
            apnsBroker.OnNotificationFailed += (notification, aggregateEx) =>
            {
                aggregateEx.Handle(ex =>
                {
                    // See what kind of exception it was to further diagnose
                    if (ex is ApnsNotificationException)
                    {
                        var notificationException = (ApnsNotificationException)ex;

                        // Deal with the failed notification
                        var apnsNotification = notificationException.Notification;
                        var statusCode       = notificationException.ErrorStatusCode;
                        resultPush          += ($"Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}") + Environment.NewLine;

                        //System.Console.WriteLine($"Apple Notification Failed: ID={apnsNotification.Identifier}, Code={statusCode}");
                    }
                    else
                    {
                        // Inner exception might hold more useful information dows.Forms.RichTextBox)mFormMain.Controls.Find("txtPushResults", true)[0];

                        resultPush = ($"Apple Notification Failed for some unknown reason : {ex.InnerException}") + Environment.NewLine;
                    }

                    // Mark it as handled
                    return(true);
                });
            };

            apnsBroker.OnNotificationSucceeded += (notification) =>
            {
                resultPush = ("Apple Notification Sent!") + Environment.NewLine;
            };

            // Start the broker
            apnsBroker.Start();
            string data = "{\"aps\":{\"badge\":" + pushObject.Badge + ", \"alert\": \"" + pushObject.Alert + "\", \"sound\": \"" + pushObject.AppleDeviceSoundNotify + "\"}}";

            foreach (var deviceToken in pushObject.ListDevice)
            {
                if (string.IsNullOrEmpty(deviceToken) || deviceToken.Equals("\r") || deviceToken.Equals("\n"))
                {
                    continue;
                }
                // Queue a notification to send
                apnsBroker.QueueNotification(new ApnsNotification
                {
                    DeviceToken = deviceToken,
                    Payload     = JObject.Parse(data)
                });
            }
            // Stop the broker, wait for it to finish
            // This isn't done after every message, but after you're
            // done with the broker
            apnsBroker.Stop();
            response.Message = "Success!";
            return;
        }
コード例 #5
0
            /// <summary>
            /// <author>Pankaj Kumar</author>
            /// <desc>For sending push notification</desc>
            /// </summary>
            /// <param name="objPushNotification"></param>
            /// <returns></returns>
            public string SendPushNotification(PushNotification objPushNotification)
            {
                string result = string.Empty;

                try
                {
                    Console.WriteLine("Sending Android notification...");
                    //var value = message;
                    //HttpWebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send") as HttpWebRequest;
                    HttpWebRequest tRequest = WebRequest.Create(PushNotificationEndpoint) as HttpWebRequest;

                    //WebRequest tRequest = WebRequest.Create("https://fcm.googleapis.com/fcm/send");
                    tRequest.Method    = "post";
                    tRequest.UserAgent = "Android GCM Message Sender Client 1.0";
                    tRequest.Headers.Add(string.Format("Authorization: key={0}", serverApiKey));
                    tRequest.Headers.Add(string.Format("Sender: id={0}", senderId));

                    //tRequest.ContentType = "application/x-www-form-urlencoded;charset=UTF-8";
                    //string postData = "collapse_key=score_update&time_to_live=108&delay_while_idle=1&data.message=" + value + "&data.time=" + System.DateTime.Now.ToString() + "&registration_id=" + deviceId + "";
                    //string postData = "notification.title=KontaKKT&notification.body=HI Pankaj&to=" + deviceId;
                    //Byte[] byteArray = Encoding.UTF8.GetBytes(postData);


                    tRequest.ContentType = "application/json";
                    var data = new
                    {
                        to       = objPushNotification.DeviceToken,
                        priority = "high", //high,//normal
                                           //collapse_key = "score_update",
                                           //delay_while_idle = true,
                                           //time_to_live = 108,
                                           //message = "Hi all",
                        notification = new
                        {
                            title = objPushNotification.Data, //objPushNotification.MessageType + "-" +
                            body  = objPushNotification.MessageText,
                            //type = objPushNotification.MessageType
                        },
                        data = new
                        {
                            title = objPushNotification.Data,//objPushNotification.MessageType + "-" +
                            body  = objPushNotification.MessageText,
                        }
                    };
                    var    serializer = new JavaScriptSerializer();
                    var    json       = serializer.Serialize(data);
                    Byte[] byteArray  = Encoding.UTF8.GetBytes(json);

                    tRequest.ContentLength = byteArray.Length;
                    using (Stream dataStream = tRequest.GetRequestStream())
                    {
                        dataStream.Write(byteArray, 0, byteArray.Length);
                        using (WebResponse tResponse = tRequest.GetResponse())
                        {
                            using (Stream dataStreamResponse = tResponse.GetResponseStream())
                            {
                                using (StreamReader tReader = new StreamReader(dataStreamResponse))
                                {
                                    string sResponseFromServer = tReader.ReadToEnd();
                                    var    deserializer        = new JavaScriptSerializer();
                                    PushNotificationResponse objPushNotificationResponse = deserializer.Deserialize <PushNotificationResponse>(sResponseFromServer);
                                    //result = sResponseFromServer;
                                    objPushNotification.Messageid = objPushNotificationResponse.results[0].message_id;
                                    objPushNotification.Error     = !string.IsNullOrEmpty(objPushNotificationResponse.results[0].error) ? objPushNotificationResponse.results[0].error : string.Empty;

                                    Console.WriteLine("{Sno:\t" + objPushNotification.Sno + "} { MessageId:\t" + objPushNotification.Messageid + "}{Error:\t" + objPushNotification.Error + "}");
                                    if (!string.IsNullOrEmpty(objPushNotification.Messageid))
                                    {
                                        UpdateUserPushNotification(objPushNotification);
                                    }
                                    else
                                    {
                                        UpdateUserPushNotification(objPushNotification);
                                        //LogEntryIntoFile(sResponseFromServer);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    return(result = ex.Message);
                }

                return(result);
            }
コード例 #6
0
 public Task OnEntry(PushNotificationResponse response)
 {
     Entry?.Invoke(response);
     return(Task.CompletedTask);
 }
コード例 #7
0
 public Task OnEntry(PushNotificationResponse push)
 => this.Insert("PUSH ENTRY");
コード例 #8
0
ファイル: MyPushDelegate.cs プロジェクト: aritchie/App1
 public async Task OnEntry(PushNotificationResponse response)
 {
     // this is when a user taps on or responds to a notification
 }