public void CalculationOutcomeTest()
 {
     Config.ShowDeleteMessages = false;
     Logger.Threshold          = Severity.Error;
     using (var db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
     {
         db.ClearTable(CalculationOutcome.TableName);
         db.ClearTable(LoadtypeOutcome.TableName);
         var ca = new CalculationOutcome("1", "2", "3", "4", "5", "6", "7", "8", TimeSpan.FromHours(1),
                                         DateTime.Today, DateTime.Today,
                                         db.ConnectionString, 0, 0, null, Guid.NewGuid().ToStrGuid());
         ca.SaveToDB();
         ca.AddLoadType("bla", 10);
         ca.AddAffordanceTimeUse("bla", "blub", 1, 1);
         var cas = new ObservableCollection <CalculationOutcome>();
         CalculationOutcome.LoadFromDatabase(cas, db.ConnectionString, false);
         (cas.Count).Should().Be(1);
         (cas[0].Entries.Count).Should().Be(1);
         (cas[0].AffordanceTimeUses.Count).Should().Be(1);
         db.Cleanup();
     }
 }
        public void MakeRelease()
        {
            const string filename          = "profilegenerator-latest.db3";
            const bool   cleanDatabase     = true;
            const bool   makeZipAndSetup   = true;
            const bool   cleanCalcOutcomes = true;

            var releasename = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            releasename = releasename.Substring(0, 5);
            var          dst = @"v:\Dropbox\LPGReleases\releases" + releasename;
            const string src = @"C:\Work\LPGDev\ReleaseBuilder\bin\Debug\net48";

            //const string srcsim = @"v:\Dropbox\LPG\SimulationEngine\bin\x64\Debug";

            if (Directory.Exists(dst))
            {
                try
                {
                    Directory.Delete(dst, true);
                }
                catch (Exception ex)
                {
                    Logger.Info(ex.Message);
                }
            }
            Directory.CreateDirectory(dst);
            Thread.Sleep(100);
            CopyFiles(src, dst);
            Thread.Sleep(100);
            // CopyFiles(src, dst);
            ReleaseCheck(filename);
            //CopyFilesSimulationEngine(srcsim, dst);
            using (var db = new DatabaseSetup("Release", filename))
            {
                Logger.Info("Using database " + filename);
#pragma warning disable S2583 // Conditionally executed blocks should be reachable
                if (cleanDatabase)
                {
#pragma warning restore S2583 // Conditionally executed blocks should be reachable
                    //DeleteOldCalcOutcomes(db);
                    DissStuffDatabaseCleaner.Run(db.FileName);
                }
                if (cleanCalcOutcomes)
                {
                    CalculationOutcome.ClearTable(db.ConnectionString);
                }
                var sim = new Simulator(db.ConnectionString);
                sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.ReasonableWithChartsAndPDF);
                sim.MyGeneralConfig.PerformCleanUpChecks = "True";
                sim.MyGeneralConfig.ShowSettlingPeriod   = "False";
                sim.MyGeneralConfig.DestinationPath      = "C:\\Work\\";
                sim.MyGeneralConfig.ImagePath            = "C:\\Work\\";
                sim.MyGeneralConfig.RandomSeed           = -1;
                sim.MyGeneralConfig.StartDateString      = "01.01.2016";
                sim.MyGeneralConfig.EndDateString        = "31.12.2016";
                SimIntegrityChecker.Run(sim);
                sim.MyGeneralConfig.PerformCleanUpChecks = "False";
                sim.MyGeneralConfig.CSVCharacter         = ";";
                var forgottenUpdates = false;
                foreach (var trait in sim.HouseholdTraits.It)
                {
                    switch (trait.Name)
                    {
                    case "Cooking, average":
                    case "Cooking, maximum": continue;

                    default:

                        var count = trait.EstimatedTimeCount;
                        var tt    = trait.EstimatedTimeType;
                        trait.CalculateEstimatedTimes();
                        if (Math.Abs(trait.EstimatedTimeCount - count) > 0.0000001 || trait.EstimatedTimeType != tt)
                        {
                            forgottenUpdates = true;
                            Logger.Error("seems you forgot to update the estimate for " + trait.PrettyName +
                                         Environment.NewLine + "Prev count: " + count + " curr: " +
                                         trait.EstimatedTimeCount + Environment.NewLine + "prev tt: " + tt +
                                         " curr tt: " + trait.EstimatedTimeType);
                        }
                        break;
                    }
                }
                if (forgottenUpdates)
                {
                    throw new LPGException("Forgotten updates!\n" + Logger.Get().ReturnAllLoggedErrors());
                }

                // get rid of all templated items
#pragma warning disable S2583 // Conditions should not unconditionally evaluate to "true" or to "false"
                if (cleanDatabase)
                {
#pragma warning restore S2583 // Conditions should not unconditionally evaluate to "true" or to "false" {
                    var templatedItems = sim.FindAndDeleteAllTemplated();
                    if (templatedItems > 0)
                    {
                        throw new LPGException("Left templated items");
                    }
                }

                File.Copy(db.FileName, Path.Combine(dst, "profilegenerator.db3"));
            }
            Thread.Sleep(1000);

            //CopyFilesSimulationEngine(srcsim, dst);
            if (makeZipAndSetup)
            {
                MakeZipFile(releasename, dst);
                MakeSetup(dst, releasename);
            }
        }
