private void DataReceived(object sender, DataReceivedEventArgs eventArgs)
 {
     if (!string.IsNullOrEmpty(eventArgs?.Data))
     {
         OnOutputReceived?.Invoke(eventArgs.Data);
     }
 }
Exemple #2
0
 private void OnOutputReceived_Proc(object sender, DataReceivedEventArgs e)
 {
     if (!HandleReceivedSelfCmd(e.Data))
     {
         OnOutputReceived?.Invoke(e.Data, false);
     }
 }
Exemple #3
0
        public async Task StartInput(OnPartialOutputReceived OnPartialOutputReceivedHandler,
                                     OnOutputReceived OnFinalOutputReceivedHandler,
                                     OnIntentReceived OnIntentReceivedHandler,
                                     OnError OnErrorHandler)
        {
            _onOutputReceived = OnFinalOutputReceivedHandler;

            await CapturePhoto();
        }
Exemple #4
0
 private void Process_ErrorDataReceived(object sender, DataReceivedEventArgs e)
 {
     if (e.Data != null)
     {
         Console.WriteLine(e.Data);
         OnOutputReceived?.Invoke(this, new StringEventArgs(e.Data));
     }
     else
     {
         countdownEvent.AddCount();
     }
 }
        private async void StatusLoop()
        {
            try
            {
                Dictionary <string, DateTime> exceptions = new Dictionary <string, DateTime>();
                bool connected = false;

                while (!statusToken.IsCancellationRequested && Running)
                {
                    try
                    {
                        this.connected = tcp.Client.IsConnected();

                        if (connected != this.connected)
                        {
                            connected = this.connected;
                            OnConnectChanged?.Invoke(this.connected);
                        }

                        if (!this.connected)
                        {
                            using (Ping ping = new Ping())
                            {
                                PingReply reply = ping.Send(Host);

                                if (reply.Status == IPStatus.Success)
                                {
                                    CreateClient();
                                }
                            }

                            continue;
                        }

                        OnOutputReceived?.Invoke(GetOutput(OutputStartAddress, OutputChannelNumber));

                        OnInputReceived?.Invoke(GetInput(InputStartAddress, InputChannelNumber));
                    }
                    catch (Exception ex)
                    {
                        bool writable = false;
                        if (!exceptions.ContainsKey(ex.Message))
                        {
                            exceptions.Add(ex.Message, DateTime.Now);
                            writable = true;
                        }
                        else
                        {
                            if ((DateTime.Now - exceptions[ex.Message]) < TimeSpan.FromSeconds(60))
                            {
                                continue;
                            }

                            exceptions[ex.Message] = DateTime.Now;
                            writable = true;
                        }

                        if (writable)
                        {
                            OnException?.Invoke(ex);
                        }
                    }
                    finally
                    {
                        if (!statusToken.IsCancellationRequested && Running)
                        {
                            await Task.Delay(DelayTime);
                        }
                    }
                }
            }
            catch (OperationCanceledException) { }
            catch (Exception ex)
            {
                OnException?.Invoke(ex);
            }

            if (Running)
            {
                BeginStatusListener();
            }
        }
Exemple #6
0
 private void OnErroeDataReceived_Proc(object sender, DataReceivedEventArgs e)
 {
     OnOutputReceived?.Invoke(e.Data, true);
 }