예제 #1
0
        private bool SendNotification(PushNotificationLogs fcmdevices)
        {
            bool status = true;

            try
            {
                WebRequest tRequest = WebRequest.Create(Utilities.fcmURL);
                tRequest.Method      = "post";
                tRequest.ContentType = "application/json";
                var data = new
                {
                    to           = Utilities.deviceToken,
                    priority     = Utilities.priority,
                    notification = new
                    {
                        body            = fcmdevices.Topic,
                        title           = "Ïnitiative Campaign",
                        notification_id = fcmdevices.InitiativeCampaignId
                    }
                };
                var    serializer = new JavaScriptSerializer();
                var    json       = serializer.Serialize(data);
                Byte[] byteArray  = Encoding.UTF8.GetBytes(json);
                tRequest.Headers.Add(string.Format("Authorization: key={0}", _config.ApplicationID));
                tRequest.Headers.Add(string.Format("Sender: id={0}", _config.SenderID));
                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();
                                JObject sResponse           = JObject.Parse(sResponseFromServer);
                                status = Convert.ToInt32(sResponse["success"]) == 1 ? true : false;
                            }
                        }
                    }
                }
            }

            catch (Exception)
            {
                status = false;
            }
            return(status);
        }
예제 #2
0
        public void ProcessCampaign(IList <Campaign> campaigns)
        {
            //log.Info(String.Format("Start Processing:{0}", campaigns.Count.ToString()));
            if (campaigns.Count > 0)
            {
                campaigns.ToList().ForEach(x => {
                    if (x.Initiative != null)
                    {
                        var runToday = x.Initiative.InitiativeCampaign.Where(dt => dt.StartDateTime.Value.Date.Equals(DateTime.Now.Date));
                        runToday.ToList().ForEach(y =>
                        {
                            //log.Info(String.Format("Start Processing Campaign:{0}", y.Id));
                            var isExists = _notificationService.GetNotificationByInitiativeCampaignId(Convert.ToInt32(y.Id));

                            if (isExists != null)
                            {
                                isExists.SendCnt   = isExists.SendCnt + 1;
                                isExists.UpdatedBy = 1;
                                isExists.UpdatedOn = DateTime.Now;
                                if (SendNotification(isExists))
                                {
                                    _notificationService.UpdateNotification(isExists);
                                }
                            }
                            else
                            {
                                PushNotificationLogs push = new PushNotificationLogs();
                                push.CreatedBy            = 1;
                                push.CreatedOn            = DateTime.Now;
                                push.InitiativeCampaignId = y.Id;
                                push.SendCnt          = 1;
                                push.NotificationType = (int)NotificationType.PushNotification;
                                push.Topic            = y.Description;
                                if (SendNotification(push))
                                {
                                    _notificationService.CreateNotification(push);
                                }
                            }
                            // log.Info(String.Format("End Processing Campaign:{0}", y.Id));
                        });
                    }
                });
            }
            //log.Info(String.Format("End Processing:{0}", campaigns.Count.ToString()));
        }
예제 #3
0
 public bool SendEmail(PushNotificationLogs notification)
 {
     throw new NotImplementedException();
 }
예제 #4
0
 public bool SendNotification(PushNotificationLogs notification) => _notification.SendToSingle(notification);
예제 #5
0
        public bool SendToSingle(PushNotificationLogs fcmdevice)
        {
            bool status = SendNotification(fcmdevice);

            return(status);
        }
예제 #6
0
 public bool SendSMS(PushNotificationLogs campaign)
 {
     throw new System.NotImplementedException();
 }
예제 #7
0
 public bool SendNotification(PushNotificationLogs campaign)
 {
     return(_notification.SendToSingle(campaign));
 }
예제 #8
0
 public int UpdateNotification(PushNotificationLogs notification)
 {
     return(_repoNotification.UpdateNotification(notification));
 }
예제 #9
0
 public int DeleteNotification(PushNotificationLogs notifications)
 {
     return(_repoNotification.DeleteNotification(notifications));
 }
예제 #10
0
 public int CreateNotification(PushNotificationLogs notifications)
 {
     return(_repoNotification.CreateNotification(notifications));
 }