Пример #1
0
        /// <summary>
        /// Lists the devices comissioned in OCTAVE
        /// </summary>
        /// <returns>An OC_Device instance</returns>
        public LW_Device GetOvtaveDevices()
        {
            try
            {
                //var responseContent = -1;
                var      OB      = new OC_Broker();
                OC_Utils OCU     = new OC_Utils();
                string   fullURL = "https://octave-api.sierrawireless.io/v5.0/<company_name>/device/?only=id,name,avSystemId,blueprintId,localVersions,location,hardware,creationDate,displayName";
                fullURL = fullURL.Replace("<company_name>", this._OctaveCompany);
                string baseAddress = fullURL;

                // We create an empty lw_device with unknown name and ID to trace
                var retDevice = new LW_Device("Unknown", "Unknown", "Unknown");

                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(baseAddress);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Add("X-Auth-Token", this._OctaveToken);
                    client.DefaultRequestHeaders.Add("X-Auth-User", this._OctaveUser);

                    var response_ = client.GetAsync("").Result;
                    if (response_.IsSuccessStatusCode)
                    {
                        OC_Device resOK = response_.Content.ReadAsAsync <OC_Device>().Result;
                        if (resOK.Head.Status == 200)
                        {
                            OC_Device Device  = new OC_Device();
                            LW_Device gDevice = new LW_Device();
                            // We populate the data fields of our lw_device with the data obtained from OCTAVE
                            gDevice.DeviceName   = resOK.Body.First().Name;
                            gDevice.DeviceId     = resOK.Body.First().Id;
                            gDevice.SerialNumber = resOK.Body.First().Hardware.Fsn;
                            gDevice.VisibleName  = OCU.UnixTimeStampToDateTime(resOK.Body.First().CreationDate).ToShortDateString();
                            gDevice.IsActive     = true;

                            return(gDevice);
                        }
                        else
                        {
                            return(retDevice);
                        }
                    }
                    else
                    {
                        return(retDevice);
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to load a device from octave, method = GetOctaveDevices", ex);
            }
        }
Пример #2
0
        /// <summary>
        /// Fetches the dataset from the DB with the device table info for a device based on the octave ID
        /// </summary>
        /// <param name="Status">Octave Devie ID</param>
        /// <returns></returns>
        public LW_Device[] GetDevicesByStatus(int Status)
        {
            var    _DB_cnx_String = _Sett.cnxString;
            string sql            = "SELECT * FROM Devices WHERE Status = " + Status;
            var    connection     = new SqlConnection(_DB_cnx_String);
            {
                var DS_Device = connection.Query(sql);
                if (DS_Device.Count() > 0)
                {
                    LW_Device[] DVS = new LW_Device[DS_Device.Count()];
                    {
                        int Pos = 0;
                        foreach (var Dev in DS_Device)
                        {
                            LW_Device Device = new LW_Device();
                            Device.ID            = Dev.Id;
                            Device.Blueprint     = Dev.Blueprint;
                            Device.CreationDate  = Dev.CreationDate;
                            Device.CurrentStatus = Status;
                            Device.DeviceId      = Dev.DeviceId;
                            Device.DeviceName    = Dev.DeviceName;
                            Device.IMEI          = Dev.IMEI;
                            Device.IsActive      = Dev.IsActive;
                            Device.SerialNumber  = Dev.SerialNumber;
                            DVS.SetValue(Device, Pos);

                            Pos++;
                        }
                    };
                    LW_Devices DeviceList = new LW_Devices(DVS);

                    return(DVS);
                }
                else
                {
                    throw new Exception("Devices not loaded");
                    //return DVS;
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Lists the devices comissioned in OCTAVE
        /// </summary>
        /// <returns>An OC_Device instance</returns>
        public async System.Threading.Tasks.Task <string> CreateNewOvtaveDevicesAsync(string Name, string IMEI, string SerialNumber)
        {
            try
            {
                //var responseContent = -1;
                var      OB      = new OC_Broker();
                OC_Utils OCU     = new OC_Utils();
                string   fullURL = "https://octave-api.sierrawireless.io/v5.0/<company_name>/device/provision";
                fullURL = fullURL.Replace("<company_name>", this._OctaveCompany);
                string baseAddress = fullURL;

                // We create an empty lw_device with unknown name and ID to trace
                var retDevice = new LW_Device("Unknown", "Unknown", "Unknown");
                retDevice.DeviceName   = Name;
                retDevice.IMEI         = IMEI;
                retDevice.SerialNumber = SerialNumber;

                using (var client = new HttpClient())
                {
                    client.BaseAddress = new Uri(baseAddress);
                    client.DefaultRequestHeaders.Accept.Clear();
                    client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                    client.DefaultRequestHeaders.Add("X-Auth-Token", this._OctaveToken);
                    client.DefaultRequestHeaders.Add("X-Auth-User", this._OctaveUser);

                    var values = new Dictionary <string, string>
                    {
                        { "name", retDevice.DeviceName },
                        { "imei", retDevice.IMEI },
                        { "fsn", retDevice.SerialNumber },
                    };

                    var json          = JsonConvert.SerializeObject(values, Formatting.Indented);
                    var stringContent = new StringContent(json);
                    //    return Ok(responseString);

                    var response_ = await client.PostAsync(baseAddress, stringContent);

                    var responseString = await response_.Content.ReadAsStringAsync();

                    if (response_.IsSuccessStatusCode)
                    {
                        var resOK = response_.Content.ReadAsAsync <OC_ProvisionResult>().Result;
                        if (resOK.Head.Status == 200)
                        {
                            OC_ProvisionResult Device  = new OC_ProvisionResult();
                            OC_ProvisionResult gDevice = new OC_ProvisionResult();
                            // We populate the data fields of our lw_device with the data obtained from OCTAVE
                            gDevice.Head.Status = resOK.Head.Status;
                            //gDevice.Head.Errors.First() = resOK.Head.Errors.First();
                            //gDevice.SerialNumber = resOK.Body.First().Hardware.Fsn;
                            //gDevice.VisibleName = OCU.UnixTimeStampToDateTime(resOK.Body.First().CreationDate).ToShortDateString();
                            //gDevice.IsActive = true;

                            return(gDevice.Head.Status.ToString());
                        }
                        else
                        {
                            OC_ProvisionResult Device  = new OC_ProvisionResult();
                            OC_ProvisionResult gDevice = new OC_ProvisionResult();
                            // We populate the data fields of our lw_device with the data obtained from OCTAVE
                            gDevice.Head.Status = resOK.Head.Status;
                            //gDevice.Head.Errors.First() = resOK.Head.Errors.First();
                            //gDevice.SerialNumber = resOK.Body.First().Hardware.Fsn;
                            //gDevice.VisibleName = OCU.UnixTimeStampToDateTime(resOK.Body.First().CreationDate).ToShortDateString();
                            //gDevice.IsActive = true;

                            return(responseString.ToString());
                        }
                    }
                    else
                    {
                        return(response_.RequestMessage.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                throw new Exception("Unable to load a device from octave, method = GetOctaveDevices", ex);
            }
        }
 public LW_Device(LW_Device device)
 {
     this.device = device;
 }