Esempio n. 1
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);
            }
        }
Esempio n. 2
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);
     }
 }
Esempio n. 3
0
        runCommand(EnumCommands command,
                   int agentId,
                   object[] data = null)
        {
            FingerPrintAgent agent = agents.Where(x => x.deviceModel?.id == agentId)
                                     .FirstOrDefault();

            if (null == agent)
            {
                return;
            }


            agent.runCommand(command,
                             data);
        }
Esempio n. 4
0
 private void GetNextCommand()
 {
     _currentCommand = EnumCommands.Unknown;
     if (_waitingCommands.Count > 0)
     {
         if (_currentCommandIndex >= _waitingCommands.Count - 1)
         {
             _currentCommandIndex = 0;
         }
         else
         {
             _currentCommandIndex++;
         }
         _currentCommand = _waitingCommands[_currentCommandIndex];
         OnNewEvent?.Invoke(this, "Get next command:" + _currentCommand);
     }
 }
        public void ExecuteCommand()
        {
            if (targetGrid == null)
            {
                CommandStatus = EnumCommands.ERROR;
                return;
            }


            MatrixD m = targetGrid.WorldMatrix;

            m.Translation = newPosition;
            targetGrid.PositionComp.SetWorldMatrix(m, forceUpdate: true, updateChildren: true, updateLocal: true, forceUpdateAllChildren: true, ignoreAssert: true);
            //targetGrid.Teleport(m);
            //newPosition.X += 0.01;
            //targetGrid.PositionComp.SetPosition(newPosition);
            CommandStatus = EnumCommands.SUCCES;
        }
Esempio n. 6
0
        public static void RunCommand(EnumCommands iCommand)
        {
            if (Commands.ContainsKey(iCommand))
            {
                switch (iCommand)
                {
                case EnumCommands.ComputeLattice:
                    printLn(">>Compute Lattice");
                    lattice = ComputeLattice();
                    break;

                case EnumCommands.GetRoute:
                    printLn(">>Get Route");
                    printLn(">>Source Location (lat, long):");
                    double[] source = ParseLocation(Console.ReadLine());

                    printLn(">>Destination Location (lat, long):");
                    double[] destination = ParseLocation(Console.ReadLine());

                    string result = RoutingService.Service.GetRoute(source, destination);
                    string path   = Path.Combine(saveFile, "route.geojson");
                    File.WriteAllText(path, result);
                    printLn("Route saved to : " + path);
                    break;

                case EnumCommands.GetTrips:
                    if (lattice == null)
                    {
                        RunCommand(EnumCommands.ComputeLattice);
                    }

                    printLn(">>Get Trips");
                    trips = GetTrips(lattice);
                    break;

                case EnumCommands.ComputeProbDist:
                    if (trips.Count == 0)
                    {
                        RunCommand(EnumCommands.GetTrips);
                    }
                    if (trips.Count > 0)
                    {
                        printLn(">>Save distribution results As:");
                        string file = Console.ReadLine();
                        printLn(">>Compute Probability Distribution");
                        TripStats.DistributionOfRequests(trips, file);
                    }
                    else
                    {
                        printLn("No trips available. Please check parameters.");
                    }
                    break;

                case EnumCommands.SaveAsBinary:
                    printLn(">>Enter File Name:");
                    string binfile = Console.ReadLine();
                    printLn(">Saving Trip Data<");
                    //TODO
                    //ToBinary.CsvToBinary(trips, Path.Combine(saveFile, binfile + ".dat"));
                    printLn(string.Format("{0} Trips Saved", trips.Count));
                    break;

                case EnumCommands.SaveAsCSV:
                    printLn(">>Enter File Name:");
                    string csvfile = Console.ReadLine();
                    printLn(">Saving Raw Trip Data<");
                    TripFunctions.Save(tripsDB, Path.Combine(saveFile, csvfile + ".csv"));
                    printLn(string.Format("{0} Trips Saved", tripsDB.Count));
                    break;

                default:
                    break;
                }
            }
        }
Esempio n. 7
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);
            }
        }