Пример #1
0
		void SendCommandResult (Command c, int exeId, object result)
		{
			new Message ((byte)ControlOp.CommandResult, c.Id, exeId, result).Write (stream);
		}
Пример #2
0
		public Task ExecuteCommandAsync (Command command)
		{
			return (new Message ((byte)ControlOp.ExecuteCommand, command.Id, eid++)).WriteAsync (stream);
		}
Пример #3
0
		void SendCommand (Command c)
		{
			new Message ((byte)ControlOp.Command, c.Id, c.Name).Write (stream);
		}
Пример #4
0
		public async Task RunAsync (CancellationToken cancellationToken)
		{
			await GetVariablesAsync ();
			await GetCommandsAsync ();

			var m = new Message ();

			while (!cancellationToken.IsCancellationRequested) {

				await m.ReadAsync (stream);

				Debug.WriteLine ("Got message: " + (ControlOp)m.Operation + "(" + string.Join (", ", m.Arguments.Select (x => x.ToString ())) + ")");

				switch ((ControlOp)m.Operation) {
				case ControlOp.Variable:
					{
						var id = (int)m.Arguments [0];
						var v = variables.FirstOrDefault (x => x.Id == id);
						if (v == null) {
							var cv = new ClientVariable {
								Client = this,
								Id = id,
								Name = (string)m.Arguments [1],
								IsWriteable = (bool)m.Arguments [2],
							};
							cv.SetValue (m.Arguments [3]);
							v = cv;
							Schedule (() => variables.Add (v));
						}
					}
					break;
				case ControlOp.VariableValue:
					{
						var id = (int)m.Arguments [0];
						var cv = variables.FirstOrDefault (x => x.Id == id) as ClientVariable;
						if (cv != null) {
							var newVal = m.Arguments [1];
							Schedule (() => cv.SetValue (newVal));
						} else {
							await GetVariablesAsync ();
						}
					}
					break;
				case ControlOp.Command:
					{
						var id = (int)m.Arguments [0];
						var c = commands.FirstOrDefault (x => x.Id == id);
						if (c == null) {
							var cc = new Command {
								Id = id,
								Name = (string)m.Arguments [1],
							};
							c = cc;
							Schedule (() => commands.Add (c));
						}
					}
					break;
					//				default:
					//					Debug.WriteLine ("Ignoring message: " + m.Operation);
					//					break;
				}
			}
		}