public void LoadData()
        {
            if (Data != null)
            {
                Data.Release();
            }
            if (IterativeRoot != null)
            {
                AlreadyLoaded = Regenerate | (IterativeRoot.CurrentIteration > 0);
            }

            var cache = GetFullPath(AlreadyLoaded ? UpdatedODC : ODC);

            if ((Regenerate && AlreadyLoaded) || !File.Exists(cache))
            {
                Generate();
            }
            Data = new OdCache(cache, UseCache);
            if (!UseCache)
            {
                var loadedData = Data.StoreAll();
                Data.Release();
                StoredData = ProcessLoadedData(loadedData, Data.Times, Data.Types);
                Data       = null;
            }
            AlreadyLoaded = true;
        }
        public void LoadData()
        {
            if (IterativeRoot != null)
            {
                AlreadyLoaded = RebuildDataOnSuccessiveLoads | IterativeRoot.CurrentIteration > 0;
            }

            var cacheFile = GetFullPath(AlreadyLoaded ? UpdatedODC : ODC);

            if ((AlreadyLoaded & RebuildDataOnSuccessiveLoads) || !File.Exists(cacheFile))
            {
                Generate(cacheFile);
            }
            Data = new OdCache(cacheFile);
            var loadedData = Data.StoreAll();

            StoredData = ProcessLoadedData(loadedData, Data.Types, Data.Times);
            Data.Release();
            Data          = null;
            AlreadyLoaded = true;
        }
Esempio n. 3
0
        private void ValidateData(int[] zones, float[][][] data, string odcFileName)
        {
            if (zones == null)
            {
                throw new ArgumentNullException(nameof(zones));
            }
            if (data == null)
            {
                throw new ArgumentNullException(nameof(data));
            }
            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 (data[i] == null)
                {
                    Assert.Fail("No data provided for data[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 (data[i][j] == null)
                    {
                        Assert.Fail("No data provided for data[i][j]");
                    }
                    if ((storedData[i][j] == null) != (data[i][j] == null))
                    {
                        Assert.Fail("The data differs at zone " + zones[i] + " in zone " + zones[j]);
                    }
                    if (storedData[i][j] != null)
                    {
                        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], 5) != Math.Round(data[i][j][k], 5))
                                {
                                    Assert.Fail("The data differs at index " + i + ":" + j + ":" + k + " (" +
                                                storedData[i][j][k] + " / " + data[i][j][k] + ")");
                                }
                            }
                        }
                    }
                }
            }
        }
Esempio n. 4
0
        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":
                {
                    OdControlGrid.IsEnabled = false;
                    Task t = new Task(delegate
                        {
                            PresentationGrid.DataContext = null;
                            try
                            {
                                var odc = new OdCache(fileName);
                                odc.Release();
                            }
                            catch
                            {
                                MessageBox.Show(this, "Unable to load the file", "Invalid Format", MessageBoxButton.OK, MessageBoxImage.Error);
                            }
                        });
                    t.Start();
                }
                break;

                case ".odc":
                {
                    OdControlGrid.IsEnabled = true;
                    Task t = new Task(delegate
                        {
                            try
                            {
                                var odc     = new OdCache(fileName);
                                var allData = odc.StoreAll().GetFlatData();
                                Dispatcher.BeginInvoke(
                                    new Action(delegate
                                {
                                    try
                                    {
                                        PresentationGrid.Items.Clear();
                                        for (int i = 0; i < 1; i++)
                                        {
                                            for (int j = 0; j < 1; j++)
                                            {
                                                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;
                }
            }
        }