Esempio n. 1
0
        /// <summary>
        /// Get notification content by NotificationType
        /// </summary>
        /// <param name="notification">notification type</param>
        /// <returns></returns>
        public static string GetContent(NotificationType notification, string countryLanguage = "fr")
        {
            switch (notification)
            {
            case NotificationType.InstructionTaken:
                return(ResourcesHelper.GetLocalizedString("InstructionTaken", countryLanguage));

            case NotificationType.RefreshPosition:
                return(ResourcesHelper.GetLocalizedString("GPSPositionReceived", countryLanguage));

            case NotificationType.RefreshPositionByCellsData:
                return(ResourcesHelper.GetLocalizedString("ApproximativePositionReceived", countryLanguage));

            case NotificationType.NotifySeekiosOutOfZone:
                return(ResourcesHelper.GetLocalizedString("OutOfZone", countryLanguage));

            case NotificationType.AddTrackingLocation:
                return(ResourcesHelper.GetLocalizedString("TrackingPositionReveived", countryLanguage));

            case NotificationType.AddNewZoneTrackingLocation:
                return(ResourcesHelper.GetLocalizedString("ZoneTrackingPositionReceived", countryLanguage));

            case NotificationType.AddNewDontMoveTrackingLocation:
                return(ResourcesHelper.GetLocalizedString("DMTrackingPositionReceived", countryLanguage));

            case NotificationType.NotifySeekiosMoved:
                return(ResourcesHelper.GetLocalizedString("SeekiosMoved", countryLanguage));

            case NotificationType.SOSSent:
                return(ResourcesHelper.GetLocalizedString("SOSAlertReceived", countryLanguage));

            case NotificationType.SOSLocationSent:
                return(ResourcesHelper.GetLocalizedString("SOSPositionGPSReceived", countryLanguage));

            case NotificationType.SOSLocationByCellsDataSent:
                return(ResourcesHelper.GetLocalizedString("SOSPositionApproximativeReceived", countryLanguage));

            case NotificationType.RefreshCredits:
                return(ResourcesHelper.GetLocalizedString("RefreshCredits", countryLanguage));

            case NotificationType.CriticalBattery:
                return(ResourcesHelper.GetLocalizedString("CriticalBattery", countryLanguage));

            case NotificationType.PowerSavingDisabled:
                return(ResourcesHelper.GetLocalizedString("PowerSavingDisabled", countryLanguage));

            case NotificationType.ChangeMode:
                return(ResourcesHelper.GetLocalizedString("ChangeMode", countryLanguage));

            default:
                return(string.Empty);
            }
        }
        public static async void SendAlertSOSEmail(seekios_dbEntities seekiosEntities
                                                   , IEnumerable <string> emailsTo
                                                   , string firstName
                                                   , string lastName
                                                   , string seekiosName
                                                   , double?lat
                                                   , double?longi
                                                   , string alertContent
                                                   , int idcountryResources
                                                   , bool isGPS = true)
        {
            var latitude = lat != null?lat.ToString().Replace(",", ".") : string.Empty;

            var longitude = longi != null?longi.ToString().Replace(",", ".") : string.Empty;

            dynamic sendGridClient  = new SendGridClient(_API_KEY);
            var     contentEmailBdd = (from cr in seekiosEntities.countryResources
                                       where cr.idcountryResources == idcountryResources
                                       select cr).Take(1).First();

            var emailContent  = string.IsNullOrEmpty(alertContent) ? contentEmailBdd.alertSOSEmailContent : contentEmailBdd.alertSOSEmailWithMsgContent;
            var emailSendFrom = new EmailAddress(_EMAIL_SENDER);
            var emailSendTo   = new List <EmailAddress>();

            foreach (var email in emailsTo)
            {
                emailSendTo.Add(new EmailAddress()
                {
                    Email = email
                });
            }

            // add the text body
            string finalAlertContent = string.IsNullOrEmpty(alertContent) ?
                                       emailContent.Replace("{0}", firstName)
                                       .Replace("{1}", lastName)
                                       .Replace("{2}", seekiosName)
                                       .Replace("{3}", isGPS ? ResourcesHelper.GetLocalizedString("GPS", idcountryResources) : ResourcesHelper.GetLocalizedString("ApproxPosition", idcountryResources))
                                       .Replace("{4}", latitude)
                                       .Replace("{5}", longitude)
                : emailContent.Replace("{0}", firstName)
                                       .Replace("{1}", lastName)
                                       .Replace("{2}", seekiosName)
                                       .Replace("{3}", alertContent)
                                       .Replace("{4}", isGPS ? ResourcesHelper.GetLocalizedString("GPS", idcountryResources) : ResourcesHelper.GetLocalizedString("ApproxPosition", idcountryResources))
                                       .Replace("{5}", latitude)
                                       .Replace("{6}", longitude);

            var content  = new Content(_ACCOUNT_VERIFICATION_EMAIL_CONTENT_TYPE, finalAlertContent);
            var mail     = MailHelper.CreateSingleEmailToMultipleRecipients(emailSendFrom, emailSendTo, contentEmailBdd.alertSOSEmailTitle, null, content.Value);
            var response = await sendGridClient.SendEmailAsync(mail);
        }
Esempio n. 3
0
        public static bool SendNotificationWithDataToAndroid(seekios_dbEntities seekiosEntities
                                                             , string tag
                                                             , string seekiosName
                                                             , string methodName
                                                             , object parameters
                                                             , string language)
        {
            var request = CreateHttpRequest(PlatformEnum.Android);
            var obj     = new
            {
                app_id                = ONESIGNAL_PRIVATE_KEY_ANDROID,
                contents              = new { en = methodName },
                headings              = new { en = seekiosName },
                filters               = new object[] { new { field = "tag", key = tag, relation = "exists" } },//filters,
                data                  = parameters,
                android_group         = _isRefreshingCredits ? "2" : "1",
                android_group_message = new { en = ResourcesHelper.GetLocalizedString("NotifCount", language) },
            };
            var param           = new JavaScriptSerializer().Serialize(obj);
            var byteArray       = Encoding.UTF8.GetBytes(param);
            var responseContent = string.Empty;
            var exception       = string.Empty;
            var returnCode      = true;

            try
            {
                using (var writer = request.GetRequestStream())
                {
                    writer.Write(byteArray, 0, byteArray.Length);
                }

                using (var response = request.GetResponse() as HttpWebResponse)
                {
                    using (var reader = new StreamReader(response.GetResponseStream()))
                    {
                        responseContent = reader.ReadToEnd();
                    }
                }
            }
            catch (WebException ex)
            {
                exception  = ex.Message;
                returnCode = !returnCode;
            }
            LogOneSignalRequest(seekiosEntities, tag, seekiosName, methodName, exception, responseContent, returnCode);
            return(returnCode);
        }