コード例 #1
0
        public async Task postNotifiactionAsync(String title, String body, Object data, String[] deviceTokens)
        {
            var messageInformation = new GoogleNotification();

            messageInformation.notification       = new NotificationBody();
            messageInformation.notification.text  = body;
            messageInformation.notification.title = title;
            messageInformation.data             = data;
            messageInformation.registration_ids = deviceTokens;
            messageInformation.priority         = "high";

            var    request     = new HttpRequestMessage(HttpMethod.Post, firebaseCloudUrl);
            string jsonMessage = Newtonsoft.Json.JsonConvert.SerializeObject(messageInformation);

            request.Headers.TryAddWithoutValidation("Authorization", "key = " + serverKey);
            request.Content = new StringContent(jsonMessage, Encoding.UTF8, "application/json");
            HttpResponseMessage result;

            using (var client = new HttpClient())
            {
                result = await client.SendAsync(request);

                System.Console.WriteLine(result.IsSuccessStatusCode);
                if (result.IsSuccessStatusCode)
                {
                }
                else
                {
                    var resultBody = result.Content;
                }
            }
        }
コード例 #2
0
ファイル: LeaveController.cs プロジェクト: iorilan/Samples
        public ActionResult Reject(int ID)
        {
            ViewBag.Title = "Leave Reject";
            var  model     = new List <LeaveApplicationObj>();
            bool isSuccess = false;

            try
            {
                var result = LeaveService.Instance.RejectLeaveApplication(ID);
                if (result.IsSuccess)
                {
                    isSuccess = true;
                    ViewBag.IsShowSuccessfullMessage = true;
                    ViewBag.Message = string.Format("Leave application {0} to {1} has been rejected.",
                                                    result.Data.StartDate.ToString("yyyy-MM-dd"),
                                                    result.Data.EndDate.ToString("yyyy-MM-dd"));

                    var leaveRecord = LeaveService.Instance.GetLeaveApplication(ID);
                    if (leaveRecord.IsSuccess)
                    {
                        var broadCastRecord = BroadcastService.Instance.GetBusCaptainGCMID(leaveRecord.Data.PersonnelNumber);
                        var err             = GoogleNotification.CallGoogleAPI(broadCastRecord.Data.GcmID, "Leave Rejected", ViewBag.Message);
                        if (err != "")
                        {
                            _log.ErrorFormat("error while doing google notification on leave reject");
                        }
                    }
                    else
                    {
                        ViewBag.IsShowSuccessfullMessage = true;
                        ViewBag.Message = leaveRecord.ErrorInfo;
                    }
                }
                else
                {
                    ViewBag.IsShowSuccessfullMessage = true;
                    ViewBag.Message = result.ErrorInfo;
                }
            }
            catch (Exception ex)
            {
                ViewBag.IsShowErrorMessage = true;
                ViewBag.Message            = this.CleanJavaScriptString(ex.ToString());
                _log.Error(ex);
            }

            BusCaptainService.Instance.saveActivity(Activities.LeaveReject.ToString(), User.Identity.Name,
                                                    "", "", isSuccess, ID);

            return(View("Index", model));
        }
コード例 #3
0
    public async Task Handle(RequestAdded args)
    {
        try
        {
            GoogleNotification notification = CreateAndroidPartnerAppNotification(deviceId);

            // this statment is executed, and the text log file will contains this line
            TracingSystem.TraceInformation("Before Send Google Notification");

            await SendersFacade.PartnerSender.Send(notification);
        }
        catch (Exception ex)
        {
            TracingSystem.TraceException(ex);
        }
    }
コード例 #4
0
    public async Task SendAsync(GoogleNotification notification)
    {
        TracingSystem.TraceInformation("Inside Send Google notification");
        var json       = notification.GetJson();
        var content    = new StringContent(json, System.Text.Encoding.UTF8, "application/json");
        var requestUri = "https://fcm.googleapis.com/fcm/send";

        using (var message = await Client.PostAsync(requestUri, content)) {
            message.EnsureSuccessStatusCode();
            var result = await message.Content.ReadAsAsync <GoogleNotificationResult>();

            if (result.Failure > 0)
            {
                throw new Exception($"Sending Failed : {result.Results.FirstOrDefault().Error}");
            }
        }
    }
