Beispiel #1
0
 private void WorkCompleted()
 {
     // InvokeRequired required compares the thread ID of the
     // calling thread to the thread ID of the creating thread.
     // If these threads are different, it returns true.
     if (this.InvokeRequired)
     {
         WorkCompletedCallback d = new WorkCompletedCallback(WorkCompleted);
         this.Invoke(d);
     }
     else
     {
         Cursor = mOldCursor;
         buttonGenerateCSV.Enabled = true;
         var fileToOpen = textBoxFileToOpen.Text;
         if (fileToOpen != null && System.IO.File.Exists(fileToOpen))
         {
             var arguments = textBoxArguments.Text;
             if (arguments != null && arguments.Length > 0)
             {
                 System.Diagnostics.Process.Start(fileToOpen, arguments);
             }
             else
             {
                 System.Diagnostics.Process.Start(fileToOpen);
             }
         }
     }
 }
Beispiel #2
0
        public void SendCommand_Async(EnumCommands command, WorkCompletedCallback callback)
        {
            try
            {
                lock (syncRoot)
                {
                    if (!_waitingCommands.Contains(command))
                    {
                        OnNewEvent?.Invoke(this, "Add command:" + command + " to waiting list");

                        _commandsRetryCount[command] = 0;
                        _waitingCommands.Add(command);
                        if (callback != null)
                        {
                            _callbacks[command] = callback;
                        }
                    }
                    else
                    {
                        OnNewEvent?.Invoke(this, "Command:" + command + " already exist and will be ignored.");
                    }
                }
            }
            catch (Exception ex)
            {
                LogManager.Error("Error in LEDStatusLightingUtil.SendCommand_Async:" + ex.Message);
                //MessageBox.Show("Error in SendCommand_Async. Details:" + ex.Message);
            }
        }
Beispiel #3
0
 private void CompleteCurrentCommand(bool?result)
 {
     try
     {
         lock (syncRoot)
         {
             _waitingCommands.Remove(_currentCommand);
             if (_commandsRetryCount.ContainsKey(_currentCommand))
             {
                 _commandsRetryCount.Remove(_currentCommand);
             }
             WorkCompletedCallback callback = null;
             if (_callbacks.ContainsKey(_currentCommand))
             {
                 callback = _callbacks[_currentCommand];
                 _callbacks.Remove(_currentCommand);
             }
             if (callback != null && result != null)
             {
                 callback(result.Value);
             }
             OnNewEvent?.Invoke(this, "Complete current command " + _currentCommand + " successfully. Result:" + (result != null ? result.Value.ToString() : "null"));
             _currentCommand = EnumCommands.Unknown;
         }
     }
     catch (Exception ex)
     {
         LogManager.Error("Error in LEDStatusLightingUtil.CompleteCurrentCommand:" + ex.Message);
         //MessageBox.Show("Error in CompleteCurrentCommand. Details:" + ex.Message);
     }
 }
Beispiel #4
0
        private void SendCommand_Async_Callback(object sender, string response)
        {
            try
            {
                lock (syncRoot)
                {
                    OnNewEvent?.Invoke(this, "SendCommand_Async_Callback, response:" + response + ", command:" + _currentCommand);

                    if (_currentCommand == EnumCommands.Unknown)
                    {
                        //MessageBox.Show("Tai sao lai xay ra truong hop nay");
                        return;
                    }
                    WorkCompletedCallback callback = null;
                    if (_callbacks.ContainsKey(_currentCommand))
                    {
                        callback = _callbacks[_currentCommand];
                    }
                    else
                    {
                        OnNewEvent?.Invoke(this, "Found no callback for command " + _currentCommand);

                        CompleteCurrentCommand(null);
                        //MessageBox.Show("Tai sao lai xay ra truong hop nay chu");
                        return;
                    }
                    //OnNewEvent?.Invoke(this, "SendCommand_Async_Callback, response:" + response);


                    if (_currentCommand == EnumCommands.CheckIfMUBIsPresent || _currentCommand == EnumCommands.CheckIfTTIsPresent)
                    {
                        if (response == "0")
                        {
                            CompleteCurrentCommand(false);
                            return;
                        }
                        else
                        {
                            CompleteCurrentCommand(true);
                            return;
                        }
                    }
                    else if (_currentCommand == EnumCommands.CheckIfMUBIsRemoved || _currentCommand == EnumCommands.CheckIfTTIsRemoved)
                    {
                        if (response == "0")
                        {
                            CompleteCurrentCommand(true);
                            return;
                        }
                        else
                        {
                            CompleteCurrentCommand(false);
                            return;
                        }
                    }
                    else
                    {
                        if (response == "1" || response.ToLower() == "ok" || response.ToLower() == "yes")
                        {
                            CompleteCurrentCommand(true);
                            return;
                        }
                        else
                        {
                            if (_commandsRetryCount[_currentCommand] == _maxRetryCount)
                            {
                                CompleteCurrentCommand(false);
                                return;
                            }
                            else
                            {
                                // Retry
                                OnNewEvent?.Invoke(this, "Continue retrying command " + _currentCommand + ", count:" + _commandsRetryCount[_currentCommand]);
                                _currentCommand = EnumCommands.Unknown;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CompleteCurrentCommand(false);
                Thread currentThread = Thread.CurrentThread;
                LogManager.Error("Error in SendCommand_Async_Callback. Current thread:" + currentThread.Name + ". Details:" + ex.Message);
                //MessageBox.Show("Error in SendCommand_Async_Callback. Current thread:" + currentThread.Name + ". Details:" + ex.Message);
            }
        }