public IGetResponse GetAll()
        {
            using (ILifetimeScope scope = DI.Container.BeginLifetimeScope())
            {
                IGatewayManager gateway = scope.Resolve <IGatewayManager>();

                return(new GetResponse(GetResponse.ResponseStatus.OK, gateway.GetBoards()));
            }
        }
Ejemplo n.º 2
0
 public GatewayAppService(IRepository <GatewayType, int> gatewayTypeRepository,
                          IGatewayRepository gatewayRepository,
                          IWorkshopRepository workshopRepository,
                          IFactoryRepository factoryRepository,
                          ICityRepository cityRepository,
                          IGatewayManager gatewayManager)
 {
     _gatewayTypeRepository = gatewayTypeRepository;
     _gatewayRepository     = gatewayRepository;
     _workshopRepository    = workshopRepository;
     _factoryRepository     = factoryRepository;
     _cityRepository        = cityRepository;
     _gatewayManager        = gatewayManager;
 }
        public IGetResponse Set(int id)
        {
            using (ILifetimeScope scope = DI.Container.BeginLifetimeScope())
            {
                IGatewayManager gateway = scope.Resolve <IGatewayManager>();

                if (gateway.TrySelectBoard(id))
                {
                    return(new GetResponse(GetResponse.ResponseStatus.OK, $"Monitoring successfully changed to Board ID {id}."));
                }
                else
                {
                    return(new GetResponse(GetResponse.ResponseStatus.OK, $"Board ID {id} was not detected."));
                }
            }
        }
 public DownloadController(IGatewayBackendFactory<IPackageBackend> factory , INuGetGatewayManager manager)
 {
     this.factory = factory;
     this.manager = manager;
 }
 public Upload15Controller(IGatewayBackendFactory <IPackageBackend> factory, IGatewayConfigurationFactory configurationFactory, INuGetGatewayManager manager)
 {
     this.factory = factory;
     this.configurationFactory = configurationFactory;
     this.manager = manager;
 }
 public Upload15Controller(IGatewayBackendFactory<IPackageBackend> factory, IGatewayConfigurationFactory configurationFactory, INuGetGatewayManager manager)
 {
     this.factory = factory;
     this.configurationFactory = configurationFactory;
     this.manager = manager;
 }
        public async void StartAsync()
        {
            /* Values gathered from previous reading cycle. */
            double?prevHumidity        = null;
            double?previousTemperature = null;
            int?   previousSensorId    = null;

            using (ILifetimeScope scope = DI.Container.BeginLifetimeScope())
            {
                ILifxManager           lifx         = scope.Resolve <ILifxManager>();
                IDewPointCalculator    dewPointCalc = scope.Resolve <IDewPointCalculator>();
                IColorCalculator       colorCalc    = scope.Resolve <IColorCalculator>();
                IGatewayManager        gateway      = scope.Resolve <IGatewayManager>();
                IConfigurationProvider config       = scope.Resolve <IConfigurationProvider>();
                IHttpServer            http         = scope.Resolve <IHttpServer>();

                await http.ListenAsync(8800, "api");

                gateway.SetDefaultBoard(config.DefaultSensorBoardId);

                try
                {
                    Dictionary <string, string> parameters = new Dictionary <string, string>
                    {
                        { "OAUTH2_TOKEN", config.LifxHttpApiOAuth2Token },
                        { "SELECTED_DEVICE", config.DefaultLifxDeviceLabel }
                    };

                    await lifx.InitAsync(parameters);

                    await gateway.InitAsync();

                    while (true)
                    {
                        try
                        {
                            IEnumerable <BoardReading> readings = await gateway.GetBoardReadingsAsync();

                            DataTextBlock.Text = readings.Count().ToString();

                            SensorsTextBlock.Text = string.Join(", ", gateway.GetBoards());

                            int?boardId = gateway.GetSelectedBoard();

                            BoardReading reading = readings
                                                   .Where(x => x.Id == boardId)
                                                   .FirstOrDefault();

                            // IF: There is a reading for the selected sensor.
                            if (reading != null)
                            {
                                double dewPoint = dewPointCalc.Calculate(reading.Humidity.Value, reading.Temperature.Value);

                                HumidityTextBlock.Text    = reading.Humidity.ToString();
                                TemperatureTextBlock.Text = reading.Temperature.ToString();
                                DewPointTextBlock.Text    = dewPoint.ToString();
                                SensorIdTextBlock.Text    = boardId.ToString();

                                /* IF: Values have been changed or sensor has been changed. */
                                if (reading.Humidity != prevHumidity || reading.Temperature != previousTemperature || previousSensorId != boardId)
                                {
                                    Color color = colorCalc.CalculateDewPointColor(dewPoint);

                                    await lifx.SetSelectedDeviceRgbColorAsync(color);

                                    IEnumerable <LifxDevice> lifxDevices = await lifx.GetAllDevicesAsync(false);

                                    if (lifxDevices != null)
                                    {
                                        BulbsTextBlock.Text = string.Join(", ", lifxDevices.Select(x => x.Label));
                                    }

                                    LifxDevice selected = await lifx.GetSelectedDeviceAsync();

                                    if (selected != null)
                                    {
                                        SelectedTextBlock.Text = selected.Label;
                                    }

                                    RedTextBlock.Text   = color.R.ToString();
                                    GreenTextBlock.Text = color.G.ToString();
                                    BlueTextBlock.Text  = color.B.ToString();

                                    HumidityRectangle.Fill = new SolidColorBrush(color);

                                    prevHumidity        = reading.Humidity;
                                    previousTemperature = reading.Temperature;
                                    previousSensorId    = boardId;
                                }
                            }
                        }
                        catch (Exception e)
                        {
                            ErrorTextBlock.Text = e.Message;
                        }
                    }
                }
                catch (Exception e)
                {
                    ErrorTextBlock.Text = e.Message;
                }
            }
        }
 public WrapController(IGatewayBackendFactory<IPackageBackend> factory, IOpenWrapGatewayManager manager)
 {
     this.factory = factory;
     this.manager = manager;           
 }
Ejemplo n.º 9
0
 public WrapController(IGatewayBackendFactory <IPackageBackend> factory, IOpenWrapGatewayManager manager)
 {
     this.factory = factory;
     this.manager = manager;
 }
Ejemplo n.º 10
0
 public WorkshopRepository(IGatewayManager gatewayManager, IDbContextProvider <IoTDbContext> dbContextProvider) : base(dbContextProvider)
 {
     _gatewayManager = gatewayManager;
 }