//constructor public SingleConfigViewModel(SessionColumnCollection columnCollection, DataTable data) { ColumnCollection = columnCollection; DownloadedData.Add(data); DataSetStartDate = ColumnCollection.DataSetStart; DataSetEndDate = ColumnCollection.DataSetEnd; }
void LoadFile() { string filename = Utils.GetFile(); if (filename.Length < 1) { return; } FileIsLoading = true; try { worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; DataRepository repository = new DataRepository(filename, DataSourceType.CSV); repository.FileOpening += new DataRepository.FileProgressEventHandler(repository_UpdateProgress); repository.FileLoading += new DataRepository.FileProgressEventHandler(repository_UpdateProgress); repository.FileLoaded += new DataRepository.FileProgressEventHandler(repository_UpdateProgress); worker.DoWork += delegate(object sender, DoWorkEventArgs args) { data = repository.GetAllData(); //reset composite flags since we're loading a new dataset // WDCompositeExists = false; //WSCompositeExists = false; ColumnCollection = new SessionColumnCollection(data); ObservableCollection <ISessionColumn> colClxn = new MultiThreadObservableCollection <ISessionColumn>(); foreach (SessionColumn sc in _sessionColumnCollection.Columns) { colClxn.Add(sc); } LiveCollection = colClxn; DataSetStartDate = ColumnCollection.DataSetStart; DataSetEndDate = ColumnCollection.DataSetEnd; FileIsLoading = false; }; worker.RunWorkerAsync(); } catch (Exception e) { MessageBox.Show(e.Message); } }
public SingleConfigViewModel(SessionColumnCollection columnCollection) { ColumnCollection = columnCollection; DataSetStartDate = ColumnCollection.DataSetStart; DataSetEndDate = ColumnCollection.DataSetEnd; }
void LoadFile() { string filename = Utils.GetFile(); if (filename.Length < 1) { return; } FileIsLoading = true; try { worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; DataRepository repository = new DataRepository(filename, DataSourceType.CSV); repository.FileOpening += new DataRepository.FileProgressEventHandler(repository_UpdateProgress); repository.FileLoading += new DataRepository.FileProgressEventHandler(repository_UpdateProgress); repository.FileLoaded += new DataRepository.FileProgressEventHandler(repository_UpdateProgress); worker.DoWork += delegate(object sender, DoWorkEventArgs args) { DataTable data = repository.GetAllData(); SessionColumnCollection collection = new SessionColumnCollection(data); if (!sessionCollections.Contains(collection)) { sessionCollections.Add(collection); } //need a better way to convert this collection to multithreaded oibservable ObservableCollection <ISessionColumn> colClxn = new MultiThreadObservableCollection <ISessionColumn>(); foreach (SessionColumn sc in collection.Columns) { colClxn.Add(sc); } collection.Columns = colClxn; if (MainWorkSpace != null) { this.Dispatcher.Invoke(DispatcherPriority.DataBind, new Action ( delegate() { MainWorkSpace = new ProcessingViewModel(sessionCollections); })); } FileIsLoading = false; }; worker.RunWorkerAsync(); } catch (Exception e) { throw e; } }
void OutPutSummary() { BackgroundWorker worker = new BackgroundWorker(); string filename = string.Empty; SaveFileDialog sf = new SaveFileDialog(); sf.Title = "save data"; sf.Filter = "Excel|*.xlsx"; sf.DefaultExt = ".xlsx"; sf.FileName = "Unified" + "_StnSummary_" + DateTime.Now.ToShortDateString().Replace(@"/", ""); DialogResult result = sf.ShowDialog(); if (result == DialogResult.Cancel) { return; } if (sf.FileName != "") { filename = sf.FileName; } else { return; } worker.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e) { SummaryIsProcessing = false; }; worker.DoWork += delegate(object s, DoWorkEventArgs args) { XbyYShearStationSummary summary = null; try { SummaryIsProcessing = true; //create the DataTable if (_unifiedData != null) { _unifiedData.Clear(); } BuildDataTable(); //create column collection ColumnCollection = new SessionColumnCollection(_unifiedData); //add column def and add configs ISessionColumn hubws = ColumnCollection[HubHeight.ToString() + "m"]; hubws.ColumnType = SessionColumnType.WSAvgShear; hubws.IsCalculated = true; hubws.IsComposite = true; SensorConfig config = new SensorConfig() { StartDate = _startDate, EndDate = _endDate, Height = HubHeight }; hubws.Configs.Add(config); ISessionColumn upperws = ColumnCollection[UpperHeight.ToString().Replace(".", "_") + "m"]; upperws.ColumnType = SessionColumnType.WSAvg; upperws.IsComposite = true; config = new SensorConfig() { StartDate = _startDate, EndDate = _endDate, Height = UpperHeight }; upperws.Configs.Add(config); ISessionColumn lowerws = ColumnCollection[LowerHeight.ToString().Replace(".", "_") + "m"]; lowerws.ColumnType = SessionColumnType.WSAvg; lowerws.IsComposite = true; config = new SensorConfig() { StartDate = _startDate, EndDate = _endDate, Height = LowerHeight }; lowerws.Configs.Add(config); ISessionColumn wd = ColumnCollection["WD"]; wd.ColumnType = SessionColumnType.WDAvg; wd.IsComposite = true; config = new SensorConfig() { StartDate = _startDate, EndDate = _endDate }; wd.Configs.Add(config); //get axis selections from UI IAxis Xaxis = GetAxis(_xShearAxis, _xBinWidth); IAxis Yaxis = GetAxis(_yShearAxis, _yBinWidth); //calculate alpha AlphaFactory afactory = new AlphaFactory(); Alpha alpha = (Alpha)afactory.CreateAlpha(_unifiedData, AlphaFilterMethod.Coincident, upperws, lowerws, Xaxis, Yaxis); alpha.SourceDataSet = this.DisplayName; alpha.CalculateAlpha(); string xBin = string.Empty; string yBin = string.Empty; if (Xaxis.AxisType == AxisType.WD) { var wdaxis = (WindDirectionAxis)Xaxis; xBin = " " + wdaxis.BinWidth.ToString() + " deg"; } if (Xaxis.AxisType == AxisType.WS) { var wsaxis = (WindSpeedAxis)Xaxis; xBin = " " + wsaxis.BinWidth.ToString() + " m/s"; } if (Yaxis.AxisType == AxisType.WD) { var wdaxis = (WindDirectionAxis)Yaxis; yBin = " " + wdaxis.BinWidth.ToString() + " deg"; } if (Yaxis.AxisType == AxisType.WS) { var wsaxis = (WindSpeedAxis)Yaxis; yBin = " " + wsaxis.BinWidth.ToString() + " m/s"; } //Set up column metadata for the summary run summary = new XbyYShearStationSummary(ColumnCollection, _unifiedData.AsDataView(), 30, 10, 2, alpha); summary.CreateReport(filename); SummaryIsProcessing = false; } catch (ApplicationException e) { MessageBox.Show("Error calculating station summary: " + e.Message + " " + e.Source); StreamWriter fs = new StreamWriter(Path.GetDirectoryName(filename) + @"\LOG_" + Path.GetFileNameWithoutExtension(filename) + ".txt", false); summary.log.ForEach(c => fs.WriteLine(c)); fs.Close(); } finally { SummaryIsProcessing = false; } }; worker.RunWorkerAsync(); }