/// <summary>
        /// Gets all the characteristics of this service
        /// </summary>
        private async void GetAllCharacteristics()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("ObservableGattDeviceService::getAllCharacteristics: ");
            sb.Append(Name);

            try
            {
                CancellationTokenSource tokenSource = new CancellationTokenSource(5000);
                var t = Task.Run(() => Service.GetCharacteristicsAsync(Windows.Devices.Bluetooth.BluetoothCacheMode.Uncached), tokenSource.Token);

                GattCharacteristicsResult result = null;
                result = await t.Result;

                if (result.Status == GattCommunicationStatus.Success)
                {
                    sb.Append(" - getAllCharacteristics found ");
                    sb.Append(result.Characteristics.Count());
                    sb.Append(" characteristics");
                    Debug.WriteLine(sb);
                    foreach (GattCharacteristic gattchar in result.Characteristics)
                    {
                        Characteristics.Add(new ObservableGattCharacteristics(gattchar, this));
                    }
                }
                else if (result.Status == GattCommunicationStatus.Unreachable)
                {
                    sb.Append(" - getAllCharacteristics failed with Unreachable");
                    Debug.WriteLine(sb.ToString());
                }
                else if (result.Status == GattCommunicationStatus.ProtocolError)
                {
                    sb.Append(" - getAllCharacteristics failed with Unreachable");
                    Debug.WriteLine(sb.ToString());
                }
            }
            catch (AggregateException ae)
            {
                foreach (var ex in ae.InnerExceptions)
                {
                    if (ex is TaskCanceledException)
                    {
                        Debug.WriteLine("Getting characteristics took too long.");
                        Name += " - Timed out getting some characteristics";
                        return;
                    }
                }
            }
            catch (UnauthorizedAccessException)
            {
                // Bug 9145823:GetCharacteristicsAsync throw System.UnauthorizedAccessException when querying GenericAccess Service Characteristics
                Name += " - Unauthorized Access";
            }
            catch (Exception ex)
            {
                Debug.WriteLine("getAllCharacteristics: Exception - {0}" + ex.Message);
                throw;
            }
        }