Пример #3
0
        public void MakeRelease()
        {
            const string filename          = "profilegenerator-latest.db3";
            const bool   cleanDatabase     = true;
            const bool   makeZipAndSetup   = true;
            const bool   cleanCalcOutcomes = true;

            Logger.Info("### Starting Release");
            var releasename = Assembly.GetExecutingAssembly().GetName().Version.ToString();

            releasename = releasename.Substring(0, 5);
            Logger.Info("Release name: " + releasename);
            //return;
            var dstWin     = @"v:\Dropbox\LPGReleases\releases" + releasename + "\\net48";
            var dstLinux   = @"v:\Dropbox\LPGReleases\releases" + releasename + "\\linux";
            var dstWinCore = @"v:\Dropbox\LPGReleases\releases" + releasename + "\\netCore";

            //const string srcsim = @"v:\Dropbox\LPG\SimulationEngine\bin\x64\Debug";

            PrepareDirectory(dstWin);
            PrepareDirectory(dstLinux);
            PrepareDirectory(dstWinCore);
            const string srclpg = @"C:\Work\LPGDev\WpfApplication1\bin\Debug\net48";

            Logger.Info("### Copying win lpg files");
            var          filesForSetup = WinLpgCopier.CopyLpgFiles(srclpg, dstWin);
            const string srcsim        = @"C:\Work\LPGDev\SimulationEngine\bin\Debug\net48";

            SimEngineCopier.CopySimEngineFiles(srcsim, dstWin);
            const string srcsim2 = @"C:\Work\LPGDev\SimEngine2\bin\Release\netcoreapp3.1\win10-x64";

            SimEngine2Copier.CopySimEngine2Files(srcsim2, dstWinCore);
            const string srcsimLinux = @"C:\Work\LPGDev\SimEngine2\bin\Release\netcoreapp3.1\linux-x64";

            LinuxFileCopier.CopySimEngineLinuxFiles(srcsimLinux, dstLinux);
            Logger.Info("### Finished copying lpg files");
            // CopyFiles(src, dst);
            Logger.Info("### Performing release checks");
            ReleaseCheck(filename);
            //CopyFilesSimulationEngine(srcsim, dst);
            using (var db = new DatabaseSetup("Release", filename))
            {
                Logger.Info("Using database " + filename);
#pragma warning disable S2583 // Conditionally executed blocks should be reachable
                if (cleanDatabase)
                {
#pragma warning restore S2583 // Conditionally executed blocks should be reachable
                    //DeleteOldCalcOutcomes(db);
                    Logger.Info("### cleaning database");
                    DissStuffDatabaseCleaner.Run(db.FileName);
                }
                if (cleanCalcOutcomes)
                {
                    Logger.Info("### cleaning calc outcomes");
                    CalculationOutcome.ClearTable(db.ConnectionString);
                }
                Logger.Info("### integrity check");
                var sim = new Simulator(db.ConnectionString);
                sim.MyGeneralConfig.ApplyOptionDefault(OutputFileDefault.ReasonableWithChartsAndPDF);
                sim.MyGeneralConfig.PerformCleanUpChecks = "True";
                sim.MyGeneralConfig.ShowSettlingPeriod   = "False";
                sim.MyGeneralConfig.DestinationPath      = "C:\\Work\\";
                sim.MyGeneralConfig.ImagePath            = "C:\\Work\\";
                sim.MyGeneralConfig.RandomSeed           = -1;
                sim.MyGeneralConfig.StartDateString      = "01.01.2016";
                sim.MyGeneralConfig.EndDateString        = "31.12.2016";
                SimIntegrityChecker.Run(sim);
                sim.MyGeneralConfig.PerformCleanUpChecks = "False";
                sim.MyGeneralConfig.CSVCharacter         = ";";
                var forgottenUpdates = false;
                Logger.Info("### updating estimates");
                foreach (var trait in sim.HouseholdTraits.It)
                {
                    switch (trait.Name)
                    {
                    case "Cooking, average":
                    case "Cooking, maximum": continue;

                    default:

                        var count = trait.EstimatedTimeCount;
                        var tt    = trait.EstimatedTimeType;
                        trait.CalculateEstimatedTimes();
                        if (Math.Abs(trait.EstimatedTimeCount - count) > 0.0000001 || trait.EstimatedTimeType != tt)
                        {
                            forgottenUpdates = true;
                            Logger.Error("seems you forgot to update the estimate for " + trait.PrettyName +
                                         Environment.NewLine + "Prev count: " + count + " curr: " +
                                         trait.EstimatedTimeCount + Environment.NewLine + "prev tt: " + tt +
                                         " curr tt: " + trait.EstimatedTimeType);
                        }
                        break;
                    }
                }
                if (forgottenUpdates)
                {
                    throw new LPGException("Forgotten updates!\n" + Logger.Get().ReturnAllLoggedErrors());
                }

                // get rid of all templated items
#pragma warning disable S2583 // Conditions should not unconditionally evaluate to "true" or to "false"
                if (cleanDatabase)
                {
                    Logger.Info("### deleting all templated items");
#pragma warning restore S2583 // Conditions should not unconditionally evaluate to "true" or to "false" {
                    var templatedItems = sim.FindAndDeleteAllTemplated();
                    if (templatedItems > 0)
                    {
                        throw new LPGException("Left templated items");
                    }
                }

                File.Copy(db.FileName, Path.Combine(dstWin, "profilegenerator.db3"));
                File.Copy(db.FileName, Path.Combine(dstWinCore, "profilegenerator.db3"));
                File.Copy(db.FileName, Path.Combine(dstLinux, "profilegenerator.db3"));
            }
            Thread.Sleep(1000);
            Logger.Info("### Finished copying all files");
            //CopyFilesSimulationEngine(srcsim, dst);
            if (makeZipAndSetup)
            {
                List <FileInfo> fileForUpload = new List <FileInfo>();
                fileForUpload.Add(MakeZipFile(releasename, dstWin));
                fileForUpload.Add(MakeZipFile(releasename + "_core", dstWinCore));
                fileForUpload.Add(MakeZipFile(releasename + "_linux", dstLinux));
                fileForUpload.Add(MakeSetup(dstWin, releasename, filesForSetup));
                var dstUpload = @"v:\Dropbox\LPGReleases\releases" + releasename + "\\upload";
                PrepareDirectory(dstUpload);
                foreach (FileInfo fi in fileForUpload)
                {
                    string dstName = Path.Combine(dstUpload, fi.Name);
                    fi.CopyTo(dstName, true);
                }
            }
        }
