protected void OnScvEventActivity(Object sender, ActivityOnLanArgs data) { EventThread.Enqueue("OnScvEventActivity", () => { //var controlDep = DepManager.Where(d => d.Key == data.ScvId).Select(d => d.Value).ToList(); var ctrldep = DepManagers.Where(d => d.Cfg.Id == data.ScvId).FirstOrDefault(); if (ctrldep != null) { if (ctrldep.Activity != data.ActivityOnLan) { /** Actualiza el estado de la dependencia y Genera el Historico */ ctrldep.Activity = data.ActivityOnLan; History.Add(HistoryItems.DepActivityEvent, "", ctrldep.Cfg.Id, data.ActivityOnLan ? "ON" : "OFF"); /** Actualiza el Tx del SCV */ var oldEnableTx = MainManager.Manager.TxEnabled; var actives = DepManagers.Where(d => d.Activity == true).ToList(); MainManager.Manager.TxEnabled = Cfg.General.ActivateSactaLogic == "OR" ? actives.Count() > 0 : Cfg.General.ActivateSactaLogic == "AND" ? actives.Count() == DepManagers.Count() : actives.Count() == DepManagers.Count(); /** Se genera el historico si corresponde */ if (oldEnableTx != MainManager.Manager.TxEnabled) { History.Add(HistoryItems.DepTxstateChange, "", MainManager.Cfg.Id, MainManager.Manager.TxEnabled ? "ON" : "OFF"); } } } else { // Algo no va bien. Logger.Fatal <SactaProxy>($"OnScvEventActivity. {data.ScvId} Dependency is missing or duplicated"); } }); }
protected void OnScvEventSectorization(Object sender, SectorizationReceivedArgs data) { /** Se ha recibido una sectorizacion correcta de una dependencia */ EventThread.Enqueue("OnScvEventSectorization", () => { var ctrldep = DepManagers.Where(d => d.Cfg.Id == data.ScvId).FirstOrDefault(); if (ctrldep != null) { if (data.Accepted) { // Actualizo la Sectorizacion en la Dependencia. ctrldep.MapOfSectors = data.SectorMap; // Mapeo la sectorizacion recibida. var MapOfSectorsMapped = ctrldep.Map(data.SectorMap); // Actualizo la Sectorizacion en el Manager. MainManager.MergeSectorization(MapOfSectorsMapped); // Historico. History.Add(HistoryItems.DepSectorizationReceivedEvent, "", ctrldep.Cfg.Id, "", SectorizationHelper.MapToString(data.SectorMap)); // Propagar la Sectorizacion al SCV real si todas las dependencias han recibido sectorizacion. var DepWithSectInfo = DepManagers.Where(d => d.MapOfSectors.Count > 0).ToList(); if (DepWithSectInfo.Count == DepManagers.Count) { (MainManager.Manager as PsiManager).SendSectorization(MainManager.MapOfSectors); // Historico History.Add(HistoryItems.ScvSectorizationSendedEvent, "", MainManager.Cfg.Id, "", SectorizationHelper.MapToString(MainManager.MapOfSectors), $"Recibida de SACTA ({data.ScvId})"); data.Acknowledge(true); } else { //Logger.Warn<SactaProxy>($"OnScvEventSectorization. IGNORED. No all Sectorization Info Present."); History.Add(HistoryItems.DepSectorizationRejectedEvent, "", ctrldep.Cfg.Id, "", SectorizationHelper.MapToString(data.SectorMap), "No todas las dependencias tienen sectorizaciones válidas."); data.Acknowledge(false); } } else { // Evento de Sectorizacion Rechazada. Historico History.Add(HistoryItems.DepSectorizationRejectedEvent, "", ctrldep.Cfg.Id, "", data.ReceivedMap, data.RejectCause); data.Acknowledge(false); } } else { Logger.Fatal <SactaProxy>($"OnScvEventSectorization. {data.ScvId} Dependency is missing or duplicated"); } }); }
protected void OnPsiEventSectorizationAsk(Object sender, SectorizationRequestArgs data) { EventThread.Enqueue("OnPsiEventActivity", () => { //var DepWithSectInfo = DepManager.Where(d => d.Value.MapOfSectors.Count() > 0).ToList(); var DepWithSectInfo = DepManagers.Where(d => d.MapOfSectors.Count > 0).ToList(); if (DepWithSectInfo.Count == DepManagers.Count) { (MainManager.Manager as PsiManager).SendSectorization(MainManager.MapOfSectors); /** Historico */ History.Add(HistoryItems.ScvSectorizationSendedEvent, "", MainManager.Cfg.Id, "", SectorizationHelper.MapToString(MainManager.MapOfSectors), $"Peticion SCV"); } else { Logger.Warn <SactaProxy>($"OnPsiEventSectorizationAsk. IGNORED. No all Sectorization Info Present."); } }); }