Exemplo n.º 1
0
        private async void GetTimeCategories(object sender, EventArgs e)
        {
            string MethodName         = "GetTimeCategories";
            var    timeCategoriesTask = Awareness.GetCaptureClient(this).GetTimeCategoriesAsync();

            try
            {
                await timeCategoriesTask;
                if (timeCategoriesTask.IsCompleted && timeCategoriesTask.Result != null)
                {
                    ITimeCategories timeCategories = timeCategoriesTask.Result.TimeCategories;
                    foreach (int timeCode in timeCategories.GetTimeCategories())
                    {
                        log.ShowLog(Constant.GetTimeCategory(timeCode));
                        Log.Info(MethodName, timeCode.ToString());
                    }
                }
                else
                {
                    var    exception    = timeCategoriesTask.Exception;
                    string errorMessage = $"{AwarenessStatusCodes.GetMessage(exception.GetStatusCode())}: {exception.Message}";
                    log.ShowLog(errorMessage);
                    Log.Error(MethodName, errorMessage);
                }
            }
            catch (Exception exception)
            {
                string errorMessage = $"{AwarenessStatusCodes.GetMessage(exception.GetStatusCode())}: {exception.Message}";
                log.ShowLog(errorMessage);
                Log.Error(MethodName, errorMessage);
            }
        }
Exemplo n.º 2
0
        private async void GetHeadsetStatus(object sender, EventArgs e)
        {
            string MethodName        = "GetHeadsetStatus";
            var    headsetStatusTask = Awareness.GetCaptureClient(this).GetHeadsetStatusAsync();

            try
            {
                await headsetStatusTask;
                if (headsetStatusTask.IsCompleted && headsetStatusTask.Result != null)
                {
                    IHeadsetStatus headsetStatus = headsetStatusTask.Result.HeadsetStatus;
                    int            status        = headsetStatus.Status;
                    string         logMessage    = $"Headsets are {(status == HeadsetStatus.Connected ? "connected" : "disconnected")}";
                    log.ShowLog(logMessage);
                    Log.Info(MethodName, logMessage);
                }
                else
                {
                    var    exception    = headsetStatusTask.Exception;
                    string errorMessage = $"{AwarenessStatusCodes.GetMessage(exception.GetStatusCode())}: {exception.Message}";
                    log.ShowLog(errorMessage);
                    Log.Error(MethodName, errorMessage);
                }
            }
            catch (Exception exception)
            {
                string errorMessage = $"{AwarenessStatusCodes.GetMessage(exception.GetStatusCode())}: {exception.Message}";
                log.ShowLog(errorMessage);
                Log.Error(MethodName, errorMessage);
            }
        }
Exemplo n.º 3
0
        private async void GetBluetoothStatus(object sender, EventArgs e)
        {
            string MethodName          = "GetBluetoothStatus";
            var    bluetoothStatusTask = Awareness.GetCaptureClient(this).GetBluetoothStatusAsync(BluetoothStatus.DeviceCar);

            try
            {
                await bluetoothStatusTask;
                if (bluetoothStatusTask.IsCompleted && bluetoothStatusTask.Result != null)
                {
                    IBluetoothStatus bluetoothStatus = bluetoothStatusTask.Result.BluetoothStatus;
                    int    status     = bluetoothStatus.Status;
                    string logMessage = $"The Bluetooth car stereo are {(status == BluetoothStatus.Connected ? "connected" : "disconnected")}";
                    log.ShowLog(logMessage);
                    Log.Info(MethodName, logMessage);
                }
                else
                {
                    var    exception    = bluetoothStatusTask.Exception;
                    string errorMessage = $"{AwarenessStatusCodes.GetMessage(exception.GetStatusCode())}: {exception.Message}";
                    log.ShowLog(errorMessage);
                    Log.Error(MethodName, errorMessage);
                }
            }
            catch (Exception exception)
            {
                string errorMessage = $"{AwarenessStatusCodes.GetMessage(exception.GetStatusCode())}: {exception.Message}";
                log.ShowLog(errorMessage);
                Log.Error(MethodName, errorMessage);
            }
        }
