public static WorkingDir SetupDB3([JetBrains.Annotations.NotNull] string name, bool clearTemplatedFirst = false)
        {
            var srcPath = DatabaseSetup.GetSourcepath(null);

            Config.CatchErrors = false;
            var wd          = new WorkingDir(name);
            var dstfullName = Path.Combine(wd.WorkingDirectory, "profilegenerator.db3");

            Config.IsInUnitTesting = true;
            if (File.Exists("profilegenerator.db3"))
            {
                File.Delete("profilegenerator.db3");
            }
            File.Copy(srcPath, dstfullName);

            Directory.SetCurrentDirectory(wd.WorkingDirectory);
            Logger.Info("Using directory:" + Directory.GetCurrentDirectory());
            var connectionString = "Data Source=" + dstfullName;
            // ReSharper disable once UseObjectOrCollectionInitializer
            Simulator sim = new Simulator(connectionString);

            sim.MyGeneralConfig.DeviceProfileHeaderMode = DeviceProfileHeaderMode.Standard;
            if (clearTemplatedFirst)
            {
                sim.FindAndDeleteAllTemplated();
            }
            DatabaseVersionChecker.CheckVersion(connectionString);
            Logger.Info("Checked database version. It is ok.");
            return(wd);
        }
Example #2
0
 public void RunatabaseVersionCheckerTest()
 {
     using (DatabaseSetup db = new DatabaseSetup(Utili.GetCurrentMethodAndClass()))
     {
         DatabaseVersionChecker.CheckVersion(db.ConnectionString);
         string previousVersion = DatabaseVersionChecker.DstVersion;
         DatabaseVersionChecker.DstVersion = "asdf";
         Action a = () => DatabaseVersionChecker.CheckVersion(db.ConnectionString);
         a.Should().Throw <LPGException>();
         DatabaseVersionChecker.DstVersion = previousVersion;
     }
 }