Exemple #2
0
        public override void OnConnect()
        {
            Console.WriteLine("Device Connected!");

            Windesheart.PairedDevice = this;

            //Check if bluetooth-state changes to off and then on, to enable reconnection management
            BluetoothService.StartListeningForAdapterChanges();

            Characteristics?.Clear();

            CharacteristicDisposable?.Dispose();
            //Find unique characteristics
            CharacteristicDisposable = IDevice.WhenAnyCharacteristicDiscovered().Subscribe(async characteristic =>
            {
                if (characteristic != null && !Characteristics.Contains(characteristic))
                {
                    Characteristics.Add(characteristic);

                    //Check if authCharacteristic has been found, then authenticate
                    if (characteristic.Uuid == MiBand3Resource.GuidCharacteristicAuth)
                    {
                        //Check if this is a new connection that needs authentication
                        await _authenticationService.Authenticate();
                    }
                }
            });
        }
        /// <summary>
        /// Gets all the characteristics of this service
        /// </summary>
        private async void GetAllCharacteristics()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("ObservableGattDeviceService::getAllCharacteristics: ");
            sb.Append(Name);



            try
            {
                // Request the necessary access permissions for the service and abort
                // if permissions are denied.
                GattOpenStatus status = await Service.OpenAsync(GattSharingMode.SharedReadAndWrite);

                if (status != GattOpenStatus.Success && status != GattOpenStatus.AlreadyOpened)
                {
                    string error = " - Error: " + status.ToString();
                    Name += error;
                    sb.Append(error);
                    Debug.WriteLine(sb.ToString());

                    return;
                }

                GattCharacteristicsResult result = await Service.GetCharacteristicsAsync(Services.SettingsServices.SettingsService.Instance.UseCaching?BluetoothCacheMode.Cached : BluetoothCacheMode.Uncached);

                if (result.Status == GattCommunicationStatus.Success)
                {
                    sb.Append(" - getAllCharacteristics found ");
                    sb.Append(result.Characteristics.Count());
                    sb.Append(" characteristics");
                    Debug.WriteLine(sb);
                    foreach (GattCharacteristic gattchar in result.Characteristics)
                    {
                        if (gattchar.Uuid.ToString() == "49535343-1e4d-4bd9-ba61-23c647249616")
                        {
                            Characteristics.Clear();

                            Characteristics.Add(new ObservableGattCharacteristics(gattchar, this));
                        }
                    }
                }
                else if (result.Status == GattCommunicationStatus.Unreachable)
                {
                    sb.Append(" - getAllCharacteristics failed with Unreachable");
                    Debug.WriteLine(sb.ToString());
                }
                else if (result.Status == GattCommunicationStatus.ProtocolError)
                {
                    sb.Append(" - getAllCharacteristics failed with Unreachable");
                    Debug.WriteLine(sb.ToString());
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("getAllCharacteristics: Exception - {0}" + ex.Message);
                throw;
            }
        }
        public void ApplyFrom(IPresetMetadata presetMetadata)
        {
            if (!UserOverwrittenProperties.Contains(nameof(Author)))
            {
                Author = presetMetadata.Author;
            }

            if (!UserOverwrittenProperties.Contains(nameof(Comment)))
            {
                Comment = presetMetadata.Comment;
            }

            if (!UserOverwrittenProperties.Contains(nameof(PresetName)))
            {
                PresetName = presetMetadata.PresetName;
            }

            if (!UserOverwrittenProperties.Contains(nameof(BankPath)))
            {
                BankPath = presetMetadata.BankPath;
            }

            if (!UserOverwrittenProperties.Contains(nameof(Types)))
            {
                using (Types.SuspendChangeNotifications(SuspensionMode.None))
                {
                    Types.Clear();

                    foreach (var type in presetMetadata.Types)
                    {
                        if (!type.IsIgnored)
                        {
                            Types.Add(new Type {
                                TypeName = type.TypeName, SubTypeName = type.SubTypeName
                            });
                        }
                    }
                }
            }

            if (!UserOverwrittenProperties.Contains(nameof(Characteristics)))
            {
                using (Characteristics.SuspendChangeNotifications(SuspensionMode.None))
                {
                    Characteristics.Clear();

                    foreach (var characteristic in presetMetadata.Characteristics)
                    {
                        if (!characteristic.IsIgnored)
                        {
                            Characteristics.Add(new Characteristic
                            {
                                CharacteristicName = characteristic.CharacteristicName
                            });
                        }
                    }
                }
            }
        }
Exemple #5
0
    void LoadCharacteristicsDefinitions()
    {
        characteristics = new Characteristics();

        foreach (var def in race.rulerCreationRules.characteristicDefinitions.Keys)
        {
            characteristics.Add(def, new Characteristic(race.rulerCreationRules.characteristicDefinitions[def]));
        }
    }
        private void RegisterCharacteristic(Guid service_uuid, Guid characteristicUuid)
        {
            var accData = DeviceServices.FirstOrDefault(s => s.Uuid == service_uuid).GetCharacteristics(characteristicUuid)[0];

            if (!Characteristics.ContainsKey(service_uuid.ToString()))
            {
                Characteristics.Add(service_uuid.ToString(), new List <GattCharacteristic>());
            }
            Characteristics[service_uuid.ToString()].Add(accData);
        }
        /// <summary>
        /// Gets all the characteristics of this service
        /// </summary>
        private async Task GetAllCharacteristics()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("ObservableGattDeviceService::getAllCharacteristics: ");
            sb.Append(name);

            try
            {
                // Request the necessary access permissions for the service and abort
                // if permissions are denied.
                GattOpenStatus status = await service.OpenAsync(GattSharingMode.SharedReadAndWrite);

                if (status != GattOpenStatus.Success && status != GattOpenStatus.AlreadyOpened)
                {
                    string error = " - Error: " + status.ToString();
                    Name += error;
                    sb.Append(error);
                    Debug.WriteLine(sb.ToString());
                    return;
                }

                var result = await service.GetCharacteristicsAsync(Services.SettingsServices.SettingsService.Instance.UseCaching?BluetoothCacheMode.Cached : BluetoothCacheMode.Uncached);

                if (result.Status == GattCommunicationStatus.Success)
                {
                    sb.Append(" - getAllCharacteristics found ");
                    sb.Append(result.Characteristics.Count());
                    sb.Append(" characteristics");
                    Debug.WriteLine(sb);
                    foreach (GattCharacteristic gattchar in result.Characteristics)
                    {
                        ObservableGattCharacteristics temp = new ObservableGattCharacteristics(gattchar, this);
                        await temp.Initialize();

                        Characteristics.Add(temp);
                    }
                }
                else if (result.Status == GattCommunicationStatus.Unreachable)
                {
                    sb.Append(" - getAllCharacteristics failed with Unreachable");
                    Debug.WriteLine(sb.ToString());
                }
                else if (result.Status == GattCommunicationStatus.ProtocolError)
                {
                    sb.Append(" - getAllCharacteristics failed with Unreachable");
                    Debug.WriteLine(sb.ToString());
                }
            }
            catch (Exception ex)
            {
                Debug.WriteLine("getAllCharacteristics: Exception - {0}" + ex.Message);
                Name += " - Exception: " + ex.Message;
            }
        }
