Example #1
0
        private void ClientOnMessageReceived(object sender, MessageEventArgs messageEventArgs)
        {
            var message = messageEventArgs.Message;

            if (message == null || message.Type != MessageType.Text)
            {
                return;
            }

            var messageInfo = message.ToChatMessage();

            OnMessageReceived?.Invoke(messageInfo);

            try
            {
                var response = messagesProcessor.ProcessMessage(messageInfo);
                if (!string.IsNullOrEmpty(response))
                {
                    client.SendTextMessageAsync(message.Chat.Id, response, ParseMode.Markdown);
                }
            }
            catch (Exception e)
            {
                OnErrorOccured?.Invoke(e.Message);
            }
        }
Example #2
0
        public static void LogError(string msg, [CallerMemberName] string previousMethodName = null, [CallerLineNumber] int callermemberlineNo = 0, [CallerFilePath] string calledFilePath = null)
        {
            if (string.IsNullOrEmpty(msg) || string.IsNullOrWhiteSpace(msg))
            {
                return;
            }

            LogMessageReceived?.Invoke(null, new LogMessageEventArgs(msg, DateTime.Now, LogEnums.LogLevel.ERROR, previousMethodName, callermemberlineNo, calledFilePath));
            OnErrorOccured?.Invoke(null, new EventArgsBase(DateTime.Now, msg, previousMethodName, callermemberlineNo, calledFilePath));
        }
Example #3
0
        /// <summary>
        /// Checks if the ScreenSaver is active at the moment.
        /// Reason: the ScreenSaver sometimes turns off the USB ports and after that, the connection to the simulator is lost.
        /// Also "pings" the simulator to maintain the connection.
        /// </summary>
        void ScreenSaverStateCheckTimer_Tick(object sender, EventArgs e)
        {
            int ok = SystemParametersInfo(SPI_GETSCREENSAVERRUNNING, 0, ref screenSaverRunning, 0);

            if (screenSaverRunning != 0) //screen saver is running
            {
                ScreenSaverStateCheckTimer.Stop();
                OnErrorOccured?.Invoke(this, "Der Windows Bildschirmschoner war aktiv. Bitte starten Sie die Software neu, um Verbindungsprobleme mit dem Gerät zu vermeiden!");
            }
        }
        private void Work(object obj, EventArgs args)
        {
            Action action = null;

            lock (_locker)
            {
                if (_queue.Count > 0)
                {
                    action = _queue.Dequeue();
                }
            }

            if (action != null)
            {
                try
                {
                    ThreadPool.QueueUserWorkItem(
                        _ =>
                    {
                        _semaphore.WaitOne();
                        try
                        {
                            action.Invoke();
                        }
                        catch (Exception ex)
                        {
                            MonitoringErrorEventArgs margs = new MonitoringErrorEventArgs
                            {
                                Message      = "Возникла ошибка при исполнении метода",
                                Method       = action.Method.Name,
                                ErrorMessage = ex.Message
                            };
                            OnErrorOccured?.Invoke(this, margs);
                        }
                        finally
                        {
                            _semaphore.Release();
                        }
                    });
                }
                catch (Exception ex)
                {
                    MonitoringErrorEventArgs margs = new MonitoringErrorEventArgs
                    {
                        Message      = "Не удалось поместить метод в очередь выполнения.",
                        Method       = action.Method.Name,
                        ErrorMessage = ex.Message
                    };
                    OnErrorOccured?.Invoke(this, margs);
                }
            }
        }
Example #5
0
        /// <summary>
        /// This event is fired when the system goes to sleep or wakes up.
        /// </summary>
        void SystemEvents_PowerModeChanged(object sender, PowerModeChangedEventArgs e)
        {
            switch (e.Mode)
            {
            case PowerModes.Suspend:
                break;

            case PowerModes.Resume:
                OnErrorOccured?.Invoke(this, "Der Computer wurde aus dem Standby-Modus geholt. Bitte starten Sie die Software neu, um Verbindungsprobleme mit dem Gerät zu vermeiden!");
                break;

            default:
                break;
            }
        }
