Beispiel #1
0
 /// <summary>
 /// Initializes the connection.
 /// </summary>
 /// <param name="brokerAddress">The brokerAddress<see cref="string"/></param>
 /// <param name="user">The user<see cref="string"/></param>
 /// <param name="pass">The pass<see cref="string"/></param>
 /// <param name="secret">The secret<see cref="string"/></param>
 private static async Task InitBrokerConnection(string brokerAddress, string user, string pass, string secret)
 {
     try
     {
         client             = NanomiteClient.CreateGrpcClient(brokerAddress, user);
         client.OnConnected = async() =>
         {
             var subscriptionMessage = new SubscriptionMessage()
             {
                 Topic = "SetLogLevel"
             };
             await client.SendCommandAsync(subscriptionMessage, StaticCommandKeys.Subscribe);
         };
         client.OnCommandReceived = (cmd, c) =>
         {
             switch (cmd.Topic)
             {
             case "SetLogLevel":
                 var level = cmd.Data[0].CastToModel <LogLevelInfo>()?.Level;
                 LoggingLevel = (int)(LogLevel)System.Enum.Parse(typeof(LogLevel), level);
                 break;
             }
         };
         await client.ConnectAsync(user, pass, secret, true);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Beispiel #2
0
        private async void InitBrokerConnection(string brokerAddress, string clientId, string user, string pass, string secret)
        {
            try
            {
                client             = NanomiteClient.CreateGrpcClient(brokerAddress, clientId);
                client.OnConnected = async() =>
                {
                    SubscriptionMessage subscriptionMessage = new SubscriptionMessage()
                    {
                        Topic = LogLevel.Debug.ToString()
                    };
                    await client.SendCommandAsync(subscriptionMessage, StaticCommandKeys.Subscribe);

                    subscriptionMessage = new SubscriptionMessage()
                    {
                        Topic = LogLevel.Info.ToString()
                    };
                    await client.SendCommandAsync(subscriptionMessage, StaticCommandKeys.Subscribe);

                    subscriptionMessage = new SubscriptionMessage()
                    {
                        Topic = LogLevel.Warning.ToString()
                    };
                    await client.SendCommandAsync(subscriptionMessage, StaticCommandKeys.Subscribe);

                    subscriptionMessage = new SubscriptionMessage()
                    {
                        Topic = LogLevel.Error.ToString()
                    };
                    await client.SendCommandAsync(subscriptionMessage, StaticCommandKeys.Subscribe);
                };
                client.OnCommandReceived = (cmd, c) =>
                {
                    switch (cmd.Topic)
                    {
                    case "Info":
                    case "Debug":
                    case "Warning":
                    case "Error":
                        Device.BeginInvokeOnMainThread(() =>
                        {
                            var message     = cmd.Data[0].CastToModel <LogMessage>();
                            LogEditor.Text += message.Message + Environment.NewLine;
                        });
                        break;
                    }
                };
                await client.ConnectAsync(user, pass, secret, true);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }