Esempio n. 1
0
        /// <summary>
        /// 向服务器报告自己软件信息,使用UDP
        /// </summary>
        public static void ReportInfo()
        {
            MsgObj msg = new MsgObj("pc", Environment.MachineName, MyInfo.myMAC, ConvertDateTimeInt(DateTime.Now));

            Thread t = new Thread(new ThreadStart(delegate() {
                while (true)
                {
                    try
                    {
                        IPAddress remoteIP     = IPAddress.Parse(ConfigResource.SERVER_2_IP); //假设发送给这个IP
                        IPEndPoint remotePoint = new IPEndPoint(remoteIP, ConfigResource.SERVER_2_PORT);
                        UdpClient client       = new UdpClient();
                        byte[] sendData        = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(msg)); //要发送的字节数组
                        client.Send(sendData, sendData.Length, remotePoint);                               //将数据发送到远程端点
                        log.InfoFormat("向服务器 {0}汇报消息成功", ConfigResource.SERVER_2_IP);
                        client.Close();                                                                    //关闭连接
                    }
                    catch (Exception e)
                    {
                        log.Error("向服务器汇报消息失败", e);
                    }
                    Thread.Sleep(1000 * 60 * 20);
                }
            }));

            t.IsBackground = true;
            t.Start();
        }
        public void msgReceivedHandler(MsgObj msg, String deviceId, string payload)
        {
            eMsgType type = msg.mType;

            switch (type)
            {
            case eMsgType.Meausurements:
                Console.WriteLine($"Got Measurement msg from device ID: '{deviceId}'");
                break;

            case eMsgType.BTscan:
                Console.WriteLine($"Got BT scan msg from device ID: '{deviceId}'");
                break;

            case eMsgType.MeasurementsAndBT:
                Console.WriteLine($"Got Measurement and BT scan msg from device ID: '{deviceId}'");
                break;

            default:
                Console.WriteLine("ERROR - message is of unknown Type");
                break;
            }

            //MsgReceivedEvent.OnMsgReceived(msg); // Raise event msgReceived
            //GetAsync(Configs.AZURE_WEB_API + @"/Device/msg_handler").Wait(); // try call controller
            Post(Configs.AZURE_WEB_API + @"/Device/msg_handler", "=" + payload, "application/x-www-form-urlencoded");
        }
Esempio n. 3
0
 public PushMessage(string[] platform, string fromuserid, TagObj audience, MsgObj message, Notification notification)
 {
     Platform     = platform;
     Fromuserid   = fromuserid;
     Audience     = audience;
     Message      = message;
     Notification = notification;
 }
Esempio n. 4
0
 public IActionResult msg_handler(string payload)
 {
     if (payload != null)
     {
         MsgObj msg = JsonConvert.DeserializeObject <MsgObj>(payload);
         dbManager.LogInDB(msg);
         alarm.msgReceived_handler(msg);
         return(Ok("Msg transfered...")); // TODO - change to logger
     }
     return(Ok("Payload null."));
 }
Esempio n. 5
0
 void BroadcastHandler(byte[] data)
 {
     if (state != SceneState.Title)
     {
         MsgObj msgObj = MessagePackSerializer.Deserialize <MsgObj>(data);
         if (chatUI != null)
         {
             chatUI.Log(msgObj.Team, msgObj.Msg);
         }
     }
 }
Esempio n. 6
0
File: Msg.cs Progetto: orapow/x.yc
 public static MsgObj Get(string tk_xml, string sign, string nonce, string timestamp)
 {
     try
     {
         var xml = Crypt.DecryptMsg(Open.appid, sign, timestamp, nonce, tk_xml);
         var obj = new MsgObj(xml);
         return(obj);
     }
     catch (WxExcep wex)
     {
         Loger.Error(wex);
         return(null);
     }
 }
        public Task ProcessEventsAsync(PartitionContext context, IEnumerable <EventData> messages)
        {
            Console.WriteLine($"Batch of events received on partition '{context.PartitionId}'.");

            foreach (var eventData in messages)
            {
                var payload = Encoding.ASCII.GetString(eventData.Body.Array,
                                                       eventData.Body.Offset,
                                                       eventData.Body.Count);

                var deviceId = eventData.SystemProperties["iothub-connection-device-id"];

                Console.WriteLine($"Message received on partition '{context.PartitionId}', " +
                                  $"device ID: '{deviceId}', " +
                                  $"payload: '{payload}'");


                MsgObj msg = JsonConvert.DeserializeObject <MsgObj>(payload);
                msgReceivedHandler(msg, (String)deviceId, payload);
            }
            return(context.CheckpointAsync());
        }
Esempio n. 8
0
 public void LogInDB(MsgObj msg)
 {
     context.Msg.Add(msg);
     context.SaveChanges();
 }