Exemplo n.º 1
0
        public async static Task <bool> PullDataFromCloud()
        {
            Pull pull = new Pull();
            await pull.PullAppData();

            await pull.PullDevData();

            await pull.PullFileData();

            await pull.PullInitData();

            await pull.PullProgramData();

            await pull.PullReviewData();

            await pull.PullShopInfoData();

            await pull.PullSystemData();;

            return(true);
        }
Exemplo n.º 2
0
        async void MessageReceived(string msg)
        {
            try
            {
                log.WriteLogToFile("IOTMsg", msg, 0);
                //  log.WriteLogToFile(msg, "WebSocketLog");

                string type = "";
                Dictionary <string, Object> dic = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, Object> >(msg.ToLower());
                if (dic["content"] != null && dic["senderid"] != null)
                {
                    Dictionary <string, Object> Commands = JsonConvert.DeserializeObject <Dictionary <string, Object> >(dic["content"].ToString());

                    if (!string.IsNullOrEmpty(Commands["type"].ToString()))
                    {
                        type = Commands["type"].ToString();
                    }

                    switch (type.Trim())
                    {
                    case "dataupdate":
                        log.WriteLogToFile("云端数据更新", "WebSocketLog");
                        if (!string.IsNullOrEmpty(Commands["modulename"].ToString()))
                        {
                            Pull pull = new Pull();
                            switch (Commands["modulename"].ToString().Trim())
                            {
                            case "app":
                                await pull.PullAppData();

                                break;

                            case "dev":
                                await pull.PullDevData();

                                break;

                            case "file":
                                await pull.PullFileData();

                                break;

                            case "init":
                                await pull.PullInitData();

                                break;

                            case "prog":
                                await pull.PullProgramData();

                                break;

                            case "review":
                                await pull.PullReviewData();

                                break;

                            case "shopinfo":
                                await pull.PullShopInfoData();

                                break;

                            case "system":
                                await pull.PullSystemData();

                                break;

                            default:
                                break;
                            }
                        }
                        break;

                    case "devicecommand":
                        DbContextOptions <ContextString> options = new DbContextOptions <ContextString>();
                        ContextString dbContext = new ContextString(options);
                        log.WriteLogToFile("设备命令", "WebSocketLog");
                        if (!string.IsNullOrEmpty(Commands["devicecode"].ToString()) && !string.IsNullOrEmpty(Commands["cmdstr"].ToString()) && !string.IsNullOrEmpty(Commands["msgtype"].ToString()))
                        {
                            var         devicecode  = Commands["devicecode"].ToString();
                            var         cmdstr      = Commands["cmdstr"].ToString();
                            var         msgtype     = Commands["msgtype"].ToString();
                            MsgTemplate msgTemplate = new MsgTemplate();
                            // var dev = dbContext.Device.Where(i => i.Code == devicecode).FirstOrDefault();
                            //if (dev != null)
                            //{
                            msgTemplate.SenderID    = Method.ServerAddr;
                            msgTemplate.MessageType = msgtype;
                            msgTemplate.Content     = cmdstr;
                            msgTemplate.ReceiverID  = devicecode;
                            await Method.SendMsgAsync(msgTemplate);

                            // }
                        }
                        break;

                    default:
                        break;
                    }
                }
                if (WebSocketReceiveEvent != null)
                {
                    WebSocketReceiveEvent(type, "");
                }
            }
            catch (Exception ex)
            {
                //  log.WriteLogToFile(ex.ToString(), "WebSocketLog");
                log.WriteLogToFile("IOTMsg", ex.ToString(), 0);
            }
        }