Пример #1
0
        async Task AddSensor(IDevice device)
        {
            if (isAddingSensor)
                return;

            isAddingSensor = true;
            try
            {
                SensorModel sensor = null;
                sensor = await SensorKitExtensions.BeginInvokeOnMainThreadAsync<SensorModel>(()=>{
                    sensor = new SensorModel()
                    {
                        Id = device.Id,
                        Name = device.Name,
                        Information = Registry.Public.FirstOrDefault(s => s.Model == SensorInformation.TryParseSensorType(device.Name)),
                        IsLive = true
                    };
                    Data.Add(sensor);
                    return sensor;
                });
                
                if (sensor != null)
                {

                    InvokeHelper.Invoke(() =>
                    {
                        NotifyPropertyChanged("Data");
                    });
                }
            }catch(Exception x)
            {
                Debug.WriteLine(x);
            }
            isAddingSensor = false;
        }
Пример #2
0
        private SensorKit()
        {
            // automatically add local model for the local on-phone sensors
            LocalData = new SensorModel()
            {
                Id          = default(Guid),
                Name        = SensorTypes.Hub.ToString(),
                Information = Registry.Items.FirstOrDefault(d => d.Model == SensorTypes.Hub)
            };
            Data.Add(LocalData);

            BLE     = CrossBluetoothLE.Current;
            Adapter = CrossBluetoothLE.Current.Adapter;

            BLE.StateChanged             += OnStateChanged;
            Adapter.DeviceDiscovered     += OnDeviceDiscovered;
            Adapter.ScanTimeoutElapsed   += Adapter_ScanTimeoutElapsed;
            Adapter.DeviceDisconnected   += OnDeviceDisconnected;
            Adapter.DeviceConnectionLost += OnDeviceConnectionLost;
        }
Пример #3
0
 public SensorKitConnector(SensorModel data)
 {
     Data = data;
 }
Пример #4
0
        public static async Task <bool> PostToApi(SensorModel sensor, SensorItem item)
        {
            try
            {
                if (String.IsNullOrEmpty(SensorKit.Instance.API))
                {
                    return(false);
                }

                string rootUrl = SensorKit.Instance.API;
                string url     = rootUrl;
                var    client  = new HttpClient();

                HttpResponseMessage response;

                string json = "";

                if (item.itemType == SensorItemTypes.Dribble)
                {
                    url = rootUrl + "dribblesession";
                    var dribblesession = new dribblesession
                    {
                        deviceId   = sensor.Id.ToString().ToLower(),
                        deviceName = sensor.Name,
                        count      = item.dribbles,
                        duration   = item.duration,
                        gavg       = item.dgavg,
                        gmax       = item.dgmax,
                        pace       = item.pace,
                        tag        = sensor.Tag
                    };
                    json = dribblesession.ToJsonString();
                }
                //else if (item.itemType == SensorItemTypes.Summary)
                //{
                //    url = rootUrl + "dribblesummary";
                //    var dribblesummary = new summary
                //    {
                //        deviceId = Id.ToString().ToLower(),
                //        deviceName = Name,
                //        tag = Tag,
                //        air = item.aircount,
                //        airaltmax = item.airaltmax,
                //        airgavg = item.airgavg,
                //        airgmax = item.airgmax,
                //        airt = item.airt,
                //        steps = (int)item.steps,
                //        dribbleCount = item.dribbles,
                //        dgavg = item.dgavg,
                //        dgmax = item.dgmax,
                //        dpace = item.pace,
                //        dsessions = item.sessions
                //    };
                //    json = dribblesummary.ToJsonString();
                //}

                if (!String.IsNullOrEmpty(json))
                {
                    byte[] byteData = Encoding.UTF8.GetBytes(json);

                    using (var content = new ByteArrayContent(byteData))
                    {
                        content.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                        response = await client.PostAsync(url, content);
                    }

                    if (response.IsSuccessStatusCode)
                    {
                        return(true);
                    }
                }
            }catch (Exception x)
            {
                Debug.WriteLine(x);
            }

            return(false);
        }
Пример #5
0
        public static Device RegisterDeviceFromSensorModel(this SessionDataContainer sessionContainer, SensorModel sensorModel)
        {
            var match = (from d in sessionContainer.Session.Devices
                         where d.Id == sensorModel.Id.ToString()
                         select d).FirstOrDefault();

            if (match == null)
            {
                var device = new Device()
                {
                    Id        = sensorModel.Id.ToString(),
                    SessionId = sessionContainer.Session.Id
                };
                sessionContainer.Session.Devices.Add(device);

                return(device);
            }
            else
            {
                return(match);
            }
        }