public void CalcAffordanceDtoLoggerTest()
        {
            using (WorkingDir wd = new WorkingDir(Utili.GetCurrentMethodAndClass()))
            {
                CalcAffordanceDtoLogger ael    = new CalcAffordanceDtoLogger(wd.SqlResultLoggingService);
                HouseholdKey            key    = new HouseholdKey("hhkey");
                List <IDataSaverBase>   savers = new List <IDataSaverBase>
                {
                    ael
                };
                InputDataLogger idl = new InputDataLogger(savers.ToArray());
                //CalcLoadTypeDto cldto = new CalcLoadTypeDto("loadtype", 1, "kw", "kwh", 1, true, "guid");
                CalcProfileDto cpd = new CalcProfileDto("name", 1, ProfileType.Absolute, "source", Guid.NewGuid().ToStrGuid());
                AvailabilityDataReferenceDto adrd  = new AvailabilityDataReferenceDto("blub", "availguid".ToStrGuid());
                CalcAffordanceDto            cadto = new CalcAffordanceDto("blub", 1, cpd, "locname", "locguid".ToStrGuid(), true, new List <CalcDesireDto>(),
                                                                           1, 100, PermittedGender.All, true, 1, 1, 1, 1, "affcat", false, false, new List <CalcAffordanceVariableOpDto>(),
                                                                           new List <VariableRequirementDto>(), ActionAfterInterruption.GoBackToOld,
                                                                           "timelimitname", 100, true, "srctrait", "guid".ToStrGuid(), adrd, key, BodilyActivityLevel.Low);

                cadto.AddDeviceTuple("devname", "deviguid".ToStrGuid(), cpd, "calcloadtypename", "loadtypeguid".ToStrGuid(), 1, new TimeSpan(0, 1, 0), 1, 1);
                List <IHouseholdKey> aes = new List <IHouseholdKey>
                {
                    cadto
                };
                idl.SaveList(aes);
                var res = ael.Load(key);
                var s1  = JsonConvert.SerializeObject(aes, Formatting.Indented);
                var s2  = JsonConvert.SerializeObject(res, Formatting.Indented);
                s1.Should().Be(s2);
                wd.CleanUp();
            }
        }
예제 #2
0
        private void MakeAffordanceDevices([NotNull] CalcLocationDto calcloc, TimeSpan internalStepSize,
                                           [NotNull] CalcLoadTypeDtoDictionary ltdict,
                                           [NotNull][ItemNotNull] ObservableCollection <DeviceAction> allDeviceActions,
                                           AffordanceWithTimeLimit aff, [NotNull] CalcAffordanceDto caff, [NotNull] AffordanceDevice devtup,
                                           [NotNull][ItemNotNull] List <CalcDeviceDto> devicesAtLocation,
                                           [ItemNotNull][NotNull] List <DeviceCategoryDto> deviceCategoryDtos)
        {
            if (devtup.Device == null)
            {
                throw new LPGException("Device was null");
            }
            // pick the device itself
            var pickedDevice = _picker.GetDeviceDtoForAffordance(devtup.Device, devicesAtLocation,
                                                                 calcloc.ID, allDeviceActions, deviceCategoryDtos);

            if (pickedDevice == null)
            {
                throw new DataIntegrityException(
                          "Affordance " + aff.Affordance.Name + " has broken devices. Please fix",
                          aff.Affordance);
            }

            // find the device in the calc devices
            var dev = devicesAtLocation.Single(calcDevice => calcDevice.Name == pickedDevice.Name);

            if (dev == null)
            {
                throw new DataIntegrityException(
                          "Affordance " + aff.Affordance.Name + " has broken devices. Please fix",
                          aff.Affordance);
            }

            if (devtup.Device == null)
            {
                throw new LPGException("Device was null");
            }

            switch (devtup.Device.AssignableDeviceType)
            {
            case AssignableDeviceType.Device:
            case AssignableDeviceType.DeviceCategory:
            {
                if (devtup.LoadType == null)
                {
                    throw new LPGException("No load type set");
                }
                if (ltdict.SimulateLoadtype(devtup.LoadType))
                {
                    if (devtup.TimeProfile == null)
                    {
                        throw new DataIntegrityException(
                                  "Affordance " + aff.Affordance.Name + " has broken time profiles. Please fix.",
                                  aff.Affordance);
                    }

                    var newprof =
                        CalcDeviceDtoFactory.GetCalcProfileDto(devtup.TimeProfile);
                    CalcLoadTypeDto loadtype = ltdict.GetLoadtypeDtoByLoadType(devtup.LoadType);
                    caff.AddDeviceTuple(dev.Name, dev.Guid, newprof, loadtype.Name, loadtype.Guid,
                                        devtup.TimeOffset, internalStepSize, 1, devtup.Probability);
                }
            }
            break;

            case AssignableDeviceType.DeviceAction:
            case AssignableDeviceType.DeviceActionGroup:
            {
                DeviceAction da;
                // if it's a device action group, then go back to the picker to select a specific
                // device action based on the available devices
                if (devtup.Device.AssignableDeviceType == AssignableDeviceType.DeviceActionGroup)
                {
                    da =
                        _picker.GetDeviceActionFromGroup(devtup.Device, devicesAtLocation,
                                                         allDeviceActions);
                }
                else
                {
                    da = (DeviceAction)devtup.Device;
                }
                if (da == null)
                {
                    throw new LPGException("Device action was null");
                }

                if (da.Profiles.Count == 0)
                {
                    throw new DataIntegrityException(
                              "The device action " + da.Name + " has no time profiles. Please fix", da);
                }

                foreach (var profile in da.Profiles)
                {
                    if (profile.VLoadType == null)
                    {
                        throw new LPGException("Profile was null");
                    }

                    if (ltdict.SimulateLoadtype(profile.VLoadType))
                    {
                        if (profile.Timeprofile == null)
                        {
                            throw new DataIntegrityException(
                                      "The device action " + da.Name + " has broken time profiles. Please fix.",
                                      da);
                        }

                        if (profile.VLoadType == null)
                        {
                            throw new DataIntegrityException(
                                      "The device action " + da.Name + " has broken load types. Please fix.", da);
                        }

                        var newprof =
                            CalcDeviceDtoFactory.GetCalcProfileDto(profile.Timeprofile);
                        CalcLoadTypeDto loadType = ltdict.GetLoadtypeDtoByLoadType(profile.VLoadType);
                        caff.AddDeviceTuple(dev.Name, dev.Guid, newprof, loadType.Name, loadType.Guid,
                                            profile.TimeOffset + devtup.TimeOffset, internalStepSize, profile.Multiplier,
                                            devtup.Probability);
                    }
                }
            }
            break;

            default:
                throw new LPGException(
                          "Missing an AssignableDeviceType at GetCalcAffordancesAtLocation! Please report to the programmer.");
            }
        }