protected IBulbCacheReadObject UpdateEnableOrDisableStatusData(IMetricCacheReadObject metric) { var statusService = Context.BulbService; IBulbCacheReadObject data = null; var processDate = DateTime.Now; if (metric.CanProcess) { var unknownSignal = BulbSignal.CreateUnknown(metric.AccountId, processDate); data = statusService.SetSignal(metric.StatusDataId, unknownSignal); } else { var disableSignal = BulbSignal.CreateDisable(metric.AccountId, processDate); data = statusService.SetSignal(metric.StatusDataId, disableSignal); } //Context.ComponentService.CalculateAllStatuses(metric.AccountId, metric.ComponentId); return(data); }
protected IComponentCacheReadObject RecalculateComponentStatuses(IComponentCacheReadObject component) { var accountId = component.AccountId; var cache = new AccountCache(accountId); IComponentCacheReadObject result = component; // обновим ParentEnable if (component.ParentId.HasValue) { var parent = cache.Components.Read(component.ParentId.Value); if (parent.CanProcess != component.ParentEnable) { using (var componentWrite = cache.Components.Write(component)) { componentWrite.ParentEnable = parent.CanProcess; componentWrite.BeginSave(); component = componentWrite; } UpdateParentEnableFlags(component, true); } } // если время выключения истекло, то включим компонент if (component.Enable == false && component.DisableToDate.HasValue && component.DisableToDate < DateTime.Now) { using (var componentWrite = cache.Components.Write(component)) { componentWrite.Enable = true; componentWrite.BeginSave(); component = componentWrite; result = component; } UpdateParentEnableFlags(component, true); } var statusService = Context.BulbService; var allStatusesIds = component.GetAllStatusesIds(); var allStatuses = allStatusesIds.Select(cache.StatusDatas.Read).ToList(); // если надо выключить if (component.CanProcess == false && allStatuses.Any(x => x.Status != Api.MonitoringStatus.Disabled)) { // выключим все колбаски // выжно выключить их в этом порядке, чтобы не создать лишних событий колбасок-родителей var disableSignal = BulbSignal.CreateDisable(accountId, DateTime.Now); statusService.SetSignal(component.ExternalStatusId, disableSignal); statusService.SetSignal(component.ChildComponentsStatusId, disableSignal); statusService.SetSignal(component.InternalStatusId, disableSignal); statusService.SetSignal(component.EventsStatusId, disableSignal); statusService.SetSignal(component.UnitTestsStatusId, disableSignal); statusService.SetSignal(component.MetricsStatusId, disableSignal); } // обновим тесты var allUnitTestsStatusDataIds = new List <Guid>(); foreach (var unitTestRef in component.UnitTests.GetAll()) { using (var unitTest = cache.UnitTests.Write(unitTestRef.Id)) { if (unitTest.IsDeleted) { continue; } allUnitTestsStatusDataIds.Add(unitTest.StatusDataId); if (unitTest.ParentEnable != component.CanProcess) { unitTest.ParentEnable = component.CanProcess; unitTest.BeginSave(); } } Context.UnitTestService.GetUnitTestResult(component.AccountId, unitTestRef.Id); } // обновим метрики var allMetricsStatusDataIds = new List <Guid>(); Guid metricTypeId; foreach (var metricRef in component.Metrics.GetAll()) { using (var metric = cache.Metrics.Write(metricRef.Id)) { if (metric.IsDeleted) { continue; } metricTypeId = metric.MetricTypeId; allMetricsStatusDataIds.Add(metric.StatusDataId); if (metric.ParentEnable != component.CanProcess) { metric.ParentEnable = component.CanProcess; metric.BeginSave(); } } Context.MetricService.GetActualMetric(component.AccountId, component.Id, metricTypeId); } // проверим, нужно ли обновить детей var childComponentsStatusDataIds = new List <Guid>(); foreach (var childRef in component.Childs.GetAll()) { using (var child = cache.Components.Write(childRef.Id)) { if (child.IsDeleted) { continue; } childComponentsStatusDataIds.Add(child.ExternalStatusId); if (child.ParentEnable != component.CanProcess) { child.ParentEnable = component.CanProcess; child.BeginSave(); } } GetComponentExternalState(component.AccountId, childRef.Id); } if (component.CanProcess) { // обновим колбасу тестов явно (вдруг нет ни одного теста) statusService.CalculateByChilds(accountId, component.UnitTestsStatusId, allUnitTestsStatusDataIds); // обновим колбасу метрик явно (вдруг нет ни одной метрики) statusService.CalculateByChilds(accountId, component.MetricsStatusId, allMetricsStatusDataIds); // обновим колбасу событий CalculateComponentEventsStatus(accountId, component.EventsStatusId); // обновим внутренний статус var childsForInternal = new List <Guid>() { component.EventsStatusId, component.UnitTestsStatusId, component.MetricsStatusId }; statusService.CalculateByChilds(accountId, component.InternalStatusId, childsForInternal); // обновим колбасу дочерних statusService.CalculateByChilds(accountId, component.ChildComponentsStatusId, childComponentsStatusDataIds); // обновим внешний статус var childsForExternal = new List <Guid>() { component.InternalStatusId, component.ChildComponentsStatusId }; statusService.CalculateByChilds(accountId, component.ExternalStatusId, childsForExternal); } return(result); }