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); } }