Exemple #8
0
 public Classifier(Export export)
 {
     myExport = export;
     myExport.ProductGroups = groups = new Groups(export);
     foreach (NomenclatureProperties item in Enum.GetValues(typeof(NomenclatureProperties)))
     {
         var title = item.GetEnumTitle();
         var guid  = item.GetAttribute <OnlineStoreGuidAttribute>().Guid;
         Characteristics.Add(item, new PropertyOfGoods(guid, title, PropertyTypeValue.String));
     }
 }
Exemple #9
0
 /// <summary>
 /// Discovers the characteristics for the services.
 /// </summary>
 public void DiscoverCharacteristics()
 {
     Characteristics.Clear();
     // do nothing
     foreach (var c in NativeService.Characteristics)
     {
         var characteristic = new Characteristic(c, _gatt, _callback);
         Characteristics.Add(characteristic);
     }
     CharacteristicDiscovered(this, new CharacteristicsDiscoveredEventArgs(Characteristics));
 }
        /// <summary>
        /// Gets all the characteristics of this service
        /// </summary>
        /// <returns>The status of the communication with the GATT device.</returns>
        private async Task <GattCommunicationStatus> GetAllCharacteristics()
        {
            var tokenSource            = new CancellationTokenSource(5000);
            var getCharacteristicsTask = await Task.Run(
                () => Service.GetCharacteristicsAsync(BluetoothCacheMode.Uncached),
                tokenSource.Token);

            GattCharacteristicsResult result = null;

            result = await getCharacteristicsTask;

            if (result.Status == GattCommunicationStatus.Success)
            {
                foreach (var gattCharacteristic in result.Characteristics)
                {
                    Characteristics.Add(new ObservableGattCharacteristics(gattCharacteristic, this));
                }
            }

            return(result.Status);
        }
