Example #1
0
        private void ExecuteRequest(TRequest requestTypeIdentifier, SubsystemRequest request)
        {
            if (_requestExecutionInfos.ContainsKey(requestTypeIdentifier) == false)
            {
                throw new NotSupportedException("Not supported request detected");
            }

            _logger.DebugFormat("Executing request in '{0}'", SubsystemIdentifier);

            Type requestCtxType = typeof(RequestContext <,>);

            requestCtxType = requestCtxType.MakeGenericType(request.GetType(), request.ResponseType);

            ConstructorInfo ctor = requestCtxType.GetConstructor(new Type[] { request.GetType(), typeof(EndpointContext) });

            if (ctor == null)
            {
                throw new NotSupportedException("RequestContext does not contain apropriate constructor");
            }

            object requestContext = ctor.Invoke(new object[] { request, _context });

            _logger.DebugFormat("Executing request '{0}'", request);
            _requestExecutionInfos[requestTypeIdentifier].Callback.DynamicInvoke(this, requestContext);
        }
Example #2
0
        /// <summary>
        /// Reads the RequestType from the stream, creates the appropriate request object, populates it and executes the request (calls the handler)
        /// </summary>
        /// <param name="packet"></param>
        public virtual void HandlePacket(DataPacket packet)
        {
            _logger.DebugFormat("Handling request in '{0}'", SubsystemIdentifier);
            using (ByteStream src = new ByteStream(packet.Payload))
            {
                TRequest         requestTypeIdentifier = (TRequest)Enum.ToObject(typeof(TRequest), StreamHelper.ReadUInt16(src));
                SubsystemRequest request = CreateRequestFromIdentifier(requestTypeIdentifier);
                request.Read(src);
                request.PacketIdentifier = new PacketIdentifier(packet.PacketNr);

                ExecuteRequest(requestTypeIdentifier, request);
            }
        }
 public NoResponse(SubsystemRequest request, EndpointContext ctx)
     : base(request, ctx)
 {
 }
Example #4
0
 public SubsystemResponse(SubsystemRequest request, EndpointContext ctx)
     : base(ctx)
 {
     _request = request;
 }
Example #5
0
 public SubsystemResponse(SubsystemRequest request, EndpointContext ctx)
     : base(ctx)
 {
     _request = request;
 }