Ejemplo n.º 1
0
 public DeviceCategoryPresenter(
     [NotNull] ApplicationPresenter applicationPresenter,
     [NotNull] DeviceCategoryView view, [NotNull] DeviceCategory deviceCategory)
     : base(view, "ThisDeviceCategory.Name", deviceCategory, applicationPresenter)
 {
     _deviceCategory = deviceCategory;
     _dcp            = new DeviceCategoryPickerPresenter(Sim, _deviceCategory,
                                                         view.DeviceCategoryPicker1);
     view.DeviceCategoryPicker1.DataContext = _dcp;
     _selectedParentCategory = _deviceCategory.ParentCategory;
     _deviceCategory.RefreshSubDevices();
     _usedIns = new ObservableCollection <UsedIn>();
     RefreshUsedIn();
 }
        public void IsAffordanceAvailableTestCheckDeviceActionGroupInDeviceActionGroup()
        {
            // Location: device action group
            // affordance: device Action Group
            Config.IsInUnitTesting = true;
            var col           = new ColorRGB(255, 0, 0);
            var deviceActions = new ObservableCollection <DeviceAction>();
            var aff           = new Affordance("bla", null, null, false, PermittedGender.All, 1, col, string.Empty, null,
                                               string.Empty, string.Empty,
                                               true, true, 0, 100, false, ActionAfterInterruption.GoBackToOld, false, Guid.NewGuid().ToStrGuid(), BodilyActivityLevel.Low);
            var rd1 = new RealDevice("rd1", 1, string.Empty, null, string.Empty, false, false, string.Empty, Guid.NewGuid().ToStrGuid());

            var dg = new DeviceActionGroup("group", string.Empty, string.Empty, Guid.NewGuid().ToStrGuid());
            var da = new DeviceAction("device action 1", null, "blub", string.Empty, dg, rd1, Guid.NewGuid().ToStrGuid());

            deviceActions.Add(da);
            var devices = new ObservableCollection <RealDevice>
            {
                rd1
            };
            // check if it works with a device category that has the device
            var dc1 = new DeviceCategory("dc1", 0, string.Empty, false, devices, Guid.NewGuid().ToStrGuid(), null, true);

            rd1.DeviceCategory = dc1;
            dc1.RefreshSubDevices();
            (dc1.SubDevices.Count).Should().Be(1);
            var connectionString = string.Empty;
            var lt = new VLoadType("lt", string.Empty, "bla", "blub", 1, 1, new TimeSpan(0, 1, 0), 1, connectionString,
                                   LoadTypePriority.Mandatory, true, Guid.NewGuid().ToStrGuid());
            var tbp = new TimeBasedProfile("name", 1, connectionString, TimeProfileType.Absolute, "data source", Guid.NewGuid().ToStrGuid());

            aff.AffordanceDevices.Add(new AffordanceDevice(dg, tbp, null, 0, null,
                                                           new ObservableCollection <RealDevice>(),
                                                           new ObservableCollection <DeviceCategory>(), "name", lt, string.Empty, 1, Guid.NewGuid().ToStrGuid()));
            var allDevices3 = new List <IAssignableDevice>
            {
                dg
            };

            if (da.DeviceActionGroup == null)
            {
                throw new LPGException("device action group was null");
            }
            var relevantDeviceActionGroup = da.DeviceActionGroup.GetDeviceActions(deviceActions);

            (relevantDeviceActionGroup.Count).Should().Be(1);
            (aff.IsAffordanceAvailable(allDevices3, deviceActions)).Should().BeTrue();
        }
Ejemplo n.º 3
0
        // the real picking function that selects a device
        public RealDevice PickDeviceFromCategory(DeviceCategory deviceCategory, EnergyIntensityType energyIntensity,
                                                 ObservableCollection <DeviceAction> deviceActions)
        {
            deviceCategory.RefreshSubDevices();
            var rds = deviceCategory.SubDevices;

            if (rds.Count == 0)
            {
                throw new DataIntegrityException("The device category " + deviceCategory.Name +
                                                 " has no devices but it is used. A device could not be picked from it.");
            }
            RealDevice pickedDevice = null;

            // look for this device category in the device selection
            if (_deviceSelection != null && _deviceSelection.Items.Count > 0)
            {
                foreach (var item in _deviceSelection.Items)
                {
                    if (item.DeviceCategory == deviceCategory)
                    {
                        pickedDevice = item.Device;
                    }
                }
            }
            if (pickedDevice == null)
            {
                switch (energyIntensity)
                {
                case EnergyIntensityType.Random:
                    var dstval = _random.Next(rds.Count);
                    pickedDevice = rds[dstval];
                    break;

                case EnergyIntensityType.EnergySaving:
                    pickedDevice = rds[0];
                    foreach (var t in rds)
                    {
                        if (pickedDevice.WeightedEnergyIntensity > t.WeightedEnergyIntensity)
                        {
                            pickedDevice = t;
                        }
                    }
                    break;

                case EnergyIntensityType.EnergySavingPreferMeasured:
                    var devices = GetMeasuredDevicesFromRealDevices(deviceActions, rds);
                    pickedDevice = devices[0];
                    foreach (var t in devices)
                    {
                        if (pickedDevice.WeightedEnergyIntensity > t.WeightedEnergyIntensity)
                        {
                            pickedDevice = t;
                        }
                    }
                    break;

                case EnergyIntensityType.EnergyIntensive:
                    pickedDevice = rds[0];
                    foreach (var t in rds)
                    {
                        if (pickedDevice.WeightedEnergyIntensity < t.WeightedEnergyIntensity)
                        {
                            pickedDevice = t;
                        }
                    }
                    break;

                case EnergyIntensityType.EnergyIntensivePreferMeasured:
                    var rdevices = GetMeasuredDevicesFromRealDevices(deviceActions, rds);
                    pickedDevice = rdevices[0];
                    foreach (var t in rdevices)
                    {
                        if (pickedDevice.WeightedEnergyIntensity < t.WeightedEnergyIntensity)
                        {
                            pickedDevice = t;
                        }
                    }
                    break;

                case EnergyIntensityType.AsOriginal:
                    throw new DataIntegrityException("Not permitted energy intensity type here: As Original");

                default:
                    throw new DataIntegrityException("Unknown EnergyIntensityType");
                }
            }

            Logger.Debug("Picked " + pickedDevice + " from " + rds.Count + " devices.");
            return(pickedDevice);
        }