public void LoadData() { if ( this.IterativeRoot != null ) { this.AlreadyLoaded = this.IterativeRoot.CurrentIteration > 0; } var cacheFile = GetFullPath( this.AlreadyLoaded ? this.UpdatedODC : this.ODC ); if ( ( this.AlreadyLoaded & this.RebuildDataOnSuccessiveLoads ) || !File.Exists( cacheFile ) ) { Generate( cacheFile ); } Data = new ODCache( cacheFile ); var loadedData = Data.StoreAll(); this.StoredData = ProcessLoadedData( loadedData, Data.Types, Data.Times ); Data.Release(); Data = null; this.AlreadyLoaded = true; }
public void LoadData() { if ( Data == null ) { var cacheFile = GetFullPath( this.ODC ); if ( ( this.AlreadyLoaded & this.RebuildDataOnSuccessiveLoads ) || !File.Exists( cacheFile ) ) { // create the data if it doesn't already exist ODMatrixWriter<IZone> creator = new ODMatrixWriter<IZone>( this.Root.ZoneSystem.ZoneArray, 2, 3 ); creator.Year = this.Year; creator.AdditionalDescription = "Automatically Generated"; creator.StartTimesHeader = "6:00,15:30,Other"; creator.EndTimesHeader = "9:00AM,18:30,Other"; creator.TypeHeader = "TravelTime,Cost"; creator.Modes = "Auto"; LoadTimes( creator, this.AMTravelTimeOriginalData, 0 ); LoadTimes( creator, this.PMTravelTimeOriginalData, 1 ); LoadTimes( creator, this.OffpeakTravelTimeOriginalData, 2 ); LoadCosts( creator, this.AMTravelCostOriginalData, 0 ); LoadCosts( creator, this.PMTravelCostOriginalData, 1 ); LoadCosts( creator, this.OffpeakTravelCostOriginalData, 2 ); creator.Save( cacheFile, false ); } Data = new ODCache( cacheFile ); this.StoredData = Data.StoreAll(); } this.AlreadyLoaded = true; }
private void ValidateData(int[] zones, float[][][] data, string odcFileName) { ODCache odc = new ODCache( odcFileName ); var storedData = odc.StoreAll().GetFlatData(); odc.Release(); if ( storedData.Length != data.Length ) { Assert.Fail( "The stored data is not the same size as the given data! " + storedData.Length + " : " + data.Length ); } for ( int i = 0; i < storedData.Length; i++ ) { if ( ( storedData[i] == null ) != ( data[i] == null ) ) { Assert.Fail( "The data differs at zone " + zones[i] ); } if ( storedData[i] == null ) continue; if ( storedData[i].Length != data[i].Length ) { Assert.Fail( "The stored data is not the same size as the given data for zone " + zones[i] + "! " + storedData[i].Length + " : " + data[i].Length ); } for ( int j = 0; j < storedData[i].Length; j++ ) { if ( ( storedData[i][j] == null ) != ( data[i][j] == null ) ) { Assert.Fail( "The data differs at zone " + zones[i] + " in zone " + zones[j] ); } for ( int k = 0; k < storedData[i][j].Length; k++ ) { if ( storedData[i][j][k] != data[i][j][k] ) { if ( Math.Round( storedData[i][j][k], 3 ) != Math.Round( data[i][j][k], 3 ) ) { Assert.Fail( "The data differs at index " + i + ":" + j + ":" + k + " (" + storedData[i][j][k] + " / " + data[i][j][k] + ")" ); } } } } } }
public void LoadData() { if ( Data == null ) { var cacheFile = GetFullPath( this.ODC ); if ( ( this.AlreadyLoaded & this.RebuildDataOnSuccessiveLoads ) || !File.Exists( cacheFile ) ) { // create the data if it doesn't already exist ODMatrixWriter<IZone> creator = new ODMatrixWriter<IZone>( this.Root.ZoneSystem.ZoneArray, 2, 3 ); creator.Year = this.Year; creator.AdditionalDescription = "Automatically Generated"; creator.StartTimesHeader = "Six,FiveThirty,Other"; creator.EndTimesHeader = "Nine,SixThirty,Other"; creator.TypeHeader = "TravelTime,Cost"; creator.Modes = String.IsNullOrWhiteSpace( this.NetworkType ) ? "Auto" : this.NetworkType; creator.LoadEMME2( FailIfNotExist( this.AMTravelTimeOriginalData ), 0, (int)AutoDataTypes.TravelTime ); creator.LoadEMME2( FailIfNotExist( this.AMTravelCostOriginalData ), 0, (int)AutoDataTypes.CarCost ); creator.LoadEMME2( FailIfNotExist( this.PMTravelTimeOriginalData ), 1, (int)AutoDataTypes.TravelTime ); creator.LoadEMME2( FailIfNotExist( this.PMTravelCostOriginalData ), 1, (int)AutoDataTypes.CarCost ); creator.LoadEMME2( FailIfNotExist( this.OffpeakTravelTimeOriginalData ), 2, (int)AutoDataTypes.TravelTime ); creator.LoadEMME2( FailIfNotExist( this.OffpeakTravelCostOriginalData ), 2, (int)AutoDataTypes.CarCost ); creator.Save( cacheFile, false ); } Data = new ODCache( cacheFile ); this.StoredData = Data.StoreAll(); } this.AlreadyLoaded = true; }
private void OpenMenuItem_Click(object sender, RoutedEventArgs e) { var open = new Microsoft.Win32.OpenFileDialog(); open.Filter = "OD Cache (.odc)|*.odc|Zone File Cache (.zfc)|.zfc"; open.FilterIndex = 0; open.CheckPathExists = true; open.CheckFileExists = true; open.AddExtension = true; open.DereferenceLinks = true; if ( open.ShowDialog() == true ) { var fileName = open.FileName; var ext = System.IO.Path.GetExtension( fileName ).ToLowerInvariant(); switch ( ext ) { case ".zfc": { this.ODControlGrid.IsEnabled = false; Task t = new Task( new Action( delegate() { this.PresentationGrid.DataContext = null; try { ODCache odc = new ODCache( fileName ); var allData = odc.StoreAll(); //foreach(var index in odc.Release(); } catch { MessageBox.Show( this, "Unable to load the file", "Invalid Format", MessageBoxButton.OK, MessageBoxImage.Error ); } } ) ); t.Start(); } break; case ".odc": { this.ODControlGrid.IsEnabled = true; Task t = new Task( new Action( delegate() { try { ODCache odc = new ODCache( fileName ); var allData = odc.StoreAll().GetFlatData(); this.Dispatcher.BeginInvoke( new Action( delegate() { try { this.PresentationGrid.Items.Clear(); for ( int i = 0; i < 1; i++ ) { for ( int j = 0; j < 1; j++ ) { this.PresentationGrid.ItemsSource = allData[i][j]; } } } catch { MessageBox.Show( this, "Unable to display the data", "Loading Fail", MessageBoxButton.OK, MessageBoxImage.Error ); } } ) ); odc.Release(); } catch { MessageBox.Show( this, "Unable to load the file", "Invalid Format", MessageBoxButton.OK, MessageBoxImage.Error ); } } ) ); t.Start(); } break; default: MessageBox.Show( this, "Unable to load the extension " + ext + ".", "Invalid Format", MessageBoxButton.OK, MessageBoxImage.Error ); break; } } }