Ejemplo n.º 1
0
        public ActionResult Results(string jobId, string jobId2, long?timestamp)
        {
            var _ts = new DateTime(timestamp ?? 0);

            if (Math.Abs(DateTime.Now.Subtract(_ts).TotalMinutes) > MINUTES_FOR_RESULTS_USER_REFRESH)
            {
                return(RedirectToAction("GoToResults"));
            }

            var _isAuthenticated = User.Identity.IsAuthenticated;
            var _userName        = User.Identity.Name;
            var _runResult       = new PersonalizedForecastResultBuilder(_userName, TemperatureMode.F).Build(jobId, jobId2, Context.City);

            Context.City      = WeatherWorker.ConvertFromIDToName(Context.City);
            ViewBag.ShowEmail = _isAuthenticated;
            ViewBag.LastJobId = jobId;
            ViewBag.City      = Context.City;
            return(View(_runResult));
        }
Ejemplo n.º 2
0
        public ActionResult Index()
        {
            var _name     = User.Identity.Name;
            var _sendInfo = settingService.GetInfo(_name);

            ViewBag.SelectedLocation = WeatherWorker.ConvertFromIDToName(_sendInfo.City);
            ViewBag.EmailSend        = _sendInfo.SendEmail ?? false;
            ViewBag.SmsSend          = _sendInfo.SendSms ?? false;
            ViewBag.Email            = _sendInfo.UserEmail;
            ViewBag.Phone            = _sendInfo.UserPhone;
            ViewBag.AuthDt           = new UserAuthWorker().GetCurrent().AuthDt;
            ViewBag.DataFileName     = _sendInfo.DataFileName;
            ViewBag.wakeupDay        = _sendInfo.TimeWeekDay;
            ViewBag.wakeupEnd        = _sendInfo.TimeWeekEnd;
            ViewBag.tzOffset         = _sendInfo.TimeZoneOffset;
            ViewBag.tzValue          = _sendInfo.TimeZoneValue;
            ViewBag.CountryCode      = _sendInfo.CountryCode;

            var _values = new[]
            {
                new { Id = WeekEndMode.SendEmail.ToString(), Name = "Only send email notifications on weekend" },
                new { Id = WeekEndMode.SendSms.ToString(), Name = "Only send txt msg (SMS) notifications on weekend" },
                new { Id = WeekEndMode.SendBoth.ToString(), Name = "Send notifications on weekends" },
                new { Id = WeekEndMode.None.ToString(), Name = "Do not send any notifications on weekends" },
                new { Id = WeekEndMode.Push.ToString(), Name = "Only send push notifications on weekend" },
                new { Id = WeekEndMode.PushAndEmail.ToString(), Name = "Send push and email notifications on weekend" },
                new { Id = WeekEndMode.PushAndSms.ToString(), Name = "Send push and msg (SMS) notifications on weekend" },
                new { Id = WeekEndMode.All.ToString(), Name = "Send all notifications on weekend" },
            };

            ViewBag.weekendModeList = new SelectList(_values, "Id", "Name", _sendInfo.WeekendMode.ToString());
            ViewBag.weekendMode     = _sendInfo.WeekendMode;
            ViewBag.temperature     = _sendInfo.Temperature;
            ViewBag.temperatureList = new SelectList(new[]
            {
                new { Id = TemperatureMode.F.ToString(), Name = "F" },
                new { Id = TemperatureMode.C.ToString(), Name = "C" },
            }, "Id", "Name", _sendInfo.Temperature.ToString());
            return(View(new CommonData()));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Checks all users and sends emails/sms/on-site-alerts when appropriate
        /// </summary>
        public void CheckAllAndSendEmails()
        {
            using (var _ctx = new WeatherAppDbEntities())
            {
                var _api   = new MandrillApi(Options.MandrillApi);
                var _infos =
                    _ctx.SendInfo.Where(info => (info.SendEmail ?? false) || (info.SendSms ?? false)).ToList();
                foreach (var _info in _infos)
                {
                    var _mode = _info.Temperature ?? TemperatureMode.F;
                    var _rrb  = new PersonalizedForecastResultBuilder(_info.UserName, _mode);
                    LogManager.GetLogger(GetType()).Debug("Processing sendInfo:" + _info.Id);
                    if (IsRightTime(_info))
                    {
                        LogManager.GetLogger(GetType()).Debug("Processing sendInfo, time was right:" + _info.Id);
                        var _weatherWorker = new WeatherWorker(_info.UserName);
                        var _forecastRoot  = _weatherWorker.GetForecast10(_info.City);
                        LogManager.GetLogger(GetType()).Debug("Received forecast:" + _info.Id);
                        if (string.IsNullOrEmpty(_info.DataFileId))
                        {
                            continue;
                        }
                        var _jobId = GetJobId(_info);
                        LogManager.GetLogger(GetType()).Debug("Started job:" + _info.Id);

                        var _riskValue = _rrb.GetAppChainResultingRisks(_jobId.Item1.ToString(), _jobId.Item2.ToString());
                        var _alertCode = _forecastRoot.alerts.Count == 0 ? "--" : _forecastRoot.alerts[0].type;

                        var _riskDescription = _rrb.GetPersonalizedRiskDescription(_forecastRoot.forecast.simpleforecast.forecastday[0].conditions, _alertCode, _riskValue, _info.UserName, Options.ApplicationName);
                        var _subj            =
                            string.Format("Forecast for " +
                                          DateTime.Now.ToString("dddd MMMM d"));
                        var _city          = WeatherWorker.ConvertFromIDToName(_info.City);
                        var _time          = _forecastRoot.current_observation.observation_time;
                        var _todayForecast = _mode == TemperatureMode.F ?
                                             _forecastRoot.forecast.txt_forecast.forecastday[0].fcttext :
                                             _forecastRoot.forecast.txt_forecast.forecastday[0].fcttext_metric;
                        var _currentObservation = _forecastRoot.current_observation.weather + " and " + (_mode == TemperatureMode.F
                                                 ? _forecastRoot.current_observation.temp_f + "F"
                                                 : _forecastRoot.current_observation.temp_c + "C");

                        if (_info.SendSms ?? false)
                        {
                            LogManager.GetLogger(GetType()).Debug("Sending sms:" + _info.Id);
                            SendSmsNotification(_info, _city, _todayForecast, _currentObservation, _riskDescription);
                        }

                        if (notificationService.IsUserSubscribed(_info.Id))
                        {
                            LogManager.GetLogger(GetType()).Debug("Sending push:" + _info.Id);
                            SendPushNotification(_info, _city, _todayForecast, _currentObservation, _riskDescription);
                        }

                        if (_info.SendEmail ?? false)
                        {
                            LogManager.GetLogger(GetType()).Debug("Sending email:" + _info.Id);
                            SendEmailNotification(_info, _city, _todayForecast, _currentObservation, _riskDescription, _forecastRoot, _mode, _api, _subj);
                        }

                        _info.LastSendDt = DateTime.Now;
                        _ctx.SaveChanges();
                    }
                }
            }
        }