Esempio n. 1
0
        private ClientStatusModel UnboxMsg(string msg)
        {
            ClientStatusModel clientStatusModel = new ClientStatusModel();
            string            tempMsg           = msg;

            //if (tempMsg.IndexOf(CommonFlag.F_IP) >= 0)
            //{
            //    clientStatusModel.Recive_IP = tempMsg.Substring(tempMsg.IndexOf(CommonFlag.F_IP) + CommonFlag.F_IP.Length, tempMsg.IndexOf(";", tempMsg.IndexOf(CommonFlag.F_IP)) - tempMsg.IndexOf(CommonFlag.F_IP) - CommonFlag.F_IP.Length);
            //    tempMsg = tempMsg.Replace(CommonFlag.F_IP + clientStatusModel.Recive_IP + ";", "");
            //}

            if (tempMsg.IndexOf(CommonFlag.F_Port) >= 0)
            {
                clientStatusModel.Recive_Port = Convert.ToInt32(tempMsg.Substring(tempMsg.IndexOf(CommonFlag.F_Port) + CommonFlag.F_Port.Length, tempMsg.IndexOf(";", tempMsg.IndexOf(CommonFlag.F_Port)) - tempMsg.IndexOf(CommonFlag.F_Port) - CommonFlag.F_Port.Length));
                tempMsg = tempMsg.Replace(CommonFlag.F_Port + clientStatusModel.Recive_Port.ToString() + ";", "");
            }

            if (tempMsg.IndexOf(CommonFlag.F_ObjectID) >= 0)
            {
                clientStatusModel.ObjectID = tempMsg.Substring(tempMsg.IndexOf(CommonFlag.F_ObjectID) + CommonFlag.F_ObjectID.Length, tempMsg.IndexOf(";", tempMsg.IndexOf(CommonFlag.F_ObjectID)) - tempMsg.IndexOf(CommonFlag.F_ObjectID) - CommonFlag.F_ObjectID.Length);
                tempMsg = tempMsg.Replace(CommonFlag.F_ObjectID + clientStatusModel.ObjectID.ToString(), "");
            }

            return(clientStatusModel);
        }
        public static IServiceCollection AddMqttClient(this IServiceCollection services, MqttClientOptions options)
        {
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            if (options.SharpLimit && options.Subscribers.Any(x => x.Topic?.Contains("#") == true))
            {
                throw new ArgumentException("不能以通配符'#'订阅任何主题");
            }

            if (options.WillMessage == null)
            {
                options.WillMessage = new MqttMessageBuilder()
                                      .WithTopic(new ClientStatusTopic(options.ClientId))
                                      .WithPayload(ClientStatusModel.Create(options.ClientId, false))
                                      .WithRetainFlag(!options.CleanSession)
                                      .Build();
            }

            services
            .AddSingleton <IMqttClientOptions>(options)
            .AddM2MqttClient();
            //.AddMqttnetClient(clientId, host, port, cleanSession)

            return(services);
        }
Esempio n. 3
0
 static object Map(ClientStatusModel model)
 {
     return(new
     {
         type = model.Type.ToString("g").ToLower(),
         message = model.Message
     });
 }
Esempio n. 4
0
        public static void AddCurrentClients(ClientStatusModel clientStatusModel)
        {
            if (Singleton <Dictionary <string, ClientStatusModel> > .Instance == null)
            {
                Singleton <Dictionary <string, ClientStatusModel> > .Instance = new Dictionary <string, ClientStatusModel>();
            }



            lock (Singleton <Dictionary <string, ClientStatusModel> > .Instance)
            {
                if (Singleton <Dictionary <string, ClientStatusModel> > .Instance.ContainsKey(clientStatusModel.ObjectID))
                {
                    Singleton <Dictionary <string, ClientStatusModel> > .Instance[clientStatusModel.ObjectID] = clientStatusModel;
                }
                else
                {
                    Singleton <Dictionary <string, ClientStatusModel> > .Instance.Add(clientStatusModel.ObjectID, clientStatusModel);
                }
            }
        }
        public static IServiceCollection AddMqttClient(this IServiceCollection services, string clientId, string host, int?port = null, bool cleanSession = true, params TopicSubscriber[] topics)
        {
            services
            .AddMqttClient(new MqttClientOptions()
            {
                Host            = host,
                Port            = port ?? 1883,
                CleanSession    = cleanSession,
                ClientId        = clientId,
                KeepAlivePeriod = TimeSpan.FromSeconds(15),
                WillMessage     = new MqttMessageBuilder()
                                  .WithTopic(new ClientStatusTopic(clientId))
                                  .WithPayload(ClientStatusModel.Create(clientId, false))
                                  .WithRetainFlag(!cleanSession)
                                  .Build(),
                Subscribers = topics ?? new TopicSubscriber[] { },
                SharpLimit  = false
            })
            ;

            return(services);
        }
Esempio n. 6
0
 public async Task ExecuteAsync(ClientStatusModel model)
 {
     _clients.Client(model.Id).Status(Map(model));
 }
 internal DiscordClientStatus(ClientStatusModel model)
 {
     Desktop = model.Desktop;
     Mobile  = model.Mobile;
     Web     = model.Web;
 }