Пример #1
0
 public ActionResult Create(DeviceForm form)
 {
     try {
         if (form.Type == DeviceType.GATEWAY &&
             string.IsNullOrWhiteSpace(form.IP))
         {
             ModelState.AddModelError("IP", Resources.IPRequired);
         }
         else if (ModelState.IsValid)
         {
             if (dbAccess.SaveDevice(deviceFactory.CreateDevice(form)))
             {
                 return(RedirectToAction("Index"));
             }
             ModelState.AddModelError("ID", Resources.IDAndSNPresent);
             return(View(form));
         }
         return(View(form));
     }
     catch
     {
         ViewData["ErrorMessage"] = Resources.ErrorWhileSavingDevice;
         return(View());
     }
 }
Пример #2
0
        /// <summary>
        /// Created and registered a device from the provided definition
        /// </summary>
        /// <param name="Def"></param>
        /// <returns></returns>
        protected ITargetDevice CreateAndRegisterDeviceFromDefinition(DeviceDefinition Def)
        {
            ITargetDevice NewDevice = null;

            IDeviceFactory Factory = Gauntlet.Utils.InterfaceHelpers.FindImplementations <IDeviceFactory>()
                                     .Where(F => F.CanSupportPlatform(Def.Platform))
                                     .FirstOrDefault();

            if (Factory == null)
            {
                throw new AutomationException("No IDeviceFactory implementation that supports {0}", Def.Platform);
            }

            try
            {
                bool IsDesktop = Def.Platform != null && UnrealBuildTool.Utils.GetPlatformsInClass(UnrealPlatformClass.Desktop).Contains(Def.Platform.Value);

                if (IsDesktop)
                {
                    string ClientTempDir = Path.Combine(LocalTempDir, "DeviceCache", Def.Platform.ToString());
                    int    DeviceCount   = AvailableDevices.Union(ReservedDevices).Where(D => D.Platform == Def.Platform).Count();

                    NewDevice = Factory.CreateDevice(Def.Name, ClientTempDir);
                }
                else
                {
                    NewDevice = Factory.CreateDevice(Def.Address, Def.DeviceData);
                }

                lock (LockObject)
                {
                    if (NewDevice != null)
                    {
                        RegisterDevice(NewDevice, new UnrealTargetConstraint(NewDevice.Platform, Def.PerfSpec, Def.Model));
                    }
                }
            }
            catch (Exception Ex)
            {
                Log.Info("Failed to create device {0}. {1}", Def.ToString(), Ex.Message);
            }

            return(NewDevice);
        }
Пример #3
0
        /// <summary>
        /// Retrieves a set of device configs from the repository and creates devices with this information
        /// Once the devices are built, they are started
        /// </summary>
        /// <param name="token"></param>
        public async Task ProcessDevicesAsync(CancellationToken token)
        {
            var dm = new DeviceManager(_logger, token);

            try
            {
                _logger.LogInfo("********** Starting Simulator **********");
                while (!token.IsCancellationRequested)
                {
                    var devices = await _deviceStorage.GetDeviceListAsync();

                    var liveDevices = dm.GetLiveDevices();

                    var newDevices     = devices.Where(d => !liveDevices.Contains(d.DeviceId)).ToList();
                    var removedDevices = liveDevices.Where(d => !devices.Any(x => x.DeviceId == d)).ToList();

                    if (removedDevices.Any())
                    {
                        _logger.LogInfo("********** {0} DEVICES REMOVED ********** ", removedDevices.Count);

                        dm.StopDevices(removedDevices);
                    }

                    //begin processing any new devices that were retrieved
                    if (newDevices.Any())
                    {
                        _logger.LogInfo("********** {0} NEW DEVICES FOUND ********** ", newDevices.Count);

                        var devicesToProcess = new List <IDevice>();

                        foreach (var deviceConfig in newDevices)
                        {
                            _logger.LogInfo("********** SETTING UP NEW DEVICE : {0} ********** ", deviceConfig.DeviceId);
                            devicesToProcess.Add(_deviceFactory.CreateDevice(_logger, _transportFactory, _telemetryFactory, _configProvider, deviceConfig));
                        }

                        dm.StartDevices(devicesToProcess);
                    }

                    await Task.Delay(TimeSpan.FromSeconds(_devicePollIntervalSeconds), token);
                }
            }
            catch (TaskCanceledException)
            {
                //do nothing if task was cancelled
                _logger.LogInfo("********** Primary worker role cancellation token source has been cancelled. **********");
            }
            finally
            {
                //ensure that all devices have been stopped
                dm.StopAllDevices();
            }
        }