Example #6
0
        /// <summary>
        /// Pings each available simulator device currently connected to this software.
        /// </summary>
        void SimulatorPingTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            timerTickCnt++;

            if (this.simulatorSetupType == CBaseSimulator.SimulatorSetupTypes.OneDevice)
            {
                CBaseSimulator simulator = SimulatorController.SingleSimulatorMode.SimulatorControl.Instance.GetOstererSimulator();
                string         id        = simulator.GetDeviceId(); //retrieve the id of the device to see whether it is still connected or not
                SimulatorPingTimer.Start();
                return;
            }

            List <CBaseSimulator> Simulators = SimulatorController.MultiSimulatorMode.SimulatorControl.Instance.GetAllConnectedSimulators();

            if (Simulators == null)
            {
                SimulatorPingTimer.Start();
                return;
            }

            foreach (CBaseSimulator device in Simulators)
            {
                string id;

                if (device is SerialSimulatorServices.CSerialSimulator)
                {
                    if ((device as SerialSimulatorServices.CSerialSimulator).IsConnected)
                    {
                        if ((device as SerialSimulatorServices.CSerialSimulator).LastUsageTime < DateTime.Now.AddMinutes(-10d))
                        {
                            id = (device as SerialSimulatorServices.CSerialSimulator).GetDeviceId();
                        }
                    }
                    else if (device is NgMattApiWrapper.CngMattSimulator)
                    {
                        id = device.GetDeviceId(); //this does not actually communicate with the device as this is not needed for ngMatts
                    }
                    else
                    {
                        OnErrorOccured?.Invoke(this, "Fehler im Watchdog beim überprüfen der Simulatorverbindungen. Unbekannter Typ: " + device.GetType().ToString());
                    }
                }
            }

            SimulatorPingTimer.Start();
        }
        private void OnIrixiAxisStateChanged(object sender, Tuple <byte, AxisArgs> e)
        {
            int AxisNo = e.Item1 - 1;

            AxisArgsList[AxisNo].CurAbsPos   = e.Item2.CurAbsPos;
            AxisArgsList[AxisNo].IsBusy      = e.Item2.IsBusy;
            AxisArgsList[AxisNo].IsHomed     = e.Item2.IsHomed;
            AxisArgsList[AxisNo].IsInRequest = e.Item2.IsInRequest;
            OnAxisStateChanged?.Invoke(this, e.Item1 - 1, AxisArgsList[AxisNo]);
            if (AxisArgsList[AxisNo].ErrorCode != e.Item2.ErrorCode)
            {
                AxisArgsList[AxisNo].ErrorCode = e.Item2.ErrorCode;
                if (e.Item2.ErrorCode != 0)
                {
                    OnErrorOccured?.Invoke(this, e.Item2.ErrorCode, ParseErrorCode(e.Item2.ErrorCode));
                }
            }
        }
        private void OnIrixiAxisStateChanged(object sender, UnitState e)
        {
            int AxisNo = e.UnitID - (int)UnitID.U1;

            AxisArgsList[AxisNo].CurAbsPos         = (double)e.AbsPosition / AxisArgsList[AxisNo].GainFactor;
            AxisArgsList[AxisNo].IsBusy            = e.IsBusy;
            AxisArgsList[AxisNo].IsHomed           = e.IsHomed;
            AxisArgsList[AxisNo].IsHomedAndNotBusy = e.IsHomed && (!e.IsBusy);
            AxisArgsList[AxisNo].CurAbsPosPuse     = e.AbsPosition;
            OnAxisStateChanged?.Invoke(this, AxisNo, AxisArgsList[AxisNo]);
            if (AxisArgsList[AxisNo].ErrorCode != (byte)e.Error)
            {
                AxisArgsList[AxisNo].ErrorCode = (byte)e.Error;
                if ((byte)e.Error != 0)
                {
                    OnErrorOccured?.Invoke(this, (int)e.Error, ParseErrorCode((int)e.Error));
                }
            }
        }
Example #9
0
        public void Start()
        {
            while (!Finish)
            {
                if (!Queue.IsEmpty)
                {
                    if (Queue.TryDequeue(out data))
                    {
                        if (data.Message != null)
                        {
                            Bot.Instance.PressMessage(data.Message);
                        }
                        else if (data.Repeat > 0 && data.Keys.Length == 1)
                        {
                            Bot.Instance.Press(data.Keys[0], data.Repeat);
                        }
                        else if (data.Keys.Length == 1 && !data.Pressed)
                        {
                            Bot.Instance.PressAndRelease(data.Keys[0]);
                        }
                        else if (data.Keys.Length == 1 && data.Pressed)
                        {
                            Bot.Instance.Press(data.Keys[0]);
                        }
                        else if (data.Keys.Length == 2)
                        {
                            Bot.Instance.PressAndRelease(data.Keys[0], data.Keys[1]);
                        }
                        else if (data.Keys.Length == 3)
                        {
                            Bot.Instance.PressAndRelease(data.Keys[0], data.Keys[1], data.Keys[2]);
                        }
                        else
                        {
                            OnErrorOccured?.Invoke("UNDEFINED DATA", LogView.LogType.Error);
                        }
                    }
                }

                Thread.Sleep(1);
            }
        }
 private void ClientOnReceiveError(object sender, ReceiveErrorEventArgs errorEventArgs)
 {
     OnErrorOccured?.Invoke(errorEventArgs.ApiRequestException.Message);
 }