コード例 #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));
        }
コード例 #2
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();
                    }
                }
            }
        }