public bool StopOutageSimulation(long outageElementId) { //TODO: END TASK HERE if (!outageTokenMap.ContainsKey(outageElementId)) { return(false); } outageTokenMap[outageElementId].Cancel(); outageTokenMap.Remove(outageElementId); if (!activeOutagesMap.ContainsKey(outageElementId)) { return(false); } ActiveOutageBindingModel outage = activeOutagesMap[outageElementId]; ActiveOutages.Remove(outage); activeOutagesMap.Remove(outageElementId); OnPropertyChanged("IsSelectedOutageGridVisible"); OnPropertyChanged("OutageElement"); OnPropertyChanged("OptimumIsolationPoints"); OnPropertyChanged("DefaultIsolationPoints"); return(true); }
private async Task EndOutage() { var outageElementId = SelectedOutage.OutageElement.GID; var outageSimulatorUIClient = OutageSimulatorUIClient.CreateClient(); if (await outageSimulatorUIClient.EndOutage(outageElementId)) { if (!activeOutagesMap.ContainsKey(outageElementId)) { return; } ActiveOutageBindingModel outage = activeOutagesMap[outageElementId]; ActiveOutages.Remove(outage); activeOutagesMap.Remove(outageElementId); OnPropertyChanged("ActiveOutages"); OnPropertyChanged("SelectedOutage"); OnPropertyChanged("IsSelectedOutageGridVisible"); OnPropertyChanged("OutageElement"); OnPropertyChanged("OptimumIsolationPoints"); OnPropertyChanged("DefaultIsolationPoints"); } }
public void GenerateOutage(ActiveOutageBindingModel outage) { CancellationTokenSource tokenSource = new CancellationTokenSource(); CancellationToken token = tokenSource.Token; Task task = Task.Run(() => { token.ThrowIfCancellationRequested(); ScadaNotification scadaCallback = new ScadaNotification("OUTAGE_SIMULATOR", outage); SubscriberProxy scadaSubscriber = proxyFactory.CreateProxy <SubscriberProxy, ISubscriber>(scadaCallback, EndpointNames.SubscriberEndpoint); if (scadaSubscriber == null) { string message = "GenerateOutage task => SubscriberProxy is null"; Logger.LogError(message); return; } scadaSubscriber.Subscribe(Topic.SWITCH_STATUS); bool toContinue = !token.IsCancellationRequested; while (toContinue) { //TODO: OUTAGE LOGIC if (token.IsCancellationRequested) { // Clean up here scadaSubscriber.Close(); toContinue = false; //token.ThrowIfCancellationRequested(); } } }, token); outageTokenMap.Add(outage.OutageElement.GID, tokenSource); ActiveOutages.Add(outage); activeOutagesMap.Add(outage.OutageElement.GID, outage); Dispatcher.BeginInvoke((Action)(() => parent.TabControl.SelectedIndex = 0)); }
public void SetOutages(IEnumerable <SimulatedOutage> simulatedOutages) { activeOutagesMap.Clear(); //Dispatcher.Invoke(new Action(() => ActiveOutages.Clear())); ActiveOutages.Clear(); foreach (var simulatedOutage in simulatedOutages) { var outage = new ActiveOutageBindingModel() { OutageElement = new GlobalIDBindingModel(simulatedOutage.OutageElementGid), OptimumIsolationPoints = new ObservableCollection <GlobalIDBindingModel>(simulatedOutage.OptimumIsolationPointGids.Select(gid => new GlobalIDBindingModel(gid))), DefaultIsolationPoints = new ObservableCollection <GlobalIDBindingModel>(simulatedOutage.DefaultIsolationPointGids.Select(gid => new GlobalIDBindingModel(gid))), DefaultToOptimumIsolationPointMap = new Dictionary <long, long>(simulatedOutage.DefaultToOptimumIsolationPointMap), }; //Dispatcher.Invoke(new Action(() => ActiveOutages.Add(outage))); ActiveOutages.Add(outage); activeOutagesMap.Add(simulatedOutage.OutageElementGid, outage); } }