protected void UpdateParentByChild(IBulbCacheReadObject childBulb) { if (childBulb == null) { return; } var parentId = childBulb.GetParentId(); if (parentId == null) { return; } var parentRequest = new AccountCacheRequest() { AccountId = childBulb.AccountId, ObjectId = parentId.Value }; IBulbCacheReadObject rParent = null; using (var parent = AllCaches.StatusDatas.Write(parentRequest)) { // менять выключенного родителя нельзя, его надо сначала включить if (parent.Status == MonitoringStatus.Disabled) { return; } var processDate = DateTime.Now; BulbSignal signal = null; if (childBulb.Status > parent.Status) { // 1. если дочерний опаснее signal = BulbSignal.CreateFromChild(processDate, childBulb); rParent = ProlongOrChangeStatus(signal, parent.Id); } else { // 2. если дочерний менее опасный и он был последней причиной if (childBulb.Status < parent.Status && parent.LastChildBulbId == childBulb.Id) { // нужно расчитать занова CalculateByChilds(parent); } } } if (rParent != null) { UpdateParentByChild(rParent); } }
public void CalculateByChilds(Guid accountId, Guid statusId, List <Guid> childs) { var processDate = DateTime.Now; var request = new AccountCacheRequest() { AccountId = accountId, ObjectId = statusId }; IBulbCacheReadObject rBulb = null; using (var statusData = AllCaches.StatusDatas.Write(request)) { var childsList = new List <IBulbCacheReadObject>(); foreach (var childId in childs) { var childRequest = new AccountCacheRequest() { AccountId = accountId, ObjectId = childId }; var child = AllCaches.StatusDatas.Find(childRequest); // Disabled и Unknown не влияют на родителей if (child != null && child.Status != MonitoringStatus.Disabled && child.Status != MonitoringStatus.Unknown) { childsList.Add(child); } } var mostDandger = childsList.OrderByDescending(x => x.Status).FirstOrDefault(); if (mostDandger == null) { var signal = BulbSignal.CreateUnknown(accountId, processDate); rBulb = ProlongOrChangeStatus(signal, statusId); } else { var signal = BulbSignal.CreateFromChild(processDate, mostDandger); rBulb = ProlongOrChangeStatus(signal, statusId); } } UpdateParentByChild(rBulb); }