Example #3
0
        public Simulator([NotNull] string connectionString, bool ignoreMissingTables = false)
        {
            ConnectionString = connectionString;
            MyGeneralConfig  = new GeneralConfig(ConnectionString);
            CategoryOrDevice.Add("Device");
            CategoryOrDevice.Add("Device Category");

            Categories = new ObservableCollection <object>();
            LoadTypes  = new CategoryDBBase <VLoadType>("Load types");
            Categories.Add(LoadTypes);
            Holidays = new CategoryDBBase <Holiday>("Holidays");
            Categories.Add(Holidays);
            GeographicLocations = new CategoryDBBase <GeographicLocation>("Geographic Locations / Cities");
            Categories.Add(GeographicLocations);
            TemperatureProfiles = new CategoryDBBase <TemperatureProfile>("Temperature Profiles");
            Categories.Add(TemperatureProfiles);
            DateBasedProfiles = new CategoryDBBase <DateBasedProfile>("Date Based Profiles");
            Categories.Add(DateBasedProfiles);
            Vacations = new CategoryDBBase <Vacation>("Vacations");
            Categories.Add(Vacations);
            Desires = new CategoryDBBase <Desire>("Desires");
            Categories.Add(Desires);
            Locations = new CategoryDBBase <Location>("Locations");
            Categories.Add(Locations);
            Persons = new CategoryDBBase <Person>("Persons");
            Categories.Add(Persons);
            DeviceCategories = new CategoryDeviceCategory();
            Categories.Add(DeviceCategories);
            RealDevices = new CategoryDBBase <RealDevice>("Devices");
            Categories.Add(RealDevices);
            DeviceActions = new CategoryDBBase <DeviceAction>("Device Actions");
            Categories.Add(DeviceActions);
            DeviceActionGroups = new CategoryDBBase <DeviceActionGroup>("Device Action Groups");
            Categories.Add(DeviceActionGroups);
            DeviceTaggingSets = new CategoryDBBase <DeviceTaggingSet>("Device Tagging Set");
            Categories.Add(DeviceTaggingSets);
            Timeprofiles = new CategoryDBBase <TimeBasedProfile>("Time Profiles");
            Categories.Add(Timeprofiles);
            TimeLimits = new CategoryDBBase <TimeLimit>("Time Limits");
            Categories.Add(TimeLimits);
            Variables = new CategoryDBBase <Variable>("Variables");
            Categories.Add(Variables);
            Affordances = new CategoryAffordance("Affordances");
            Categories.Add(Affordances);
            SubAffordances = new CategoryDBBase <SubAffordance>("Sub-Affordances");
            Categories.Add(SubAffordances);
            AffordanceTaggingSets = new CategoryDBBase <AffordanceTaggingSet>("Affordance Tagging Set");
            Categories.Add(AffordanceTaggingSets);
            TraitTags = new CategoryDBBase <TraitTag>("Household Trait Tags");
            Categories.Add(TraitTags);
            HouseholdTraits = new CategoryDBBase <HouseholdTrait>("Household Traits");
            Categories.Add(HouseholdTraits);
            HouseholdTags = new CategoryDBBase <HouseholdTag>("Household Template Tags");
            Categories.Add(HouseholdTags);
            HouseholdTemplates = new CategoryDBBase <HouseholdTemplate>("Household Templates");
            Categories.Add(HouseholdTemplates);
            DeviceSelections = new CategoryDBBase <DeviceSelection>("Device Selections");
            Categories.Add(DeviceSelections);
            TemplatePersons = new CategoryDBBase <TemplatePerson>("Template Persons");
            Categories.Add(TemplatePersons);
            ModularHouseholds = new CategoryDBBase <ModularHousehold>("Modular Households");
            Categories.Add(ModularHouseholds);
            TransformationDevices = new CategoryDBBase <TransformationDevice>("Transformation Devices");
            Categories.Add(TransformationDevices);
            EnergyStorages = new CategoryDBBase <EnergyStorage>("Energy Storages");
            Categories.Add(EnergyStorages);
            Generators = new CategoryDBBase <Generator>("Externally Controlled Generators");
            Categories.Add(Generators);
            HouseTypes = new CategoryDBBase <HouseType>("House Types");
            Categories.Add(HouseTypes);
            Houses = new CategoryDBBase <House>("Houses");
            Categories.Add(Houses);
            HouseholdPlans = new CategoryDBBase <HouseholdPlan>("Household Plans");
            Categories.Add(HouseholdPlans);
            SettlementTemplates = new CategoryDBBase <SettlementTemplate>("Settlement Templates");
            Categories.Add(SettlementTemplates);
            Settlements = new CategorySettlement();
            Categories.Add(Settlements);
            Sites = new CategoryDBBase <Site>("Sites");
            Categories.Add(Sites);

            TransportationDeviceCategories = new CategoryDBBase <TransportationDeviceCategory>("Transportation Device Categories");
            Categories.Add(TransportationDeviceCategories);

            TransportationDevices = new CategoryDBBase <TransportationDevice>("Transportation Devices");
            Categories.Add(TransportationDevices);

            TransportationDeviceSets = new CategoryDBBase <TransportationDeviceSet>("Transportation Devices Sets");
            Categories.Add(TransportationDeviceSets);

            TravelRoutes = new CategoryDBBase <TravelRoute>("Travel Routes");
            Categories.Add(TravelRoutes);

            TravelRouteSets = new CategoryDBBase <TravelRouteSet>("Travel Route Sets");
            Categories.Add(TravelRouteSets);

            ChargingStationSets = new CategoryDBBase <ChargingStationSet>("Charging Station Sets");
            Categories.Add(ChargingStationSets);

            Categories.Add(new OtherCategory("Calculation"));
            Categories.Add(new OtherCategory("Settings"));
            CalculationOutcomes = new CategoryOutcome();
            Categories.Add(CalculationOutcomes);
            try {
                if (!ignoreMissingTables)
                {
                    DatabaseVersionChecker.CheckVersion(ConnectionString);
                }
                LoadFromDB(ignoreMissingTables);
            }
            catch (Exception e) {
                if (Config.IsInUnitTesting)
                {
                    Logger.Exception(e);
                }

                throw;
            }
            Logger.Info("Loaded the Database");
            foreach (dynamic category in Categories)
            {
                if (category.LoadingNumber == -1)
                {
                    throw new LPGException("Loading of the database failed due to invalid loading number for " +
                                           category.Name + " of " + category.LoadingNumber + ".");
                }
            }
        }