Пример #1
0
 /// <summary>
 /// Send instruction to client
 /// </summary>
 public void QueueInstruction(TerminalInstructionCode instruction, object data = null)
 {
     QueueInstruction(new TerminalInstruction()
     {
         Code = instruction, Data = data
     });
 }
Пример #2
0
        /// <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;
            }
        }
Пример #3
0
        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);
        }