private void queryRecords(Pagination pagination) { try { IEnumerable <FreezeBaseInfo> orders = FreezeService.Query(getCondition(), pagination); dataList.DataSource = orders; dataList.DataBind(); if (orders.Any()) { pager.Visible = true; if (pagination.GetRowCount) { pager.RowCount = pagination.RowCount; } } else { pager.Visible = false; } } catch (Exception ex) { ShowExceptionMessage(ex, "查询账户状态"); } }
public DevicesController(DeviceService deviceService, TelemetryService telemetryService, AlarmService alarmService, FreezeService freezeService) { this.deviceService = deviceService; this.telemetryService = telemetryService; this.alarmService = alarmService; this.freezeService = freezeService; }
public static async Task Run([TimerTrigger("0 0 18 * * *")] TimerInfo myTimer, TraceWriter log) { log.Info($"C# Timer trigger function executed at: {DateTime.Now}"); DependencyInjection.ConfigureInjection(log); using (var scope = DependencyInjection.Container.BeginLifetimeScope()) { FreezingAlgorithme algorithme = scope.Resolve <FreezingAlgorithme>(); DeviceService deviceService = scope.Resolve <DeviceService>(); NotificationService notificationService = scope.Resolve <NotificationService>(); FreezeService freezeService = scope.Resolve <FreezeService>(); AlarmService alarmService = scope.Resolve <AlarmService>(); OpenWeatherMapClient weatherClient = scope.Resolve <OpenWeatherMapClient>(); IList <Alarm> alarms = new List <Alarm>(); try { log.Info("Get latest telemtry"); Dictionary <Device, Telemetry> telemetries = deviceService.GetLatestTelemetryByDevice(); foreach (var item in telemetries) { OwmCurrentWeather current = await weatherClient.GetCurrentWeather(item.Key.Position.Latitude, item.Key.Position.Longitude); OwmForecastWeather forecast = await weatherClient.GetForecastWeather(item.Key.Position.Latitude, item.Key.Position.Longitude); log.Info($"Execute Algorithme (device {item.Key.Id})"); FreezeForecast freeze = await algorithme.Execute(item.Value, item.Key, current.Weather, forecast.Forecast, forecast.StationPosition); if (freeze == null) { log.Error($"Unable to calculate the freeze probability (no forecast)"); continue; } // TODO : complete process Dictionary <DateTime, FreezingProbability> averageFreezePrediction12h = freezeService.CalculAverageFreezePrediction12h(freeze.FreezingProbabilityList); log.Info($"Create alarms"); alarmService.CreateFreezeAlarm(item.Key.Id, item.Key.SiteId, averageFreezePrediction12h); log.Info($"Insert Freeze in Db"); freezeService.CreateFreezeAndThawByDevice(item.Key.Id, averageFreezePrediction12h); } notificationService.SendNotifications(alarms); log.Info($"Notifications sent at: {DateTime.Now}"); } catch (AlgorithmeException) { throw; } catch (Exception e) { log.Error(e.Message, e); throw; } } }
protected void dataList_ItemCommand(object source, RepeaterCommandEventArgs e) { try { decimal applyFormId = e.CommandArgument.ToString().ToDecimal(); FreezeService.UnFreeze(applyFormId); ShowMessage("解冻成功!"); var pagination = new Pagination { PageSize = pager.PageSize, PageIndex = pager.CurrentPageIndex, GetRowCount = true }; queryRecords(pagination); } catch (Exception ex) { ShowExceptionMessage(ex, "解冻账户"); } }
public void TestCreateFreezeAndThawByDevice() { //GIVEN string deviceId = "1"; DateTime date = new DateTime(2018, 02, 13, 0, 0, 0); DateTime date2 = date.AddHours(12); Dictionary <DateTime, FreezeForecast.FreezingProbability> dicoPredictionBy12h = new Dictionary <DateTime, FreezeForecast.FreezingProbability> { { date, FreezeForecast.FreezingProbability.IMMINENT }, { date2, FreezeForecast.FreezingProbability.ZERO } }; Mock <IFreezeRepository> freezeRepo = new Mock <IFreezeRepository>(); //WHEN FreezeService service = new FreezeService(freezeRepo.Object); service.CreateFreezeAndThawByDevice(deviceId, dicoPredictionBy12h); //THEN freezeRepo.Verify(o => o.AddOrUpdateFreeze("1", date, 4), Times.Once); freezeRepo.Verify(o => o.AddOrUpdateFreeze("1", date2, 0), Times.Once); }
protected override void ProcessProduct(int productId, Dictionary <string, string> actionParameters) { string[] channels = actionParameters.GetChannels(); bool localize = actionParameters.GetLocalize(); string ignoredStatus = (actionParameters.ContainsKey("IgnoredStatus")) ? actionParameters["IgnoredStatus"] : null; var ignoredStatuses = ignoredStatus?.Split(',') ?? Enumerable.Empty <string>().ToArray(); var product = DoWithLogging( () => Productservice.GetProductById(productId), "Getting product {id}", productId ); if (product == null) { throw new ProductException(productId, nameof(TaskStrings.ProductsNotFound)); } ProductIds.Add(product.Id); if (ignoredStatuses.Contains(product.Status)) { throw new ProductException(product.Id, nameof(TaskStrings.ProductsExcludedByStatus)); } if (!ArticleFilter.DefaultFilter.Matches(product)) { throw new ProductException(product.Id, nameof(TaskStrings.ProductsNotToPublish)); } var state = DoWithLogging( () => FreezeService.GetFreezeState(productId), "Getting freezing state for product {id}", productId ); if (state == FreezeState.Frozen) { throw new ProductException(product.Id, nameof(TaskStrings.ProductsFreezed)); } var xamlValidationErrors = DoWithLogging( () => ArticleService.XamlValidationById(product.Id, true), "Validating XAML for product {id}", productId ); var validationResult = ActionTaskResult.FromRulesException(xamlValidationErrors, product.Id); if (!validationResult.IsSuccess) { ValidationErrors.TryAdd(product.Id, validationResult.ToString()); throw new ProductException(product.Id, JsonConvert.SerializeObject(validationResult)); } var allArticles = DoWithLogging( () => GetAllArticles(new[] { product }).ToArray(), "Getting all articles for product {id}", productId ); bool containsIgnored = allArticles.Any(a => ignoredStatuses.Contains(a.Status)); var articleIds = allArticles .Where(a => a.Id != productId && !a.IsPublished && !ignoredStatuses.Contains(a.Status)) .Select(a => a.Id) .Distinct() .ToArray(); var result = DoWithLogging( () => ArticleService.Publish(product.ContentId, new[] { productId }), "Publishing product {id}", productId ); ValidateMessageResult(productId, result); if (articleIds.Any()) { DoWithLogging( () => ArticleService.SimplePublish(articleIds), "Publishing articles {ids} for product {id}", articleIds, productId ); } if (state == FreezeState.Unfrosen) { DoWithLogging( () => FreezeService.ResetFreezing(product.Id), "Reset freezing for product {id}", productId ); } const string doNotSendNotificationsKey = "DoNotSendNotifications"; bool doNotSendNotifications = actionParameters.ContainsKey(doNotSendNotificationsKey) && bool.Parse(actionParameters[doNotSendNotificationsKey]); if (!doNotSendNotifications) { SendNotification(product, UserName, UserId, containsIgnored, localize, channels); } }
public SitesController(SiteService siteService, FreezeService freezeService) { this.siteService = siteService; this.freezeService = freezeService; }