Ejemplo n.º 1
0
        /// <summary>
        /// 获取Iot
        /// </summary>
        /// <param name="id">Iot Id</param>
        public IIot GetIot(Guid id)
        {
            if (!_dicIotClients.TryGetValue(id, out IotClient client))
            {
                byte[] byteId = id.ToByteArray();
                uint   typeId = BitConverter.ToUInt32(byteId, 0);

                if (!_dicIotTypes.TryGetValue(typeId, out Func <Guid, IIot> clientConstructor))
                {
                    return(null);
                }

                client = new IotClient()
                {
                    Iot = clientConstructor.Invoke(id)
                };
                lock (_dicIotClients)
                {
                    _dicIotClients.Add(id, client);
                }
            }

            client.Lifetime = DateTime.Now.AddMinutes(10.0);
            return(client.Iot);
        }
Ejemplo n.º 2
0
        public Storage(IotClient client)
        {
            this.Data    = new Dictionary <string, List <string> >();
            this.Station = new StationStorage();

            this.IotClient = client;
        }
Ejemplo n.º 3
0
        public JsonResult UpdateShadow(string deviceId, string[] jsonContent)
        {
            try
            {
                var deviceShadow = IotClient.UpdateShadowRaw(deviceId, jsonContent);
                return(Json(deviceShadow));
            }
            catch (Exception ex)
            {
                Console.WriteLine("JsonResult UpdateShadow " + ex);
            }

            return(Json(""));
        }
Ejemplo n.º 4
0
        public JsonResult GetShadow(string deviceId)
        {
            try
            {
                var deviceShadow = IotClient.GetShadowRaw(deviceId);
                return(Json(deviceShadow));
            }
            catch (Exception ex)
            {
                Console.WriteLine("JsonResult GetShadow " + ex);
            }

            return(Json(""));
        }