Example #1
0
        void TestModeForSendOperation(XModemProtocol.XModemMode mode)
        {
            var communicator = new ComSendCollection();
            var context      = new Context {
                Mode         = mode,
                Data         = _rdg.GetRandomData(40000).ToList(),
                Communicator = communicator,
            };
            var dts = new List <List <byte> > {
                new List <byte> {
                    mode == XModemProtocol.XModemMode.Checksum ? context.Options.NAK : context.Options.C
                }
            };
            double payloadCount = mode == XModemProtocol.XModemMode.OneK ? 1024.0 : 128.0;
            int    ackCount     = (int)Math.Ceiling(context.Data.Count / payloadCount) + 1;

            dts.AddRange(Enumerable.Repeat(new List <byte> {
                context.Options.ACK
            }, ackCount));
            communicator.CollectionToSend = dts;
            IOperation operation = new SendOperation();

            operation.Go(context);
            var expectedData = new List <List <byte> >(context.Packets);

            expectedData.Add(new List <byte> {
                context.Options.EOT
            });
            Assert.AreEqual(expectedData, communicator.BytesRead);
        }
Example #2
0
        public override async Task Invoke(IOutgoingSendContext context, Func <Task> next)
        {
            OutgoingMessageOperation outgoingOperation;

            if (context.Headers.ContainsKey(Headers.IsSagaTimeoutMessage) && context.Headers[Headers.IsSagaTimeoutMessage] == bool.TrueString)
            {
                outgoingOperation = new RequestTimeoutOperation()
                {
                    SagaId = context.Headers[Headers.SagaId],
                    SagaTypeAssemblyQualifiedName = context.Headers[Headers.SagaType]
                };
            }
            else
            {
                outgoingOperation = new SendOperation();
            }

            outgoingOperation.SenderEndpoint  = endpointName;
            outgoingOperation.MessageId       = context.MessageId;
            outgoingOperation.MessageType     = context.Message.MessageType;
            outgoingOperation.MessageInstance = context.Message.Instance;
            outgoingOperation.MessageHeaders  = context.Headers;

            integrationContext.AddOutogingOperation(outgoingOperation);
            try
            {
                await next();
            }
            catch (Exception sendError)
            {
                outgoingOperation.OperationError = sendError;
                throw;
            }
        }
        async void Worker()
        {
            while (true)
            {
                SendOperation wi = null;
                lock (_lock)
                {
                    if (_sendQueue.Count != 0)
                    {
                        wi = _sendQueue.Dequeue();
                    }
                }
                if (wi == null)
                {
                    var signal = new TaskCompletionSource <int>();
                    lock (_lock)
                        _signal = signal;
                    await signal.Task.ConfigureAwait(false);

                    continue;
                }
                try
                {
                    await _conn.Send(wi.Message).ConfigureAwait(false);

                    wi.Tcs.TrySetResult(0);
                }
                catch (Exception e)
                {
                    wi.Tcs.TrySetException(e);
                }
            }
        }
 protected RabbitMQOutputChannelBase(BindingContext context, EndpointAddress address, Uri via)
     : base(context)
 {
     _address = address;
     _via = via;
     _sendMethod = Send;
 }
 protected RabbitMQOutputChannelBase(BindingContext context, EndpointAddress address, Uri via)
     : base(context)
 {
     _address    = address;
     _via        = via;
     _sendMethod = Send;
 }
        /// <summary>
        /// 向指定Peer发送Object
        /// </summary>
        /// <param name="peer"></param>
        /// <param name="obj"></param>
        /// <returns></returns>
        protected Task <T> sendTo <T>(NetPeer peer, object obj)
        {
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }
            if (peer == null)
            {
                throw new ArgumentNullException(nameof(peer));
            }

            SendOperation <T> op = new SendOperation <T>();

            startOperation(op, () => {
                log?.logWarn($"客户端{name}发送请求超时。");
            });

            NetDataWriter writer = new NetDataWriter();

            writer.Put((int)PacketType.sendRequest);
            writer.Put(op.id);
            writer.Put(clientID);
            writer.Put(obj.GetType().FullName);
            writer.Put(obj.ToJson());
            peer.Send(writer, DeliveryMethod.ReliableOrdered);

            return(op.task);
        }
        protected Task SendAsync(Action <SshChannelBase> operation)
        {
            if (!this.IsConnected)
            {
                throw new SshException("Connection is closed");
            }

            lock (this.sendQueue)
            {
                var packet = new SendOperation(operation);
                this.sendQueue.Enqueue(packet);

                //
                // Nofify that we have data and expect a Send()
                // callback.
                //
                NotifyReadyToSend(true);

                //
                // Return a task - it'll be completed once we've
                // actually sent the data.
                //
                return(packet.CompletionSource.Task);
            }
        }
