private void LbEditBtn_Click(object sender, RoutedEventArgs e) { //a button on list view has been clicked Button button = sender as Button; //walk up the tree to find the ListboxItem DependencyObject tvi = Helpers.ListUtility.FindParentTreeItem(button, typeof(ListBoxItem)); //if not null cast the Dependancy object to type of Listbox item. if (tvi != null) { ListBoxItem lbi = tvi as ListBoxItem; IDashboardTimeSeriesPoint timeSeriesPoint = (IDashboardTimeSeriesPoint)lbi.DataContext; // Open edit window for this point if (timeSeriesPoint is DashboardScadaTimeSeriesPoint scadaTimeSeriesPoint) { ScadaTimeSeriesPointEditWindow scadaTimeSeriesPointEditWindow = new ScadaTimeSeriesPointEditWindow(new DashboardScadaTimeSeriesPoint(scadaTimeSeriesPoint)); scadaTimeSeriesPointEditWindow.ShowDialog(); if (scadaTimeSeriesPointEditWindow.DialogResult == true) { // update the point int pointIndex = dataPointsVM.dashboardTimeSeriesPoints.IndexOf(timeSeriesPoint); if (pointIndex >= 0) { dataPointsVM.dashboardTimeSeriesPoints[pointIndex] = scadaTimeSeriesPointEditWindow.scadaTimeSeriesPointVM.ScadaTimeSeriesPoint; ICollectionView view = CollectionViewSource.GetDefaultView(dataPointsVM.dashboardTimeSeriesPoints); view.Refresh(); } } } } }
// Implementing interface public List <IPointResult> FetchHistoricalPointData(IDashboardTimeSeriesPoint dashboardTimeSeriesPoint) { if (dashboardTimeSeriesPoint.GetType().FullName == typeof(DashboardScadaTimeSeriesPoint).FullName) { List <ScadaPointResult> scadaPointResults = FetchHistoricalPointData((DashboardScadaTimeSeriesPoint)dashboardTimeSeriesPoint); List <IPointResult> pointResults = new List <IPointResult>(); for (int i = 0; i < scadaPointResults.Count; i++) { pointResults.Add(scadaPointResults.ElementAt(i)); } return(pointResults); } return(null); }
private void LbDeleteBtn_Click(object sender, RoutedEventArgs e) { if (MessageBox.Show("Remove Data Point ?", "Cell Data Points Configuration", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { //do no stuff return; } else { //a button on list view has been clicked Button button = sender as Button; //walk up the tree to find the ListboxItem DependencyObject tvi = Helpers.ListUtility.FindParentTreeItem(button, typeof(ListBoxItem)); //if not null cast the Dependancy object to type of Listbox item. if (tvi != null) { ListBoxItem lbi = tvi as ListBoxItem; // Delete the object from Observable Collection IDashboardTimeSeriesPoint timeSeriesPoint = (IDashboardTimeSeriesPoint)lbi.DataContext; dataPointsVM.dashboardTimeSeriesPoints.Remove(timeSeriesPoint); } } }
public async Task FetchAndPlotData() { // stop running fetch tasks if (cts != null) { //cts.Cancel(); return; } // ***Instantiate the CancellationTokenSource. cts = new CancellationTokenSource(); // clear the current series of the plot SeriesCollection.Clear(); // get each point data and bind it to the Series Collection // iterate through each timeseries point in the config for (int i = 0; i < LinePlotCellConfig_.TimeSeriesPoints_.Count; i++) { IDashboardTimeSeriesPoint pnt = LinePlotCellConfig_.TimeSeriesPoints_.ElementAt(i); if (pnt.GetType().FullName == typeof(DashboardScadaTimeSeriesPoint).FullName) { // handle if the point is a scada point ScadaFetcher scadaFetcher = new ScadaFetcher(); DashboardScadaTimeSeriesPoint scadaTimeseriesPnt = (DashboardScadaTimeSeriesPoint)pnt; // fetch the results from the data fetcher List <ScadaPointResult> results = new List <ScadaPointResult>(); try { // ***Send a token to carry the message if cancellation is requested. results = await scadaFetcher.FetchHistoricalPointDataAsync(scadaTimeseriesPnt, cts.Token); } // *** If cancellation is requested, an OperationCanceledException results. catch (OperationCanceledException) { AddLinesToConsole("Existing Fetch task cancelled"); } catch (Exception e) { AddLinesToConsole($"Error in running fetch task: {e.Message}"); } if (results == null) { // handle the null results by printing in the console AddLinesToConsole("No values returned after fetching"); results = new List <ScadaPointResult>(); } // Get Plot Values from ScadaResults List <double> plotVals = new List <double>(); for (int resCounter = 0; resCounter < results.Count; resCounter++) { ScadaPointResult res = results[resCounter]; plotVals.Add(res.Val_); } // change the plot values spacing in secs and the starting dateTime if (i == 0) { MeasPeriodSecs_ = scadaTimeseriesPnt.FetchPeriodSecs_; if (plotVals.Count > 0) { StartDateTime_ = new DateTime(results[0].ResultTime_.Ticks); } } // getting the required color string colorString = scadaTimeseriesPnt.ColorString_; if (colorString == null) { colorString = "NULL"; } SolidColorBrush requiredColorBrush; try { requiredColorBrush = new SolidColorBrush((Color)ColorConverter.ConvertFromString(colorString)); } catch (Exception ex) { requiredColorBrush = null; //AddLinesToConsole($"Unable to parse the color string \"{colorString}\""); } // Add the Data Point fetch results to the Plot lines Collection SeriesCollection.Add(new GLineSeries() { Title = scadaTimeseriesPnt.ScadaPoint_.Name_, Values = new GearedValues <double>(plotVals), PointGeometry = null, Fill = Brushes.Transparent, StrokeThickness = scadaTimeseriesPnt.StrokeThickness_, LineSmoothness = 0, Stroke = requiredColorBrush }); // https://stackoverflow.com/questions/2109756/how-do-i-get-the-color-from-a-hexadecimal-color-code-using-net } } // ***Set the CancellationTokenSource to null when the download is complete. cts = null; }