Exemplo n.º 4
0
        private async void GetLightIntensity(object sender, EventArgs e)
        {
            string MethodName       = "GetLightIntensity";
            var    ambientLightTask = Awareness.GetCaptureClient(this).GetLightIntensityAsync();

            try
            {
                await ambientLightTask;
                if (ambientLightTask.IsCompleted && ambientLightTask.Result != null)
                {
                    IAmbientLightStatus ambientLightStatus = ambientLightTask.Result.AmbientLightStatus;
                    string logMessage = $"Light intensity is {ambientLightStatus.LightIntensity} lux";
                    log.ShowLog(logMessage);
                    Log.Info(MethodName, logMessage);
                }
                else
                {
                    var    exception    = ambientLightTask.Exception;
                    string errorMessage = $"{AwarenessStatusCodes.GetMessage(exception.GetStatusCode())}: {exception.Message}";
                    log.ShowLog(errorMessage);
                    Log.Error(MethodName, errorMessage);
                }
            }
            catch (Exception exception)
            {
                string errorMessage = $"{AwarenessStatusCodes.GetMessage(exception.GetStatusCode())}: {exception.Message}";
                log.ShowLog(errorMessage);
                Log.Error(MethodName, errorMessage);
            }
        }
Exemplo n.º 5
0
        private async void GetBehaviorStatus(object sender, EventArgs e)
        {
            string MethodName   = "GetBehaviorStatus";
            var    behaviorTask = Awareness.GetCaptureClient(this).GetBehaviorAsync();

            try
            {
                await behaviorTask;
                if (behaviorTask.IsCompleted && behaviorTask.Result != null)
                {
                    BehaviorStatus   behaviorStatus     = behaviorTask.Result.BehaviorStatus;
                    DetectedBehavior mostLikelyBehavior = behaviorStatus.MostLikelyBehavior;
                    string           logMessage         = $"Most likely behavior is {Constant.GetBehavior(mostLikelyBehavior.Type)},the confidence is { mostLikelyBehavior.Confidence}";
                    log.ShowLog(logMessage);
                    Log.Info(MethodName, logMessage);
                }
                else
                {
                    var    exception    = behaviorTask.Exception;
                    string errorMessage = $"{AwarenessStatusCodes.GetMessage(exception.GetStatusCode())}: {exception.Message}";
                    log.ShowLog(errorMessage);
                    Log.Error(MethodName, errorMessage);
                }
            }
            catch (Exception exception)
            {
                string errorMessage = $"{AwarenessStatusCodes.GetMessage(exception.GetStatusCode())}: {exception.Message}";
                log.ShowLog(errorMessage);
                Log.Error(MethodName, errorMessage);
            }
        }
Exemplo n.º 6
0
        private async void GetLocation(object sender, EventArgs e)
        {
            string MethodName   = "GetLocation";
            var    locationTask = Awareness.GetCaptureClient(this).GetLocationAsync();

            try
            {
                await locationTask;
                if (locationTask.IsCompleted && locationTask.Result != null)
                {
                    Location location   = locationTask.Result.Location;
                    string   logMessage = $"Longtitude: {location.Longitude},Latitude: {location.Latitude}";
                    log.ShowLog(logMessage);
                    Log.Info(MethodName, logMessage);
                }
                else
                {
                    var    exception    = locationTask.Exception;
                    string errorMessage = $"{AwarenessStatusCodes.GetMessage(exception.GetStatusCode())}: {exception.Message}";
                    log.ShowLog(errorMessage);
                    Log.Error(MethodName, errorMessage);
                }
            }
            catch (Exception exception)
            {
                string errorMessage = $"{AwarenessStatusCodes.GetMessage(exception.GetStatusCode())}: {exception.Message}";
                log.ShowLog(errorMessage);
                Log.Error(MethodName, errorMessage);
            }
        }
Exemplo n.º 7
0
        private async void QueryDeviceSupportingCapabilities()
        {
            Task <CapabilityResponse> querySupportingCapabilities = Awareness.GetCaptureClient(this).QuerySupportingCapabilitiesAsync();

            try
            {
                await querySupportingCapabilities;
                if (querySupportingCapabilities.IsCompleted && querySupportingCapabilities.Result != null)
                {
                    ICapabilityStatus capabilityStatus = querySupportingCapabilities.Result.CapabilityStatus;
                    int[]             capabilities     = capabilityStatus.GetCapabilities();
                    Log.Info("QueryDeviceSupportingCapabilities", $"capabilities code : {string.Join(" ", capabilities)}");
                    string logMessage = "This device supports the following awareness capabilities:\n";
                    foreach (int capability in capabilities)
                    {
                        logMessage += Constant.GetCapabilityStatus(capability) + "\n";
                    }
                    log.ShowLog(logMessage);
                }
                else
                {
                    Log.Error("QueryDeviceSupportingCapabilities", "Failed to get supported capabilities." + querySupportingCapabilities.Exception);
                    log.ShowLog("Failed to get supported capabilities.");
                }
            }
            catch (System.Exception ex)
            {
                Log.Error("QueryDeviceSupportingCapabilities", "Failed to get supported capabilities." + ex);
                log.ShowLog("Failed to get supported capabilities.");
            }
        }
