// -- Debug -- // #endif public SCONClient(ITCPClient clientWrapper, ModuleSCON server) { Stream = new ProtobufStream(clientWrapper); Module = server; AuthorizationStatus = (EncryptionEnabled ? AuthorizationStatus.EncryprionEnabled : 0); }
public TcpShutterControl(ITCPClient tcpClient) { _tcpClient = tcpClient; InitializeComponent(); TcpButtonControl(); }
public async Task StopAsync() { lock (_msgSendTimers) { if (Status != null && !Status.IsRunning) { return; } foreach (var tmr in _msgSendTimers) { tmr.Change(Timeout.Infinite, Timeout.Infinite); tmr.Dispose(); } _msgSendTimers.Clear(); _receiveTaskCancelTokenSource?.Cancel(); _receiveTaskCancelTokenSource = null; } switch (_simulator.DefaultTransport.Value) { case TransportTypes.MQTT: DisconnectMQTT(); break; case TransportTypes.AzureIoTHub: await DisconnectAzureIoTHubAsync(); break; case TransportTypes.TCP: _tcpClient?.DisconnectAsync(); _tcpClient.Dispose(); _tcpClient = null; break; case TransportTypes.UDP: await _udpClient?.DisconnectAsync(); _udpClient.Dispose(); _udpClient = null; break; } Status = new SimulatorStatus() { IsRunning = false, Text = "Stopped" }; await _notificationPublisher.PublishAsync(Targets.WebSocket, Channels.Simulator, InstanceId, $"Simulator Stopped", CurrentState); await _notificationPublisher.PublishAsync(Targets.WebSocket, Channels.Simulator, InstanceId, $"Status Update", Status); }
public SCONClient(ITCPClient client, SCONListener sconListener) { Client = client; Stream = new ProtobufStream(Client); _listener = sconListener; AuthorizationStatus = AuthorizationStatus.RemoteClientEnabled; }
public BouncyCastleAes(ITCPClient tcp, byte[] key) { Stream = tcp.GetStream(); EncryptCipher = new BufferedBlockCipher(new CfbBlockCipher(new AesFastEngine(), 8)); EncryptCipher.Init(true, new ParametersWithIV(new KeyParameter(key), key, 0, 16)); DecryptCipher = new BufferedBlockCipher(new CfbBlockCipher(new AesFastEngine(), 8)); DecryptCipher.Init(false, new ParametersWithIV(new KeyParameter(key), key, 0, 16)); }
public HomeComingPageViewModel(ITCPClient tcpClient, INanoLeafClient nanoLeafClient, IDimScreenService dimScreen) //public HomeComingPageViewModel() { _tcpClient = tcpClient; _nanoLeafClient = nanoLeafClient; _dimScreen = dimScreen; // Create the command - calls Do...Commands. homeComingOnCommand = new Command(DoHomeComingOnCommand); homeComingOffCommand = new Command(DoHomeComingOffCommand); lightUpScreenCommand = new Command(DoLightUpScreenCommand); }
public void Run(IPAddress address, int port) { try{ _TCPClient = new TCPClient(address, port); _TCPClient.Connect(); _TCPClient.RecieveDataEvent += RecieveResponse; }catch (SocketException) { _TCPClient.Dispose(); throw new CRClientException("Cant connect to server with this ip:" + address.ToString()); } catch (TCPProtocolException exc) { _TCPClient.Dispose(); throw new CRClientException("Cant connect to server with this ip:" + address.ToString(), exc); } }
public TvRemoteControl(ITCPClient tcpClient) { _tcpClient = tcpClient; InitializeComponent(); foreach (var element in TcpSettings.IrCommandDictionary) { var newbutton = new TcpButton { Text = element.Value.Name, Address = TcpSettings.IpAddress[0], IrCommand = element.Value.Ir.IrCommand, Row = element.Value.Row, Column = element.Value.Column }; newbutton.Clicked += HandlerButtonClicked; TvButtonGrid.Children.Add(newbutton, newbutton.Column, newbutton.Row); } }
public MySimulatorModel(ITCPClient tcpClient) { _queueCommand = new BlockingCollection <AsyncCommand>(); this.client = tcpClient; Start(); }
public MainPage(ITCPClient tcpClient) { InitializeComponent(); //TcpLightControl = new Contorls.TcpSwitchControl(tcpClient); }
public async void Connect() { try { IsBusy = true; switch (Model.DefaultTransport.Value) { /* case TransportTypes.AMQP: * { * var connectionString = $"Endpoint=sb://{Model.DefaultEndPoint}.servicebus.windows.net/;SharedAccessKeyName={Model.AccessKeyName};SharedAccessKey={Model.AccessKey}"; * var bldr = new EventHubsConnectionStringBuilder(connectionString) * { * EntityPath = Model.HubName * }; * * _isConnected = true; * } * * break;*/ case TransportTypes.AzureIoTHub: #if IOTHUB var connectionString = $"HostName={Model.DefaultEndPoint};DeviceId={Model.DeviceId};SharedAccessKey={Model.AccessKey}"; _azureIoTHubClient = DeviceClient.CreateFromConnectionString(connectionString, Microsoft.Azure.Devices.Client.TransportType.Amqp_Tcp_Only); await _azureIoTHubClient.OpenAsync(); ReceivingTask = Task.Run(ReceiveDataFromAzure); SetConnectedState(); #endif break; case TransportTypes.MQTT: _mqttClient = SLWIOC.Create <IMQTTDeviceClient>(); _mqttClient.ShowDiagnostics = true; _mqttClient.BrokerHostName = Model.DefaultEndPoint; _mqttClient.BrokerPort = Model.DefaultPort; _mqttClient.DeviceId = Model.UserName; _mqttClient.Password = Model.Password; var result = await _mqttClient.ConnectAsync(); if (result.Result == ConnAck.Accepted) { _isConnected = true; if (!String.IsNullOrEmpty(Model.Subscription)) { var subscription = new MQTTSubscription() { Topic = Model.Subscription.Replace("~deviceid~", Model.DeviceId), QOS = EntityHeader <QOS> .Create(QOS.QOS2) }; await _mqttClient.SubscribeAsync(subscription); _mqttClient.MessageReceived += _mqttClient_CommandReceived; } SetConnectedState(); } else { await Popups.ShowAsync($"{Resources.SimulatorCoreResources.Simulator_ErrorConnecting}: {result.Result.ToString()}"); } break; case TransportTypes.TCP: _tcpClient = SLWIOC.Create <ITCPClient>(); await _tcpClient.ConnectAsync(Model.DefaultEndPoint, Model.DefaultPort); StartReceiveThread(); SetConnectedState(); break; case TransportTypes.UDP: _udpClient = SLWIOC.Create <IUDPClient>(); await _udpClient.ConnectAsync(Model.DefaultEndPoint, Model.DefaultPort); StartReceiveThread(); SetConnectedState(); break; } RightMenuIcon = Client.Core.ViewModels.RightMenuIcon.None; } catch (Exception ex) { Debug.WriteLine(ex.Message); await Popups.ShowAsync(ex.Message); if (_mqttClient != null) { _mqttClient.Dispose(); _mqttClient = null; } #if IOTHUB if (_azureIoTHubClient != null) { await _azureIoTHubClient.CloseAsync(); _azureIoTHubClient.Dispose(); _azureIoTHubClient = null; } #endif if (_tcpClient != null) { await _tcpClient.DisconnectAsync(); _tcpClient.Dispose(); _tcpClient = null; } if (_udpClient != null) { await _udpClient.DisconnectAsync(); _udpClient.Dispose(); _udpClient = null; } SetDisconnectedState(); } finally { IsBusy = false; } }
// -- Debug -- // #endif public ProtobufPlayer(ITCPClient client, ServerProxy proxy) { Client = client; Stream = new ProtobufOriginStream(Client); _proxy = proxy; }
public AutoPilotModel() { client = MyTCPClient.Instance; }
public RollerShutterPageViewModel(ITCPClient tcpClient) { TcpShutterControl = new TcpShutterControl(tcpClient); }
public ScreenshotController(ITCPClient client, IOptions <DataOfServer> options) { dataOfServer = options.Value; tcpClient = client; tcpClient.Connect(dataOfServer.Ip, dataOfServer.Port); }
public void StartCommandsChannel() { client = MyTCPClient.Instance; client.Connect(); }
public LightsPageViewModel(ITCPClient tcpClient, INanoLeafClient nanoLeafClient) { TcpLightControl = new Contorls.TcpSwitchControl(tcpClient); TcpLedControl = new Contorls.TcpLedControl(tcpClient); NanoLeafControl = new Contorls.NanoLeafControl(nanoLeafClient); }
public JoystickModel() { client = MyTCPClient.Instance; }
public ClientConnectEvent(ITCPClient Client) { ConnectedClient = Client; }
// -- Debug -- // #endif public P3DPlayer(ITCPClient client, ServerProxy proxy) { Client = client; Stream = new P3DStream(Client); _proxy = proxy; }
public TcpLedControl(ITCPClient tcpClient) { //_Num = Num; _tcpClient = tcpClient; InitializeComponent(); Label header = new Label { FontSize = Device.GetNamedSize(NamedSize.Large, typeof(Label)), HorizontalOptions = LayoutOptions.Center }; Picker picker = new Picker { Title = "Color", VerticalOptions = LayoutOptions.CenterAndExpand }; StackLayout switches = new StackLayout { Orientation = StackOrientation.Horizontal }; int count = 0; foreach (var element in TcpSettings.TcpLedDeviceList) { var newLabel = new Label { Text = element.Name }; var newSwitch = new LedSwitch { index = count }; newSwitch.Toggled += HandlerSwitchToggeled; switches.Children.Add(newLabel); switches.Children.Add(newSwitch); count++; } foreach (string colorName in nameToColor.Keys) { picker.Items.Add(colorName); } // Create BoxView for displaying picked Color BoxView boxView = new BoxView { WidthRequest = 150, HeightRequest = 150, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.CenterAndExpand }; picker.SelectedIndexChanged += (sender, args) => { if (picker.SelectedIndex == -1) { boxView.Color = Color.Default; } else { string colorName = picker.Items[picker.SelectedIndex]; boxView.Color = nameToColor[colorName]; foreach (var element in TcpSettings.TcpLedDeviceList) { if (element.aktive == true) { _tcpClient.SendTcpCommand(element.Address, boxView.Color.R * 255, boxView.Color.G * 255, boxView.Color.B * 255); } } } }; GridTcp.Children.AddVertical(header); GridTcp.Children.AddVertical(picker); GridTcp.Children.AddVertical(boxView); GridTcp.Children.AddVertical(switches); //// Build the page. //this.Content = new StackLayout //{ // Children = // { // header, // picker, // boxView, // switches // } //}; }
public async Task <InvokeResult> ConnectAsync() { try { IsBusy = true; switch (_simulator.DefaultTransport.Value) { /* case TransportTypes.AMQP: * { * var connectionString = $"Endpoint=sb://{Model.DefaultEndPoint}.servicebus.windows.net/;SharedAccessKeyName={Model.AccessKeyName};SharedAccessKey={Model.AccessKey}"; * var bldr = new EventHubsConnectionStringBuilder(connectionString) * { * EntityPath = Model.HubName * }; * * _isConnected = true; * } * * break;*/ case TransportTypes.AzureIoTHub: await ConnectAzureIoTHubAsync(); break; case TransportTypes.MQTT: await MQTTConnectAsync(); break; case TransportTypes.TCP: await _notificationPublisher.PublishTextAsync(Targets.WebSocket, Channels.Simulator, InstanceId, $"Connecting to {_simulator.DefaultTransport.Text} - {_simulator.DefaultEndPoint} on {_simulator.DefaultPort}."); _tcpClient = _runtimeService.GetTCPClient(); await _tcpClient.ConnectAsync(_simulator.DefaultEndPoint, _simulator.DefaultPort); StartReceiveThread(); SetConnectedState(); await _notificationPublisher.PublishTextAsync(Targets.WebSocket, Channels.Simulator, InstanceId, $"Connected to {_simulator.DefaultTransport.Text} - {_simulator.DefaultEndPoint} on {_simulator.DefaultPort}."); break; case TransportTypes.UDP: await _notificationPublisher.PublishTextAsync(Targets.WebSocket, Channels.Simulator, InstanceId, $"Connecting to {_simulator.DefaultTransport.Text} - {_simulator.DefaultEndPoint} on {_simulator.DefaultPort}."); _udpClient = _runtimeService.GetUDPCLient(); await _udpClient.ConnectAsync(_simulator.DefaultEndPoint, _simulator.DefaultPort); StartReceiveThread(); SetConnectedState(); await _notificationPublisher.PublishTextAsync(Targets.WebSocket, Channels.Simulator, InstanceId, $"Connected to {_simulator.DefaultTransport.Text} - {_simulator.DefaultEndPoint} on {_simulator.DefaultPort}."); break; case TransportTypes.RestHttp: case TransportTypes.RestHttps: break; default: await _notificationPublisher.PublishTextAsync(Targets.WebSocket, Channels.Simulator, InstanceId, $"Attempt to connect to {_simulator.DefaultTransport.Text} that does not allow connections.."); break; } return(InvokeResult.Success); } catch (Exception ex) { await _notificationPublisher.PublishTextAsync(Targets.WebSocket, Channels.Simulator, InstanceId, $"Error connecting to {_simulator.DefaultTransport.Text} - {ex.Message}."); if (_mqttClient != null) { _mqttClient.Dispose(); _mqttClient = null; } if (_azureIoTHubClient != null) { await _azureIoTHubClient.CloseAsync(); _azureIoTHubClient.Dispose(); _azureIoTHubClient = null; } if (_tcpClient != null) { await _tcpClient.DisconnectAsync(); _tcpClient.Dispose(); _tcpClient = null; } if (_udpClient != null) { await _udpClient.DisconnectAsync(); _udpClient.Dispose(); _udpClient = null; } SetDisconnectedState(); return(InvokeResult.FromException("ConnectAsync", ex)); } finally { IsBusy = false; } }