/// <summary> /// Send instruction to client /// </summary> public void QueueInstruction(TerminalInstructionCode instruction, object data = null) { QueueInstruction(new TerminalInstruction() { Code = instruction, Data = data }); }
/// <summary> /// Execute instruction on client side and wait for input /// </summary> public bool ExecuteInstruction(TerminalInstructionCode instruction, object data, out object result) { try { _currentSynchronousInstruction = new SynchronousTerminalInstruction() { Code = instruction, Data = data }; // send to client QueueInstruction(_currentSynchronousInstruction); // wait for client response or cancelation _currentSynchronousInstruction.WaitHandle.WaitOne(); result = _currentSynchronousInstruction.Result; return(!_currentSynchronousInstruction.Canceled); } finally { // cleanup _currentSynchronousInstruction.WaitHandle.Dispose(); _currentSynchronousInstruction = null; } }
private Collection <int> PromptForChoice( string caption, string message, Collection <ChoiceDescription> choices, IEnumerable <int> defaultChoices, TerminalInstructionCode instructionCode) { Collection <int> selected = null; var promptRequest = new { caption = caption, message = message, descriptions = choices.Select((cd, i) => new { name = cd.Label.Replace("&", ""), selected = (defaultChoices.Contains(i)) }) }; object result; if (_terminal.ExecuteInstruction(instructionCode, promptRequest, out result)) { var jsonArray = result as JArray; if (jsonArray != null && jsonArray.Count == choices.Count) { for (int i = 0; i < choices.Count; i++) { var jsonVal = jsonArray[i] as JValue; if (jsonVal != null) { if (selected == null) { selected = new Collection <int>(); } if (jsonVal.Value <bool>() == true) { selected.Add(i); } } } } } return(selected); }