Exemplo n.º 8
0
        private async void GetBeaconStatus(object sender, EventArgs e)
        {
            string MethodName = "GetBeaconStatus";
            string ns         = "sample namespace";
            string type       = "sample type";

            byte[]             content = Encoding.ASCII.GetBytes("sample");
            BeaconStatusFilter filter  = BeaconStatusFilter.Match(ns, type, content);
            var beaconTask             = Awareness.GetCaptureClient(this).GetBeaconStatusAsync(filter);

            try
            {
                await beaconTask;
                if (beaconTask.IsCompleted && beaconTask.Result != null)
                {
                    List <IBeaconStatusBeaconData> beaconDataList = beaconTask.Result.BeaconStatus.BeaconData.ToList();
                    string logMessage = string.Empty;
                    if (beaconDataList != null && beaconDataList.Count != 0)
                    {
                        int i = 1;
                        foreach (IBeaconStatusBeaconData beaconData in beaconDataList)
                        {
                            logMessage += $"Beacon Data {i++}\n";
                            logMessage += $"namespace: {beaconData.Namespace}\n";
                            logMessage += $"type: {beaconData.Type}\n";
                            logMessage += $"content: {BitConverter.ToString(beaconData.GetContent())}\n";
                        }
                    }
                    else
                    {
                        logMessage = "No beacon matches filters nearby.";
                    }
                    log.ShowLog(logMessage);
                    Log.Info(MethodName, logMessage);
                }
                else
                {
                    var    exception    = beaconTask.Exception;
                    string errorMessage = $"{AwarenessStatusCodes.GetMessage(exception.GetStatusCode())}: {exception.Message}";
                    log.ShowLog(errorMessage);
                    Log.Error(MethodName, errorMessage);
                }
            }
            catch (Exception exception)
            {
                string errorMessage = $"{AwarenessStatusCodes.GetMessage(exception.GetStatusCode())}: {exception.Message}";
                log.ShowLog(errorMessage);
                Log.Error(MethodName, errorMessage);
            }
        }
Exemplo n.º 9
0
        private async void GetWeatherStatus(object sender, EventArgs e)
        {
            string MethodName  = "GetWeatherStatus";
            var    weatherTask = Awareness.GetCaptureClient(this).GetWeatherByDeviceAsync();

            try
            {
                await weatherTask;
                if (weatherTask.IsCompleted && weatherTask.Result != null)
                {
                    IWeatherStatus   weatherStatus    = weatherTask.Result.WeatherStatus;
                    WeatherSituation weatherSituation = weatherStatus.WeatherSituation;
                    Situation        situation        = weatherSituation.Situation;
                    string           logMessage       = $"City:{weatherSituation.City.Name}\n";
                    logMessage += $"Weather id is {situation.WeatherId}\n";
                    logMessage += $"CN Weather id is {situation.CnWeatherId}\n";
                    logMessage += $"Temperature is {situation.TemperatureC}℃";
                    logMessage += $",{situation.TemperatureF}℉\n";
                    logMessage += $"Wind speed is {situation.WindSpeed}km/h\n";
                    logMessage += $"Wind direction is {situation.WindDir}\n";
                    logMessage += $"Humidity is {situation.Humidity}%";
                    log.ShowLog(logMessage);
                    Log.Info(MethodName, logMessage);
                }
                else
                {
                    var    exception    = weatherTask.Exception;
                    string errorMessage = $"{AwarenessStatusCodes.GetMessage(exception.GetStatusCode())}: {exception.Message}";
                    log.ShowLog(errorMessage);
                    Log.Error(MethodName, errorMessage);
                }
            }
            catch (Exception exception)
            {
                string errorMessage = $"{AwarenessStatusCodes.GetMessage(exception.GetStatusCode())}: {exception.Message}";
                log.ShowLog(errorMessage);
                Log.Error(MethodName, errorMessage);
            }
        }