コード例 #5
0
ファイル: LeaveController.cs プロジェクト: iorilan/Samples
        public ActionResult Approve(int ID)
        {
            var actionCodes = RoleModuleMappingService.Instance.GetActionCodesOfModule(User.Identity.Name,
                                                                                       ModuleRoleConstants.Module_LeaveRequest);
            var hasViewAccess   = actionCodes.Data.Contains(ModuleRoleConstants.ActionView);
            var hasUpdateAccess = actionCodes.Data.Contains(ModuleRoleConstants.ActionUpdate);

            if (!hasViewAccess || !hasUpdateAccess)
            {
                this.ShowMessage(false, "", ModuleRoleConstants.NoAccessErrorMsg);
                return(View("Index"));
            }



            ViewBag.Title = "Leave Approval";
            var  model     = new List <LeaveApplicationObj>();
            bool isSuccess = false;

            try
            {
                var result = LeaveService.Instance.ApproveLeaveApplication(ID);
                if (result.IsSuccess)
                {
                    isSuccess = true;
                    ViewBag.IsShowSuccessfullMessage = true;
                    ViewBag.Message = string.Format("Leave application {0} to {1} has been approved.",
                                                    result.Data.StartDate.ToString("yyyy-MM-dd"),
                                                    result.Data.EndDate.ToString("yyyy-MM-dd"));

                    var leaveRecord = LeaveService.Instance.GetLeaveApplication(ID);
                    if (leaveRecord.IsSuccess)
                    {
                        var broadCastRecord = BroadcastService.Instance.GetBusCaptainGCMID(leaveRecord.Data.PersonnelNumber);

                        var err = GoogleNotification.CallGoogleAPI(broadCastRecord.Data.GcmID, "Leave Approval",
                                                                   ViewBag.Message);

                        var  broadcast = new BroadcastController();
                        bool apnsErr   = AppleNotification.Push(broadCastRecord.Data.GcmID, ViewBag.Message);

                        if (err != "")
                        {
                            _log.ErrorFormat("error while doing google notification on leave approval");
                        }
                    }
                    else
                    {
                        ViewBag.IsShowErrorMessage = true;
                        ViewBag.Message            = leaveRecord.ErrorInfo;
                    }
                }
                else
                {
                    ViewBag.IsShowErrorMessage = true;
                    ViewBag.Message            = result.ErrorInfo;
                }
            }
            catch (Exception ex)
            {
                ViewBag.IsShowErrorMessage = true;
                ViewBag.Message            = this.CleanJavaScriptString(ex.ToString());
                _log.Error(ex);
            }

            BusCaptainService.Instance.saveActivity(Activities.LeaveApprove.ToString(), User.Identity.Name,
                                                    "", "", isSuccess, ID);

            return(View("Index", model));
        }
コード例 #6
0
        private async Task AndriodPushNotification(string deviceToken, Notification notification)
        {
            GoogleNotification googleNotification = new GoogleNotification
            {
                To           = deviceToken.Trim(),
                Collapse_Key = "type_a",
                Data         = new DataNotification
                {
                    Notification = notification
                },
                Notification = new NotificationModel
                {
                    Title = notification.Text,
                    Text  = notification.Text,
                    Icon  = !string.IsNullOrEmpty(notification.Image) ? notification.Image : "https://www.nextlevelfootballacademy.co.uk/wp-content/uploads/2019/06/logo.png"
                }
            };

            using (var httpClient = new HttpClient())
            {
                using var httpRequest = new HttpRequestMessage(HttpMethod.Post, "https://fcm.googleapis.com/fcm/send");
                httpRequest.Headers.Add("Authorization", $"key = {_fcmSettings.ServerKey}");
                httpRequest.Headers.Add("Sender", $"id = {_fcmSettings.SenderId}");
                var http = new HttpClient();
                var json = JsonConvert.SerializeObject(googleNotification);
                httpRequest.Content = new StringContent(json, Encoding.UTF8, "application/json");
                var response = await httpClient.SendAsync(httpRequest);

                if (!response.IsSuccessStatusCode)
                {
                    var    notificationError = response.Content.ReadAsStringAsync().Result;
                    var    device_Token      = deviceToken;
                    var    user    = _unitOfWork.UserRepository.FindOne(x => x.DeviceToken.ToLower() == device_Token.ToLower());
                    string path    = Directory.GetCurrentDirectory();
                    var    num     = string.IsNullOrEmpty(user.MobileNo) ? "" : user.MobileNo.ToString();
                    var    email   = string.IsNullOrEmpty(user.EmailID) ? "" : user.EmailID.ToString();
                    string newPath = path + "\\wwwroot\\ErrorLogFile\\AndroidErrorDevices.txt";
                    using (StreamWriter writer = new StreamWriter(newPath, true))
                    {
                        writer.WriteLine("-----------------------------------------------------------------------------");
                        writer.WriteLine("Email : " + email.ToString());
                        writer.WriteLine("Mobile_No : " + num);
                        writer.WriteLine("Device_Token : " + device_Token.ToString());
                        writer.WriteLine("Error : " + notificationError.ToString());
                        writer.WriteLine("-----------------------------------------------------------------------------");
                        writer.WriteLine();
                    }
                }
                else
                {
                    var    device_Token = deviceToken;
                    var    user         = _unitOfWork.UserRepository.FindOne(x => x.DeviceToken.ToLower() == device_Token.ToLower());
                    string path         = Directory.GetCurrentDirectory();
                    var    num          = string.IsNullOrEmpty(user.MobileNo) ? "" : user.MobileNo.ToString();
                    var    email        = string.IsNullOrEmpty(user.EmailID) ? "" : user.EmailID.ToString();
                    string newPath      = path + "\\wwwroot\\ErrorLogFile\\AndroidWorkingDevices.txt";
                    using (StreamWriter writer = new StreamWriter(newPath, true))
                    {
                        writer.WriteLine("-----------------------------------------------------------------------------");
                        writer.WriteLine("Email : " + email);
                        writer.WriteLine("Mobile_No : " + num);
                        writer.WriteLine("Device_Token : " + device_Token.ToString());
                        writer.WriteLine("-----------------------------------------------------------------------------");
                        writer.WriteLine();
                    }
                }
            }
        }