/// <summary> /// Mount data results /// </summary> /// <param name="command"></param> /// <returns></returns> public static IMountCommand GetCommandResult(IMountCommand command) { if (!IsRunning || _cts.IsCancellationRequested) { var e = new MountException(ErrorCode.ErrQueueFailed, "Queue not running"); command.Exception = e; command.Successful = false; return(command); } var sw = Stopwatch.StartNew(); while (sw.Elapsed.TotalMilliseconds < 7000) { if (_resultsDictionary == null) { break; } var success = _resultsDictionary.TryRemove(command.Id, out var result); if (!success) { Thread.Sleep(1); continue; } sw.Stop(); return(result); } sw.Stop(); var ex = new MountException(ErrorCode.ErrQueueFailed, $"Queue Read Timeout {command.Id}, {command}"); command.Exception = ex; command.Successful = false; return(command); }
/// <summary> /// Add a command to the blocking queue /// </summary> /// <param name="command"></param> public static void AddCommand(IMountCommand command) { if (!IsRunning) { return; } CleanResults(20, 120); _commandBlockingCollection.TryAdd(command); }
/// <summary> /// Process command queue /// </summary> /// <param name="command"></param> private static void ProcessCommandQueue(IMountCommand command) { try { if (!IsRunning || _cts.IsCancellationRequested || !Actions.IsConnected) { return; } command.Execute(_actions); if (command.Id > 0) { _resultsDictionary.TryAdd(command.Id, command); } } catch (Exception e) { command.Exception = e; command.Successful = false; } }