Пример #4
0
        private List <LoadingEntry> GetLoadingActions(bool ignoreMissingTables)
        {
            var actions = new List <LoadingEntry>
            {
                new LoadingEntry("Loadtypes",
                                 () => VLoadType.LoadFromDatabase(LoadTypes.MyItems, ConnectionString, ignoreMissingTables),
                                 LoadTypes),
                new LoadingEntry("Holidays",
                                 () => Holiday.LoadFromDatabase(Holidays.MyItems, ConnectionString, ignoreMissingTables), Holidays),
                new LoadingEntry("Variables",
                                 () => Variable.LoadFromDatabase(Variables.It, ConnectionString, ignoreMissingTables), Variables),

                new LoadingEntry("Date Based Profiles",
                                 () => DateBasedProfile.LoadFromDatabase(DateBasedProfiles.MyItems, ConnectionString,
                                                                         ignoreMissingTables), DateBasedProfiles),
                new LoadingEntry("Vacations",
                                 () => Vacation.LoadFromDatabase(Vacations.MyItems, ConnectionString, ignoreMissingTables),
                                 Vacations),
                new LoadingEntry("Desires",
                                 () => Desire.LoadFromDatabase(Desires.MyItems, ConnectionString, ignoreMissingTables), Desires),
                new LoadingEntry("Time Profiles",
                                 () => TimeBasedProfile.LoadFromDatabase(Timeprofiles.MyItems, ConnectionString, ignoreMissingTables),
                                 Timeprofiles),
                new LoadingEntry("Temperature Profiles",
                                 () => TemperatureProfile.LoadFromDatabase(TemperatureProfiles.MyItems, ConnectionString,
                                                                           ignoreMissingTables), TemperatureProfiles),
                new LoadingEntry("Generators",
                                 () => Generator.LoadFromDatabase(Generators.MyItems, ConnectionString, LoadTypes.MyItems,
                                                                  DateBasedProfiles.MyItems, ignoreMissingTables), Generators),
                new LoadingEntry("Energy Storages",
                                 () => EnergyStorage.LoadFromDatabase(EnergyStorages.MyItems, ConnectionString, LoadTypes.MyItems, Variables.MyItems,
                                                                      ignoreMissingTables), EnergyStorages),
                new LoadingEntry("Transformation Devices",
                                 () => TransformationDevice.LoadFromDatabase(TransformationDevices.MyItems, ConnectionString,
                                                                             LoadTypes.MyItems, Variables.MyItems, ignoreMissingTables), TransformationDevices),
                new LoadingEntry("Device Categories", () =>
                {
                    DeviceCategory.LoadFromDatabase(DeviceCategories.MyItems, out _dcnone, ConnectionString,
                                                    RealDevices.MyItems, ignoreMissingTables);
                    DeviceCategories.DeviceCategoryNone = _dcnone;
                }, DeviceCategories),

                new LoadingEntry("Real Devices",
                                 () => RealDevice.LoadFromDatabase(RealDevices.MyItems, DeviceCategories.MyItems,
                                                                   DeviceCategories.DeviceCategoryNone, ConnectionString, LoadTypes.MyItems, Timeprofiles.MyItems,
                                                                   ignoreMissingTables), RealDevices),
                new LoadingEntry("Device Action Groups",
                                 () => DeviceActionGroup.LoadFromDatabase(DeviceActionGroups.MyItems, ConnectionString,
                                                                          ignoreMissingTables), DeviceActionGroups),
                new LoadingEntry("Device Actions",
                                 () => DeviceAction.LoadFromDatabase(DeviceActions.MyItems, ConnectionString, Timeprofiles.MyItems,
                                                                     RealDevices.MyItems, LoadTypes.MyItems, DeviceActionGroups.MyItems, ignoreMissingTables),
                                 DeviceActions),
                new LoadingEntry("Device Tagging Sets",
                                 () => DeviceTaggingSet.LoadFromDatabase(DeviceTaggingSets.MyItems, ConnectionString,
                                                                         ignoreMissingTables, RealDevices.MyItems, LoadTypes.It), DeviceTaggingSets),
                new LoadingEntry("Persons",
                                 () => Person.LoadFromDatabase(Persons.MyItems, ConnectionString,
                                                               ignoreMissingTables), Persons),
                new LoadingEntry("Locations",
                                 () => Location.LoadFromDatabase(Locations.MyItems, ConnectionString, RealDevices.MyItems,
                                                                 DeviceCategories.MyItems, LoadTypes.MyItems, ignoreMissingTables), Locations),
                new LoadingEntry("Time Limits",
                                 () => TimeLimit.LoadFromDatabase(TimeLimits.MyItems, DateBasedProfiles.MyItems, ConnectionString,
                                                                  ignoreMissingTables), TimeLimits),
                new LoadingEntry("Geographic Locations",
                                 () => GeographicLocation.LoadFromDatabase(GeographicLocations.MyItems, ConnectionString,
                                                                           Holidays.MyItems, TimeLimits.MyItems, ignoreMissingTables), GeographicLocations),
                new LoadingEntry("Subaffordances",
                                 () => SubAffordance.LoadFromDatabase(SubAffordances.MyItems, ConnectionString, Desires.MyItems,
                                                                      ignoreMissingTables, Locations.It, Variables.It), SubAffordances),
                new LoadingEntry("Affordances",
                                 () => Affordance.LoadFromDatabase(Affordances.MyItems, ConnectionString, Timeprofiles.MyItems,
                                                                   DeviceCategories.MyItems, RealDevices.MyItems, Desires.MyItems, SubAffordances.MyItems,
                                                                   LoadTypes.MyItems, TimeLimits.MyItems, DeviceActions.MyItems, DeviceActionGroups.MyItems,
                                                                   Locations.It, ignoreMissingTables, Variables.It), Affordances),
                new LoadingEntry("Affordance Tagging Sets",
                                 () => AffordanceTaggingSet.LoadFromDatabase(AffordanceTaggingSets.MyItems, ConnectionString,
                                                                             ignoreMissingTables, Affordances.MyItems, LoadTypes.It), AffordanceTaggingSets),
                new LoadingEntry("Trait Tags",
                                 () => TraitTag.LoadFromDatabase(TraitTags.MyItems, ConnectionString, ignoreMissingTables),
                                 TraitTags),
                new LoadingEntry("Household Traits",
                                 () => HouseholdTrait.LoadFromDatabase(HouseholdTraits.MyItems, ConnectionString, Locations.MyItems,
                                                                       Affordances.MyItems, RealDevices.MyItems, DeviceCategories.MyItems, Timeprofiles.MyItems,
                                                                       LoadTypes.MyItems, TimeLimits.MyItems, Desires.MyItems, DeviceActions.It, DeviceActionGroups.It,
                                                                       TraitTags.It, ignoreMissingTables, Variables.It), HouseholdTraits),
                new LoadingEntry("Device Selections",
                                 () => DeviceSelection.LoadFromDatabase(DeviceSelections.MyItems, ConnectionString,
                                                                        DeviceCategories.MyItems, RealDevices.MyItems, DeviceActions.It, DeviceActionGroups.It,
                                                                        ignoreMissingTables), DeviceSelections),
                new LoadingEntry("Household Tags",
                                 () => HouseholdTag.LoadFromDatabase(HouseholdTags.It, ConnectionString, ignoreMissingTables),
                                 HouseholdTags),
                new LoadingEntry("Modular Households",
                                 () => ModularHousehold.LoadFromDatabase(ModularHouseholds.MyItems, ConnectionString,
                                                                         HouseholdTraits.MyItems, DeviceSelections.MyItems, ignoreMissingTables, Persons.MyItems,
                                                                         Vacations.It, HouseholdTags.It, TraitTags.It), ModularHouseholds),
                new LoadingEntry("Household Templates",
                                 () => HouseholdTemplate.LoadFromDatabase(HouseholdTemplates.MyItems, ConnectionString,
                                                                          HouseholdTraits.MyItems, ignoreMissingTables, Persons.MyItems, TraitTags.It, Vacations.It,
                                                                          HouseholdTags.It, DateBasedProfiles.It), HouseholdTemplates),
                new LoadingEntry("Template Persons",
                                 () => TemplatePerson.LoadFromDatabase(TemplatePersons.It, ConnectionString, HouseholdTraits.It,
                                                                       ignoreMissingTables, ModularHouseholds.It, Persons.It), TemplatePersons),
                new LoadingEntry("Household Plans",
                                 () => HouseholdPlan.LoadFromDatabase(HouseholdPlans.MyItems, ConnectionString, ignoreMissingTables,
                                                                      Persons.MyItems, AffordanceTaggingSets.MyItems, ModularHouseholds.MyItems),
                                 HouseholdPlans),
                new LoadingEntry("House Types",
                                 () => HouseType.LoadFromDatabase(HouseTypes.MyItems, ConnectionString, RealDevices.MyItems,
                                                                  DeviceCategories.MyItems, Timeprofiles.MyItems, TimeLimits.MyItems, LoadTypes.MyItems,
                                                                  TransformationDevices.MyItems, EnergyStorages.MyItems, Generators.MyItems, ignoreMissingTables,
                                                                  Locations.MyItems, DeviceActions.It, DeviceActionGroups.It, Variables.It), HouseTypes),
                new LoadingEntry("Transportation Device Categories",
                                 () => TransportationDeviceCategory.LoadFromDatabase(TransportationDeviceCategories.It, ConnectionString,
                                                                                     ignoreMissingTables), TransportationDeviceCategories),
                new LoadingEntry("Sites",
                                 () => Site.LoadFromDatabase(Sites.It,
                                                             ConnectionString, ignoreMissingTables,
                                                             Locations.It), Sites),
                new LoadingEntry("Transportation Devices",
                                 () => TransportationDevice.LoadFromDatabase(TransportationDevices.It, ConnectionString, ignoreMissingTables,
                                                                             TransportationDeviceCategories.It, LoadTypes.It), TransportationDevices),

                new LoadingEntry("Transportation Device Sets",
                                 () => TransportationDeviceSet.LoadFromDatabase(TransportationDeviceSets.It, ConnectionString,
                                                                                ignoreMissingTables, TransportationDevices.It), TransportationDeviceSets),

                new LoadingEntry("Travel Routes",
                                 () => TravelRoute.LoadFromDatabase(TravelRoutes.It, ConnectionString, ignoreMissingTables,
                                                                    TransportationDeviceCategories.It, Sites.It), TravelRoutes),

                new LoadingEntry("Travel Route Sets",
                                 () => TravelRouteSet.LoadFromDatabase(TravelRouteSets.It, ConnectionString, ignoreMissingTables,
                                                                       TravelRoutes.It), TravelRouteSets),
                new LoadingEntry("Charging Station Sets",
                                 () => ChargingStationSet.LoadFromDatabase(ChargingStationSets.It,
                                                                           ConnectionString, ignoreMissingTables,
                                                                           LoadTypes.It, TransportationDeviceCategories.It, Sites.It), ChargingStationSets),

                new LoadingEntry("Houses",
                                 () => House.LoadFromDatabase(Houses.MyItems, ConnectionString, TemperatureProfiles.MyItems,
                                                              GeographicLocations.MyItems, HouseTypes.MyItems,
                                                              ModularHouseholds.MyItems, ChargingStationSets.MyItems,
                                                              TransportationDeviceSets.MyItems, TravelRouteSets.MyItems,
                                                              ignoreMissingTables), Houses),
                new LoadingEntry("Settlements",
                                 () => Settlement.LoadFromDatabase(Settlements.MyItems, ConnectionString,
                                                                   TemperatureProfiles.MyItems, GeographicLocations.MyItems, ModularHouseholds.MyItems, Houses.MyItems,
                                                                   ignoreMissingTables), Settlements),
                new LoadingEntry("Settlement Templates",
                                 () => SettlementTemplate.LoadFromDatabase(SettlementTemplates.It, ConnectionString,
                                                                           HouseholdTemplates.It, HouseTypes.It, ignoreMissingTables, TemperatureProfiles.It,
                                                                           GeographicLocations.It, HouseholdTags.It, HouseholdTraits.It), SettlementTemplates),
                new LoadingEntry("Settings",
                                 () => MyGeneralConfig = GeneralConfig.LoadFromDatabase(ConnectionString, ignoreMissingTables), null),
                new LoadingEntry("Calculation Outcomes",
                                 () => CalculationOutcome.LoadFromDatabase(CalculationOutcomes.MyItems, ConnectionString,
                                                                           ignoreMissingTables), CalculationOutcomes)
            };

            return(actions);
        }