Example #8
0
        private IOperation SendSetup()
        {
            IOperation operation = new SendOperation();

            operation.PacketToSend += (s, e) => PacketToSend?.Invoke(this, e);
            if (_context.Data == null || _context.Data.Count == 0)
            {
                throw new XModemProtocolException(new AbortedEventArgs(XModemAbortReason.BufferEmpty));
            }
            return(operation);
        }
Example #9
0
        /// <summary>
        /// Called when a response arrives from the channel.
        /// </summary>
        private void OnResponse(IAsyncResult result)
        {
            SendOperation operation = (SendOperation)result.AsyncState;

            try
            {
                IServiceResponse response = InternalEndSendRequest(result);
                operation.Complete(response);
            }
            catch (Exception e)
            {
                operation.Fault(e, StatusCodes.BadInternalError, "Error receiving response from channel.");
            }
        }
Example #10
0
        /// <summary cref="IRequestChannel.BeginRequest(Message, TimeSpan, AsyncCallback, object)" />
        public IAsyncResult BeginRequest(Message message, TimeSpan timeout, AsyncCallback callback, object state)
        {
            int milliseconds = Utils.GetTimeout(timeout);

            SendOperation operation = new SendOperation(milliseconds, callback, state);

            // save message id for use in response.
            operation.MessageId = message.Headers.MessageId;

            // extract the request from the message properties (put there by the message inspector).
            IServiceRequest request = (IServiceRequest)message.Properties[MessageProperties.UnencodedBody];

            // start the request.
            InternalBeginSendRequest(request, milliseconds, m_ResponseCallack, operation);

            return(operation);
        }
Example #11
0
        /// <summary cref="IRequestChannel.EndRequest" />
        public Message EndRequest(IAsyncResult result)
        {
            SendOperation operation = (SendOperation)result;

            // wait for operation to complete.
            IServiceResponse response = null;

            try
            {
                response = operation.End(Int32.MaxValue);
            }
            catch (ServiceResultException e)
            {
                if (e.StatusCode == StatusCodes.BadRequestInterrupted)
                {
                    throw new TimeoutException();
                }

                throw new ServiceResultException(e, StatusCodes.BadUnexpectedError);
            }

            // create response.
            Message message = Message.CreateMessage(
                MessageVersion.Soap12WSAddressing10,
                Namespaces.OpcUaWsdl + "/InvokeServiceResponse",
                new InvokeServiceBodyWriter(null, false));

            // update headers.
            message.Headers.From      = this.m_address;
            message.Headers.RelatesTo = operation.MessageId;

            // save the response.
            message.Properties[MessageProperties.UnencodedBody] = response;

            return(message);
        }
 protected RabbitMQOutputChannelBase(BindingContext context, EndpointAddress address)
     : base(context)
 {
     m_address = address;
     m_sendMethod = new SendOperation(Send);
 }
 protected RabbitMQOutputChannelBase(BindingContext context, EndpointAddress address)
     : base(context)
 {
     m_address    = address;
     m_sendMethod = new SendOperation(Send);
 }
Example #14
0
        public static Func <Socket, ArraySegment <byte>, SocketFlags, AsyncOperationTask <int> > MakeSendOperation()
        {
            var op = new SendOperation();

            return(op.Run);
        }
Example #15
0
 protected QpidOutputChannelBase(BindingContext context, EndpointAddress address)
     : base(context)
 {
     _address    = address;
     _sendMethod = Send;
 }
 protected QpidOutputChannelBase(BindingContext context, EndpointAddress address)
     : base(context)
 {
     _address = address;
     _sendMethod = Send;
 }