Esempio n. 1
0
 /// <summary>
 /// Initializes all device properties.
 /// </summary>
 /// <param name="id">Device unique identifier (device-assigned).</param>
 /// <param name="key">Device key. Device key is a private value used for device authentication in DeviceHive.</param>
 /// <param name="name">Device name.</param>
 /// <param name="status">Device status.</param>
 /// <param name="network">Associated device network object.</param>
 /// <param name="deviceClass">Associated device class object.</param>
 public Device(Guid? id, string key, string name, string status, Network network, DeviceClass deviceClass)
 {
     Id = id;
     Key = key;
     Name = name;
     Status = status;
     Network = network;
     DeviceClass = deviceClass;
 }
Esempio n. 2
0
 /// <summary>
 /// Initializes all device properties.
 /// </summary>
 /// <param name="id">Device unique identifier (device-assigned).</param>
 /// <param name="key">Device key. Device key is a private value used for device authentication in DeviceHive.</param>
 /// <param name="name">Device name.</param>
 /// <param name="status">Device status.</param>
 /// <param name="data">Device data, an optional json token used to describe additional device information.</param>
 /// <param name="network">Associated device network object (optional).</param>
 /// <param name="deviceClass">Associated device class object.</param>
 public Device(string id, string key, string name, string status, JToken data, Network network, DeviceClass deviceClass)
     : this(id, key)
 {
     Name        = name;
     Status      = status;
     Data        = data;
     Network     = network;
     DeviceClass = deviceClass;
 }
Esempio n. 3
0
        private void RegisterDevice(DeviceBase device)
        {
            Logger.InfoFormat("Registering device {0} ({1})", device.ID, device.Name);

            try
            {
                var cDeviceClass = new DeviceClass(device.ClassName, device.ClassVersion, device.ClassOfflineTimeout,
                                                   device.ClassData == null ? null : JToken.FromObject(device.ClassData, device.JsonSerializer));
                var cDevice = new Device(device.ID, device.Key, device.Name, device.Status,
                                         device.Data == null ? null : JToken.FromObject(device.Data, device.JsonSerializer), Network, cDeviceClass);
                cDevice.Equipment = device.EquipmentInfo.Select(e => new Equipment(
                                                                    e.Name, e.Code, e.Type, e.Data == null ? null : JToken.FromObject(e.Data, device.JsonSerializer))).ToList();
                DeviceClient.RegisterDevice(cDevice);
            }
            catch (Exception ex)
            {
                // critical error - log and fault the service
                Logger.Error(string.Format("Exception while registering device {0} ({1}), rethrowing exception", device.ID, device.Name), ex);
                throw;
            }
        }
        private void RegisterDevice(DeviceBase device)
        {
            Logger.InfoFormat("Registering device {0} ({1})", device.ID, device.Name);

            try
            {
                var cDeviceClass = new DeviceClass(device.ClassName, device.ClassVersion, device.ClassOfflineTimeout,
                    device.ClassData == null ? null : JToken.FromObject(device.ClassData, device.JsonSerializer));
                var cDevice = new Device(device.ID, device.Key, device.Name, device.Status,
                    device.Data == null ? null : JToken.FromObject(device.Data, device.JsonSerializer), Network, cDeviceClass);
                cDevice.Equipment = device.EquipmentInfo.Select(e => new Equipment(
                    e.Name, e.Code, e.Type, e.Data == null ? null : JToken.FromObject(e.Data, device.JsonSerializer))).ToList();
                DeviceClient.RegisterDevice(cDevice);
            }
            catch (Exception ex)
            {
                // critical error - log and fault the service
                Logger.Error(string.Format("Exception while registering device {0} ({1}), rethrowing exception", device.ID, device.Name), ex);
                throw;
            }
        }
Esempio n. 5
0
 /// <summary>
 /// Initializes all device properties.
 /// </summary>
 /// <param name="id">Device unique identifier (device-assigned).</param>
 /// <param name="key">Device key. Device key is a private value used for device authentication in DeviceHive.</param>
 /// <param name="name">Device name.</param>
 /// <param name="status">Device status.</param>
 /// <param name="data">Device data, an optional json token used to describe additional device information.</param>
 /// <param name="network">Associated device network object (optional).</param>
 /// <param name="deviceClass">Associated device class object.</param>
 public Device(Guid? id, string key, string name, string status, JToken data, Network network, DeviceClass deviceClass)
     : this(id, key)
 {
     Name = name;
     Status = status;
     Data = data;
     Network = network;
     DeviceClass = deviceClass;
 }