Exemple #11
0
        /// <summary>
        /// Gets all the characteristics of this service
        /// </summary>
        public async Task <bool> GetAllCharacteristics()
        {
            StringBuilder sb = new StringBuilder();

            sb.Append("ObservableGattDeviceService::getAllCharacteristics: ");
            sb.Append(Name);

            try
            {
                // Request the necessary access permissions for the service and abort
                // if permissions are denied.
                GattOpenStatus status = await Service.OpenAsync(GattSharingMode.SharedReadAndWrite);

                if (status != GattOpenStatus.Success && status != GattOpenStatus.AlreadyOpened)
                {
                    string error = " - Error: " + status.ToString();
                    Name += error;
                    sb.Append(error);
                    Log.WriteLine(sb.ToString());

                    return(false);
                }

                CancellationTokenSource tokenSource = new CancellationTokenSource(5000);
                var t = Task.Run(() => Service.GetCharacteristicsAsync(Windows.Devices.Bluetooth.BluetoothCacheMode.Uncached), tokenSource.Token);

                GattCharacteristicsResult result = null;
                result = await t.Result;

                if (result.Status == GattCommunicationStatus.Success)
                {
                    sb.Append(" - getAllCharacteristics found ");
                    sb.Append(result.Characteristics.Count());
                    sb.Append(" characteristics");
                    Log.WriteLine(sb.ToString());
                    foreach (GattCharacteristic gattchar in result.Characteristics)
                    {
                        Characteristics.Add(new ObservableGattCharacteristics(gattchar, this));
                    }
                }
                else if (result.Status == GattCommunicationStatus.Unreachable)
                {
                    sb.Append(" - getAllCharacteristics failed with Unreachable");
                    Log.WriteLine(sb.ToString());
                }
                else if (result.Status == GattCommunicationStatus.ProtocolError)
                {
                    sb.Append(" - getAllCharacteristics failed with Unreachable");
                    Log.WriteLine(sb.ToString());
                }
            }
            catch (AggregateException ae)
            {
                foreach (var ex in ae.InnerExceptions)
                {
                    if (ex is TaskCanceledException)
                    {
                        Log.WriteLine("!!!Getting characteristics took too long.");
                        Name += " - Timed out getting some characteristics";
                        return(false);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.WriteLine("!!!getAllCharacteristics: Exception - {0}" + ex.Message);
                throw;
            }
            return(true);
        }
Exemple #12
0
 private void OnConnect(Characteristics characteristics)
 {
     _characteristics.Add(characteristics);
     OnUpdatePoints();
 }
        public void ProcessBlock(List <string> block)
        {
            var firstLine = block.First();

            if (firstLine.StartsWith("K0100"))
            {
                var values = firstLine.Split(' ');
                int numberOfCharacteristics;

                if (!int.TryParse(values[1], out numberOfCharacteristics))
                {
                    throw new Exception("Value of field K0100 is invalid.");
                }

                while (numberOfCharacteristics > Characteristics.Count)
                {
                    Characteristics.Add(new Characteristic());
                }

                firstLine = block[1];
            }

            if (firstLine.StartsWith("K0999"))
            {
                //todo finish
            }

            if (firstLine.StartsWith("K1"))
            {
                //process part data
                var part = PartConverter.Convert(block);

                if (part != null)
                {
                    Parts.Add(part);
                    _currentPart = part;
                }
            }
            else if (firstLine.StartsWith("K2"))
            {
                //process characteristic data
                CharacteristicConverter.Convert(block, Characteristics.ToArray());
            }
            else if (firstLine.StartsWith("K00") || char.IsNumber(firstLine[0]))
            {
                if (_currentPart == null)
                {
                    throw new Exception("Invalid key structure. Part information should be processed before any measurements.");
                }
                //process value portion
                //part and characteristic sections are considered finished now so make sure we got all processed characteristics assigned to current part
                if (_currentPart.Characteristics == null)
                {
                    //assign characteristics to _current part
                    _currentPart.Characteristics = Characteristics.Where(p => string.IsNullOrEmpty(p.PartNumber) && !string.IsNullOrEmpty(p.Number)).ToArray();

                    foreach (var currentPartCharacteristic in _currentPart.Characteristics)
                    {
                        currentPartCharacteristic.PartNumber = _currentPart.Number;
                    }
                }
                MeasurementConverter.Convert(block, _currentPart.Characteristics);
            }
        }
        /// <summary>
        /// Добавление характеристики
        /// </summary>
        private void AddCharacteristic()
        {
            var characteristic = selectedNomenclature.AddCharacteristic("Новая характеристика");

            Characteristics.Add(characteristic);
        }
        private void AddEntryes()
        {
            #region ValueType
            ValueType valueIntType    = new ValueType("int");
            ValueType valueStringType = new ValueType("string");
            ValueType valueFloatType  = new ValueType("float");
            ValueType valueBoolType   = new ValueType("bool");
            ValueTypes.Add(valueIntType);
            ValueTypes.Add(valueStringType);
            ValueTypes.Add(valueFloatType);
            ValueTypes.Add(valueBoolType);
            SaveChanges();
            #endregion

            #region DeviceType
            DeviceType deviceLaptopType = new DeviceType("Ноутбук", Properties.Resources.Laptop);
            DeviceTypes.Add(deviceLaptopType);
            SaveChanges();
            #endregion

            #region Devices
            Device device1 = new Device(deviceLaptopType.ID, "Samsung NC10");
            Device device2 = new Device(deviceLaptopType.ID, "ASUS K50IN");
            Devices.Add(device1);
            Devices.Add(device2);
            SaveChanges();
            #endregion

            #region CharacteristicType
            CharacteristicType characteristicType_Webcam       = new CharacteristicType(deviceLaptopType.ID, "Веб-камера", valueBoolType.ID);
            CharacteristicType characteristicType_VideoCard    = new CharacteristicType(deviceLaptopType.ID, "Видеокарта", valueStringType.ID);
            CharacteristicType characteristicType_WorkingHours = new CharacteristicType(deviceLaptopType.ID, "Время работы", valueIntType.ID);
            CharacteristicType characteristicType_Screen       = new CharacteristicType(deviceLaptopType.ID, "Диагональ экрана", valueFloatType.ID);
            CharacteristicType characteristicType_Storage      = new CharacteristicType(deviceLaptopType.ID, "Накопитель", valueIntType.ID);
            CharacteristicType characteristicType_RAM          = new CharacteristicType(deviceLaptopType.ID, "Оперативная память", valueIntType.ID);
            CharacteristicType characteristicType_CPU          = new CharacteristicType(deviceLaptopType.ID, "Процессор", valueStringType.ID);
            CharacteristicTypes.Add(characteristicType_Webcam);
            CharacteristicTypes.Add(characteristicType_VideoCard);
            CharacteristicTypes.Add(characteristicType_WorkingHours);
            CharacteristicTypes.Add(characteristicType_Screen);
            CharacteristicTypes.Add(characteristicType_Storage);
            CharacteristicTypes.Add(characteristicType_RAM);
            CharacteristicTypes.Add(characteristicType_CPU);
            SaveChanges();
            #endregion

            #region Characteristics
            //1 Samsung NC10
            Characteristic char1_Webcam       = new Characteristic(device1.ID, characteristicType_Webcam.ID, "true");
            Characteristic char1_VideoCard    = new Characteristic(device1.ID, characteristicType_VideoCard.ID, "Intel GMA 952 (встроенная)");
            Characteristic char1_WorkingHours = new Characteristic(device1.ID, characteristicType_WorkingHours.ID, "6");
            Characteristic char1_Screen       = new Characteristic(device1.ID, characteristicType_Screen.ID, "10,20");
            Characteristic char1_Storage      = new Characteristic(device1.ID, characteristicType_Storage.ID, "80");
            Characteristic char1_RAM          = new Characteristic(device1.ID, characteristicType_RAM.ID, "1");
            Characteristic char1_CPU          = new Characteristic(device1.ID, characteristicType_CPU.ID, "Intel 945GSE");
            Characteristics.Add(char1_Webcam);
            Characteristics.Add(char1_VideoCard);
            Characteristics.Add(char1_WorkingHours);
            Characteristics.Add(char1_Screen);
            Characteristics.Add(char1_Storage);
            Characteristics.Add(char1_RAM);
            Characteristics.Add(char1_CPU);
            //2 ASUS K50IN
            Characteristic char2_Webcam       = new Characteristic(device2.ID, characteristicType_Webcam.ID, "true");
            Characteristic char2_VideoCard    = new Characteristic(device2.ID, characteristicType_VideoCard.ID, "NVIDIA GeForce G 102M (дискретная)");
            Characteristic char2_WorkingHours = new Characteristic(device2.ID, characteristicType_WorkingHours.ID, "6");
            Characteristic char2_Screen       = new Characteristic(device2.ID, characteristicType_Screen.ID, "15,6");
            Characteristic char2_Storage      = new Characteristic(device2.ID, characteristicType_Storage.ID, "250");
            Characteristic char2_RAM          = new Characteristic(device2.ID, characteristicType_RAM.ID, "2");
            Characteristics.Add(char2_Webcam);
            Characteristics.Add(char2_VideoCard);
            Characteristics.Add(char2_WorkingHours);
            Characteristics.Add(char2_Screen);
            Characteristics.Add(char2_Storage);
            Characteristics.Add(char2_RAM);
            SaveChanges();
            #endregion
        }