public static void ImportHouseholdDefinition([NotNull] HouseholdDefinitionImporterOptions o, [NotNull] string connectionString)
        {
            var sim = new Simulator(connectionString);

            try {
                var sett = ModularHouseholdSerializer.ImportFromCSV(o.File, sim);
                SimIntegrityChecker.Run(sim);
                var bo = new BatchOptions
                {
                    OutputFileDefault = OutputFileDefault.ReasonableWithCharts,
                    EnergyIntensity   = EnergyIntensityType.EnergySavingPreferMeasured
                };
                var count = 1;
                foreach (var settlement in sett)
                {
                    bo.Suffix         = "CSV" + count++;
                    bo.SettlementName = settlement.Name;
                    BatchfileFromSettlement.MakeBatchfileFromSettlement(sim, bo);
                }
            }
            catch (Exception ex) {
                Logger.Exception(ex);
                if (!Config.CatchErrors)
                {
                    throw;
                }
            }
        }
        public void CSVImportTest2()
        {
            using (var db1 = new DatabaseSetup(Utili.GetCurrentMethodAndClass() + "_export"))
            {
                //export
                using (var wd = SetupDB3(Utili.GetCurrentMethodAndClass()))
                {
                    const string srcfile = @"v:\work\CHR15a_Sc1.csv";
                    File.Copy(srcfile, Path.Combine(wd.WorkingDirectory, "hh.csv"));
                    var sim = new Simulator("Data Source=profilegenerator.db3")
                    {
                        MyGeneralConfig = { CSVCharacter = ";" }
                    };
                    sim.MyGeneralConfig.SaveToDB();
                    var          dbm        = new DatabaseMerger(sim);
                    const string importPath = @"v:\work\profilegenerator_hennings.db3";
                    dbm.RunFindItems(importPath, null);
                    dbm.RunImport(null);
                    ModularHouseholdSerializer.ExportAsCSV(sim.ModularHouseholds[0], sim,
                                                           Path.Combine(wd.WorkingDirectory, "testexportfile.csv"));
                    //import

                    var arguments = new List <string>
                    {
                        "--ImportHouseholdDefinition",
                        "hh.csv"
                    };
                    MainSimEngine.Run(arguments.ToArray(), "simulationengine.exe");
                    db1.Cleanup();
                    wd.CleanUp(1);
                }
            }
        }
 private void ExportToCsvClick([CanBeNull] object sender, [CanBeNull] RoutedEventArgs e)
 {
     using (var sfd = new SaveFileDialog()) {
         sfd.OverwritePrompt  = true;
         sfd.Filter           = "CSV file (*.csv)|*.csv";
         sfd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
         sfd.AddExtension     = true;
         sfd.DefaultExt       = ".csv";
         sfd.Title            = "Please choose the path to save the exported CSV file.";
         sfd.CheckPathExists  = true;
         if (sfd.ShowDialog() == DialogResult.OK)
         {
             try {
                 ModularHouseholdSerializer.ExportAsCSV(Presenter.ThisModularHousehold,
                                                        Presenter.Sim, sfd.FileName);
                 Logger.Info("Finished writing the file.");
                 MessageWindowHandler.Mw.ShowInfoMessage("Finished exporting to " + sfd.FileName, "Finished Export");
             }
             catch (Exception ex) {
                 Logger.Exception(ex);
                 MessageWindowHandler.Mw.ShowDebugMessage(ex);
             }
         }
     }
 }
Esempio n. 4
0
        public void Run()
        {
            Logger.Info("Starting test");
            using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
            {
                using (var wd = new WorkingDir(Utili.GetCurrentMethodAndClass()))
                {
                    Directory.SetCurrentDirectory(wd.WorkingDirectory);

                    var sim = new Simulator(db.ConnectionString)
                    {
                        MyGeneralConfig = { PerformCleanUpChecks = "true" }
                    };
                    Logger.Info("First hh");
                    for (var i = 0; i < sim.ModularHouseholds.It.Count && i < 5; i++)
                    {
                        var mhh = sim.ModularHouseholds[i];
                        Logger.Info("exporting and importing " + mhh.Name);
                        var start = DateTime.Now;
                        if (mhh.CreationType != CreationType.ManuallyCreated)
                        {
                            continue;
                        }
                        var filename = Path.Combine(wd.WorkingDirectory, "testexport." + i + ".csv");
                        ModularHouseholdSerializer.ExportAsCSV(mhh, sim, filename);
                        ModularHouseholdSerializer.ImportFromCSV(filename, sim);
                        var import = DateTime.Now;
                        SimIntegrityChecker.Run(sim);
                        var durationTotal          = DateTime.Now - start;
                        var durationIntegrityCheck = DateTime.Now - import;
                        Logger.Info("Duration: total " + durationTotal.TotalSeconds + " seconds, integrity check: " +
                                    durationIntegrityCheck.TotalSeconds);
                    }
                    Logger.Info("finished");
                    Directory.SetCurrentDirectory(wd.PreviousCurrentDir);
                    db.Cleanup();
                    wd.CleanUp(1);
                }
            }
        }
        public void CSVImportTest()
        {
            using (var db1 = new DatabaseSetup(Utili.GetCurrentMethodAndClass() + "_export"))
            {
                //export
                using (var wd = SetupDB3(Utili.GetCurrentMethodAndClass()))
                {
                    var sim = new Simulator(db1.ConnectionString);
                    ModularHouseholdSerializer.ExportAsCSV(sim.ModularHouseholds[0], sim,
                                                           Path.Combine(wd.WorkingDirectory, "testexportfile.csv"));
                    //import

                    var arguments = new List <string>
                    {
                        "--ImportHouseholdDefinition",
                        "testexportfile.csv"
                    };
                    MainSimEngine.Run(arguments.ToArray(), "simulationengine.exe");
                    db1.Cleanup();
                    wd.CleanUp(1);
                }
            }
        }