Exemple #1
0
        protected async Task handleLocalCommand(NetworkStream stream, Guid remoteId)
        {
            string command;

            var emc = EncryptedMessage.FromStream(stream);

            command = decryptMessage(emc);

            _log.Debug($"Got command \"{command.Truncate(10)}\".");

            var crea = new CommandReceivedEventArgs()
            {
                Command      = command,
                NodeId       = remoteId,
                ResultSource = new TaskCompletionSource <string>()
            };

            CommandReceived(this, crea);

            var response = await crea.ResultSource.Task;

            try {
                var emr = encryptMessage(response, remoteId);
                emr.WriteToStream(stream);
            }
            catch (Exception x)
            {
                _log.Warn($"Could not send response: {x.Message}");
                throw x;
            }

            stream.Close();
        }
Exemple #2
0
        protected void handleRemoteCommand(NetworkStream stream, QueuedCommand serverCommand)
        {
            var emc = encryptMessage(serverCommand);

            emc.WriteToStream(stream);

            string response;

            using (MemoryStream ms = new MemoryStream())
            {
                stream.CopyTo(ms);
                ms.Position = 0;
                var emr = EncryptedMessage.FromStream(ms);
                response = decryptMessage(emr);
            }

            serverCommand.ResultSource.SetResult(response);
            stream.Close();
        }