Пример #4
0
        public void AddNewElement(UIElement uIElement)
        {
            uIElement.Id = _item_counter;
            UIElements.Add(uIElement);
            IDevice device = _deviceFactory.CreateDevice(uIElement.DeviceType, _item_counter);

            device.Position = uIElement.Position;
            switch (uIElement.DeviceType)
            {
            case DeviceType.Device:
                Device temp_device = (Device)device;
                switch (uIElement.Area)
                {
                case Area.AirTemperature:
                    temp_device.Command = _commandFactory.CreateAirTemperatureHeaterCommand();
                    break;

                case Area.WaterTemperature:
                    temp_device.Command = _commandFactory.CreateWaterTemperatureHeaterCommand();
                    break;

                case Area.Nutrient:
                    temp_device.Command = _commandFactory.CreateNutrientRegulatorCommand();
                    break;

                case Area.Acid:
                    temp_device.Command = _commandFactory.CreateAcidRegulatorCommand();
                    break;

                default:
                    throw new NotImplementedException();
                }
                Devices.Add(temp_device);
                break;

            case DeviceType.ActiveSensor:
                ActiveSensors.Add(device as ActiveSensor);
                break;

            case DeviceType.PasssiveSensor:
                PassiveSensors.Add(device as PassiveSensor);
                break;

            default:
                throw new NotImplementedException();
            }
            _item_counter++;
        }
Пример #5
0
        /// <summary>
        /// Retrieves a set of device configs from the repository and creates devices with this information
        /// Once the devices are built, they are started
        /// </summary>
        /// <param name="token"></param>
        public async Task ProcessDevicesAsync(CancellationToken token)
        {
            var dm = new DeviceManager(_logger, token);

            try
            {
                _logger.LogInfo("********** Starting Simulator **********");
                while (!token.IsCancellationRequested)
                {
                    var newDevices     = new List <InitialDeviceConfig>();
                    var removedDevices = new List <string>();
                    var devices        = await _deviceStorage.GetDeviceListAsync();

                    if (devices != null && devices.Any())
                    {
                        newDevices     = devices.Where(d => !_deviceList.Any(x => x.DeviceId == d.DeviceId)).ToList();
                        removedDevices =
                            _deviceList.Where(d => !devices.Any(x => x.DeviceId == d.DeviceId))
                            .Select(x => x.DeviceId)
                            .ToList();
                    }
                    else if (_deviceList != null && _deviceList.Any())
                    {
                        removedDevices = _deviceList.Select(x => x.DeviceId).ToList();
                    }

                    if (newDevices.Count > 0)
                    {
                        _logger.LogInfo("********** {0} NEW DEVICES FOUND ********** ", newDevices.Count);
                    }
                    if (removedDevices.Count > 0)
                    {
                        _logger.LogInfo("********** {0} DEVICES REMOVED ********** ", removedDevices.Count);
                    }


                    //reset the base list of devices for comparison the next
                    //time we retrieve the device list
                    _deviceList = devices;

                    if (removedDevices.Any())
                    {
                        //stop processing any devices that have been removed
                        dm.StopDevices(removedDevices);
                    }

                    //begin processing any new devices that were retrieved
                    if (newDevices.Any())
                    {
                        var devicesToProcess = new List <IDevice>();

                        foreach (var deviceConfig in newDevices)
                        {
                            _logger.LogInfo("********** SETTING UP NEW DEVICE : {0} ********** ", deviceConfig.DeviceId);
                            devicesToProcess.Add(_deviceFactory.CreateDevice(_logger, _transportFactory, _telemetryFactory, _configProvider, deviceConfig));
                        }

#pragma warning disable 4014
                        //don't wait for this to finish
                        dm.StartDevicesAsync(devicesToProcess);
#pragma warning restore 4014
                    }
                    await Task.Delay(TimeSpan.FromSeconds(_devicePollIntervalSeconds), token);
                }
            }
            catch (TaskCanceledException)
            {
                //do nothing if task was cancelled
                _logger.LogInfo("********** Primary worker role cancellation token source has been cancelled. **********");
            }
            finally
            {
                //ensure that all devices have been stopped
                dm.StopAllDevices();
            }
        }
Пример #6
0
 private IDevice CreateDevice(string id)
 {
     return(_deviceFactory.CreateDevice(id));
 }