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."); } }