/// <summary> /// Builds forecast page model for given app-chain job IDs and location /// </summary> /// <param name="jobId"></param> /// <param name="jobId2"></param> /// <param name="city"></param> /// <returns></returns> public RunResult Build(string jobId, string jobId2, string city) { mode = service.GetInfo(userName).Temperature ?? TemperatureMode.F; var _weatherWorker = new WeatherWorker(userName); var _forecastRoot = _weatherWorker.GetForecast10(city); var _runResult = new RunResult { Weather = _forecastRoot.current_observation.weather + " " + (mode == TemperatureMode.F ? _forecastRoot.current_observation.temp_f + "F" : _forecastRoot.current_observation.temp_c + "C"), Forecast = _forecastRoot, CurrentWeather = _forecastRoot.current_observation }; var _appChainResults = GetAppChainResultingRisks(jobId, jobId2); if (_forecastRoot != null) { var _alertCode = _forecastRoot.alerts.Count == 0 ? "--" : _forecastRoot.alerts[0].type; var _riskDescription = GetPersonalizedRiskDescription(_forecastRoot.forecast.simpleforecast.forecastday[0].conditions, _alertCode, _appChainResults, userName, Options.ApplicationName); _runResult.Risk = _riskDescription; _runResult.RawRisk = _appChainResults.MelanomaAppChainResult.ToString(); _runResult.Temperature = mode; _runResult.JobDateTime = _appChainResults.AppChainRunDt; } return(_runResult); }
public async override void Handle(MessageWrapper message, ITelegramBotClient client) { if (message.HasRegexIgnoreMention(BotWeatherRegex) || message.HasRegexIgnoreMention(BotWeatherSmallRegex)) { var we = new WeatherWorker(); var mm = BotWeatherRegex.Match(message.CurrentMessage); if (!mm.Success) { mm = BotWeatherRegex.Match(message.MessageInLayouts[1]); } if (!mm.Success) { mm = BotWeatherSmallRegex.Match(message.CurrentMessage); } if (!mm.Success) { mm = BotWeatherSmallRegex.Match(message.MessageInLayouts[1]); } var m = mm.Groups.Last(); if (m.Value.Contains("киев", StringComparison.InvariantCultureIgnoreCase)) { await client.SendTextMessageAsync(message.Chat.Id, we.GetWeather("kyiv")); } if (m.Value.Contains("днепр", StringComparison.InvariantCultureIgnoreCase)) { await client.SendTextMessageAsync(message.Chat.Id, we.GetWeather("dnipro")); } } else { NextHandler?.Handle(message, client); } }
public JsonResult ValidateLocation(string city) { if (WeatherWorker.WeatherParser(city) != null) { return(Json(JsonConvert.SerializeObject(new { isCorrect = true }), JsonRequestBehavior.AllowGet)); } return(Json(JsonConvert.SerializeObject(new { isCorrect = false }), JsonRequestBehavior.AllowGet)); }
public ActionResult SaveLocation(string city) { string location = WeatherWorker.ConvertFromNameToID(city); if (location != null) { settingService.SetUserLocation(location, User.Identity.Name); } if (!string.IsNullOrEmpty(Request.QueryString[REDIRECT_URI_PAR])) { return(Redirect(Request.QueryString[REDIRECT_URI_PAR])); } return(RedirectToAction("SelectFile")); }
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)); }
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())); }
/// <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(); } } } }
public WeatherController(WeatherWorker worker) { _worker = worker; }