예제 #1
0
        private async void Connection_RequestReceived(AppServiceConnection sender, AppServiceRequestReceivedEventArgs args)
        {
            // if you are doing anything awaitable, you need to get a deferral
            var requestDeferral = args.GetDeferral();
            var returnMessage   = new ValueSet();

            try
            {
                //obtain and react to the command passed in by the client
                var message = args.Request.Message["Request"] as string;
                switch (message)
                {
                case "SensorData":

                    CrossCuttingRT.Dto.SensorsDataDto sd = _proxy.ReadSensorData();

                    returnMessage.Add("Temperature", sd.Temperature);
                    returnMessage.Add("LightLevel", sd.LightLevel);
                    break;
                }
                returnMessage.Add("Response", "OK");
            }
            catch (Exception ex)
            {
                returnMessage.Add("Response", "Failed: " + ex.Message);
            }

            await args.Request.SendResponseAsync(returnMessage);

            //let the OS know that the action is complete
            requestDeferral.Complete();
        }
예제 #2
0
        private async void _timerElapsed(ThreadPoolTimer timer)
        {
            if (_running)
            {
                return;
            }
            _running = true;
            try
            {
                var data = await PollData();

                if (data != null)
                {
                    SensorData = data;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.Write(ex);
            }
            finally
            {
                _running = false;
            }
        }
예제 #3
0
        internal CrossCuttingRT.Dto.SensorsDataDto ReadSensorData()
        {
            try
            {
                var dto = new CrossCuttingRT.Dto.SensorsDataDto();

                dto.Temperature = _instance.GetTemperature();

                dto.LightLevel = _instance.GetLightLevel();

                return(dto);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
예제 #4
0
        private async Task <CrossCuttingRT.Dto.SensorsDataDto> PollData()
        {
            CrossCuttingRT.Dto.SensorsDataDto result = null;

            using (var dataService = new AppServiceConnection())
            {
                var listing = await AppServiceCatalog.FindAppServiceProvidersAsync("DataCollectorInterface");

                var packageName = "";

                // there may be cases where other applications could expose the same App Service Name, in our case
                // we only have the one
                if (listing.Count == 1)
                {
                    packageName = listing[0].PackageFamilyName;
                }

                dataService.AppServiceName    = "DataCollectorInterface";
                dataService.PackageFamilyName = packageName;
                var status = await dataService.OpenAsync();

                if (status == AppServiceConnectionStatus.Success)
                {
                    var msg = new ValueSet();
                    msg.Add("Request", "SensorData");
                    AppServiceResponse request = await dataService.SendMessageAsync(msg);

                    if (request.Status == AppServiceResponseStatus.Success)
                    {
                        CrossCuttingRT.Dto.SensorsDataDto data = new CrossCuttingRT.Dto.SensorsDataDto();

                        data.Temperature = request.Message["Temperature"] as double?;
                        data.LightLevel  = request.Message["LightLevel"] as double?;
                        result           = data;
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Request Response Status: " + status.ToString());
                    }
                }
            }

            return(result);
        }
예제 #5
0
        public CrossCuttingRT.Dto.SensorsDataDto ReadSensorData()
        {
            try
            {
                //var InstanceTask = FEZHAT.CreateAsync();
                //InstanceTask.Wait();
                //var Instance = InstanceTask.Result;
                //Instance.D3.Color = new FEZHAT.Color(0, 0, 255);

                if (Instance == null)
                {
                    return(null);
                }

                var dto = new CrossCuttingRT.Dto.SensorsDataDto();

                dto.Temperature = Instance.GetTemperature();

                dto.LightLevel = Instance.GetLightLevel();

                if (Instance.D2.Color.R == 255)
                {
                    Instance.D2.Color = new FEZHAT.Color(0, 255, 0);
                }
                else
                {
                    Instance.D2.Color = new FEZHAT.Color(255, 0, 0);
                }

                return(dto);
            }
            catch (Exception ex)
            {
                throw;
            }
        }