コード例 #1
0
ファイル: Tesira.cs プロジェクト: uxav/lib2-devices
        private void ClientOnReceivedData(TtpSshClient client, TesiraMessage message)
        {
            try
            {
                JToken json;
                switch (message.Type)
                {
                case TesiraMessageType.OkWithResponse:
                    var response = message as TesiraResponse;
                    if (response == null)
                    {
                        return;
                    }
                    if (response.Command == "DEVICE get networkStatus")
                    {
                        json = response.TryParseResponse();
                        if (json != null)
                        {
                            Debug.WriteSuccess("Network Config", "\r\n" + json.ToString(Formatting.Indented));
                        }
                    }
                    break;

                case TesiraMessageType.Notification:
                    json = message.TryParseResponse();
                    if (json != null)
                    {
                        Debug.WriteSuccess(json.ToString(Formatting.Indented));
                    }
                    break;

                default:
                    break;
                }
            }
            catch (Exception e)
            {
                CloudLog.Exception(e, "Error handling received data");
            }

            if (ReceivedData == null)
            {
                return;
            }
            try
            {
                ReceivedData(client, message);
            }
            catch (Exception e)
            {
                CloudLog.Exception(e, "Error calling event handler");
            }
        }
コード例 #2
0
ファイル: Tesira.cs プロジェクト: uxav/lib2-devices
        private void ClientOnConnectionStatusChange(TtpSshClient client, TtpSshClient.ClientStatus status)
        {
            switch (status)
            {
            case TtpSshClient.ClientStatus.Connected:
                Send("DEVICE", TesiraCommand.Get, TesiraAttributeCode.NetworkStatus);
                Send("SESSION", TesiraCommand.Get, TesiraAttributeCode.Aliases);
                DeviceCommunicating = true;
                break;

            case TtpSshClient.ClientStatus.Disconnected:
                DeviceCommunicating = false;
                break;
            }
        }
コード例 #3
0
        protected virtual void OnConnectionStatusChange(TtpSshClient client, ClientStatus status)
        {
            var handler = ConnectionStatusChange;

            if (handler != null)
            {
                try
                {
                    handler(client, status);
                }
                catch (Exception e)
                {
                    CloudLog.Exception(e);
                }
            }
        }
コード例 #4
0
ファイル: TesiraBlockBase.cs プロジェクト: uxav/lib2-devices
 private void OnReceivedData(TtpSshClient client, TesiraMessage message)
 {
     if (message.Type != TesiraMessageType.Notification && message.Id == InstanceTag)
     {
         var response = message as TesiraResponse;
         if (response != null && response.Type == TesiraMessageType.OkWithResponse)
         {
             Debug.WriteSuccess(GetType().Name + " \"" + InstanceTag + "\"", "Received {0}\r\n{1}",
                                response.AttributeCode, response.TryParseResponse().ToString(Formatting.Indented));
             ReceivedResponse(response);
         }
     }
     else if (message.Type == TesiraMessageType.Notification && Subscriptions.ContainsKey(message.Id))
     {
         var response = message as TesiraNotification;
         if (response != null)
         {
             Debug.WriteSuccess(GetType().Name + " \"" + InstanceTag + "\"", "Received notification \"{0}\"\r\n{1}",
                                Subscriptions[message.Id], response.TryParseResponse().ToString(Formatting.Indented));
             ReceivedNotification(Subscriptions[message.Id], response.TryParseResponse());
         }
     }
 }
コード例 #5
0
ファイル: Tesira.cs プロジェクト: uxav/lib2-devices
 public Tesira(string address, string username, string password)
 {
     _client = new TtpSshClient(address, username, password);
     _client.ReceivedData           += ClientOnReceivedData;
     _client.ConnectionStatusChange += ClientOnConnectionStatusChange;
 }