public void Start(string[] ips, int count = 4) { var goal = ips.Length * count; var local = LocalIp; OnResponseReceived?.Invoke($"Current IP: {local} ({GetIpLocation(local)})"); new Thread(new ThreadStart(() => { foreach (var ip in ips.Select((value, index) => new { value, index })) { var roundTrip = new List <int>(); var head = $">>>>>>>>>>>>>>>>> Started to ping [{ip.value}]: "; OnResponseReceived?.Invoke(head); for (int i = 0; i < count; i++) { OnResponseReceived(DoPing(ip.value)); OnProgressUpdated(ip.index * 4 + i + 1, goal); Thread.Sleep(1000); } } OnResponseReceived?.Invoke("================== Done ==================="); })).Start(); }
private void _WebSocket_OnMessage(object sender, MessageEventArgs e) { _lastReceivedTime = DateTime.UtcNow; if (e.IsBinary) { string data = GZipDecompresser.Decompress(e.RawData); var pingMessage = JsonConvert.DeserializeObject <PingMessage>(data); if (pingMessage != null && pingMessage.ping != 0) { //Console.WriteLine($"received ping:{pingMessage.ping}"); string pongData = $"{{\"pong\":{pingMessage.ping}}}"; _WebSocket.Send(pongData); //Console.WriteLine($"replied pong:{pingMessage.ping}"); } else { var response = JsonConvert.DeserializeObject <DataResponseType>(data); OnResponseReceived?.Invoke(response); } } }
private void _WebSocket_OnMessage(object sender, MessageEventArgs e) { _lastReceivedTime = DateTime.UtcNow; if (e.IsBinary) { string data = GZipDecompresser.Decompress(e.RawData); var pingMessage = JsonConvert.DeserializeObject <PingMessage>(data); if (pingMessage != null && pingMessage.ping != 0) { _logger.Log(Log.LogLevel.Trace, $"WebSocekt received data, ping={pingMessage.ping}"); string pongData = $"{{\"pong\":{pingMessage.ping}}}"; _WebSocket.Send(pongData); _logger.Log(Log.LogLevel.Trace, $"WebSocket replied data, pong={pingMessage.ping}"); } else { var response = JsonConvert.DeserializeObject <DataResponseType>(data); OnResponseReceived?.Invoke(response); } } }
/// <summary> /// Method implements initial request. Returned result sets to Atomics.UnitDescription property and /// to internal this._xmlDescription variable. /// </summary> /// <param name="hostNameorAddress">Host name or IP address of the AV receiver</param> public bool RequestUnitDescription(string hostNameorAddress) { Atomics.HostNameOrIPAddress = hostNameorAddress; bool result = false; try { if (PingIpAddress(3, hostNameorAddress) == true) { string ynccmd = YNCCommand.CreateCommand(MethodType.NONE); Atomics.UnitDescription = Http.Send(hostNameorAddress, Atomics.UnitDescriptionPath, HttpMethod.Get, ynccmd); UnitDescription = Atomics.UnitDescription; OnResponseReceived?.Invoke(this, new CommEventArgs() { Success = true, UnitDescription = Atomics.UnitDescription, YNCFunction = CommandListFunctionType.UnitDescription }); result = true; } else { throw new Exception("Receiver is not accessible."); } } catch (Exception ex) { OnResponseReceived?.Invoke(this, new CommEventArgs() { Success = false, ErrorMessage = ex.Message, YNCFunction = CommandListFunctionType.UnitDescription }); } return(result); }
public void ReceivedCommandResponse(ZToolPacket packet) { Log.Verbose(" {Packet} received as synchronous command.", packet.GetType().Name); OnResponseReceived?.Invoke(this, packet); }
private void sender_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { inUse = false; OnResponseReceived?.Invoke(this, new ResponseReceivedEventArgs(asyncResponse)); }
private Task HandleResponse(JsonObject data) { OnResponseReceived?.Invoke(this, data); return(Task.CompletedTask); }
private void SocketOnResponseReceived(Service service) { OnResponseReceived?.Invoke(service); }
private static void CallHandler(object obj, HttpResponseMessage response) { var args = new ResponseEventArguments(DateTime.Now, response.StatusCode); OnResponseReceived.Invoke(obj, args); }
public static async void StartService() { try { if (isRunning) { // If the service is already running, exits. return; } isRunning = true; var isConnected = false; while (!isConnected) { // Be sure to be connected to the Internet. var profile = NetworkInformation.GetInternetConnectionProfile(); isConnected = profile?.GetNetworkConnectivityLevel() == NetworkConnectivityLevel.InternetAccess; await Task.Delay(200); } if (Settings.Instance == null) { await LoadSettingsAsync(); } if (directLineClient == null) { // Obtain a token using the Direct Line secret var tokenResponse = await new DirectLineClient(Settings.Instance.DirectLineSecret).Tokens.GenerateTokenForNewConversationAsync(); // Use token to create conversation directLineClient = new DirectLineClient(tokenResponse.Token); conversation = await directLineClient.Conversations.StartConversationAsync(); // Connect using a WebSocket. webSocketClient = new MessageWebSocket(); webSocketClient.MessageReceived += WebSocketClient_MessageReceived; await webSocketClient.ConnectAsync(new Uri(conversation.StreamUrl)); } if (assistantInvokerSpeechRecognizer == null) { // Create an instance of SpeechRecognizer. assistantInvokerSpeechRecognizer = new SpeechRecognizer(new Language(Settings.Instance.Culture)); assistantInvokerSpeechRecognizer.Timeouts.InitialSilenceTimeout = TimeSpan.MaxValue; assistantInvokerSpeechRecognizer.Timeouts.BabbleTimeout = TimeSpan.MaxValue; // Add a list constraint to the recognizer. var listConstraint = new SpeechRecognitionListConstraint(new string[] { Settings.Instance.AssistantName }, "assistant"); assistantInvokerSpeechRecognizer.Constraints.Add(listConstraint); await assistantInvokerSpeechRecognizer.CompileConstraintsAsync(); } if (commandSpeechRecognizer == null) { commandSpeechRecognizer = new SpeechRecognizer(new Language(Settings.Instance.Culture)); // Apply the dictation topic constraint to optimize for dictated freeform speech. var dictationConstraint = new SpeechRecognitionTopicConstraint(SpeechRecognitionScenario.WebSearch, "dictation"); commandSpeechRecognizer.Constraints.Add(dictationConstraint); await commandSpeechRecognizer.CompileConstraintsAsync(); } // The assistant is ready to receive input. SoundPlayer.Instance.Play(Sounds.SpeechActive); while (isRunning) { try { var assistantInvocationResult = await assistantInvokerSpeechRecognizer.RecognizeAsync(); if (assistantInvocationResult.Status == SpeechRecognitionResultStatus.Success && assistantInvocationResult.Confidence != SpeechRecognitionConfidence.Rejected) { OnStartRecognition?.Invoke(null, EventArgs.Empty); SoundPlayer.Instance.Play(Sounds.Ready); // Starts command recognition. It returns when the first utterance has been recognized. var commandResult = await commandSpeechRecognizer.RecognizeAsync(); if (commandResult.Status == SpeechRecognitionResultStatus.Success && commandResult.Confidence != SpeechRecognitionConfidence.Rejected) { var command = commandResult.NormalizeText(); Debug.WriteLine(command); OnCommandReceived?.Invoke(null, EventArgs.Empty); // Sends the activity to the Bot. The answer will be received in the WebSocket received event handler. var userMessage = new Activity { From = new ChannelAccount(Settings.Instance.UserName), Text = command, Type = ActivityTypes.Message }; await directLineClient.Conversations.PostActivityAsync(conversation.ConversationId, userMessage); } } } catch (Exception ex) { OnResponseReceived?.Invoke(null, new BotEventArgs(ex.Message)); } } // Clean up used resources. SoundPlayer.Instance.Play(Sounds.SpeechStopped); } catch (Exception ex) { OnResponseReceived?.Invoke(null, new BotEventArgs(ex.Message)); SoundPlayer.Instance.Play(Sounds.SpeechStopped); } assistantInvokerSpeechRecognizer?.Dispose(); commandSpeechRecognizer?.Dispose(); webSocketClient?.Dispose(); directLineClient?.Dispose(); assistantInvokerSpeechRecognizer = null; commandSpeechRecognizer = null; webSocketClient = null; conversation = null; directLineClient = null; isRunning = false; }