Exemplo n.º 1
0
        /// <summary>
        /// Intercepts delegate parameters.
        /// </summary>
        /// <param name="details">Invocation details</param>
        private void Invoke_InterceptDelegateParams(InvocationDetails details)
        {
            var serverMethodParamDefs = details.MethodInfo.GetParameters();

            foreach (int index in details.DelegateParamIndexes.Keys)
            {
                var delegateParamInterceptor = details.DelegateParamIndexes[index];
                var serverMethodParamDef     = serverMethodParamDefs[index];

                var dynamicWire = DynamicWireFactory.CreateDynamicWire(details.Type, serverMethodParamDef.ParameterType);
                dynamicWire.Interceptor = delegateParamInterceptor;
                details.Args[index]     = dynamicWire.InDelegate;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Removes wires between server and client components (as defined in correlation set).
        /// </summary>
        /// <param name="type">Type of the server component</param>
        /// <param name="eventStub"><see cref="EventStub"/> with cached subscriptions.</param>
        /// <param name="delegateCorrelationSet">Correlation set with wiring information</param>
        /// <param name="wiringList">List with known wirings</param>
        private void RemoveClientServerWires(Type type, EventStub eventStub, IEnumerable <DelegateCorrelationInfo> delegateCorrelationSet, Dictionary <Guid, Delegate> wiringList)
        {
            if (delegateCorrelationSet == null)
            {
                return;
            }

            var currentSession = ServerSession.CurrentSession;

            foreach (var correlationInfo in delegateCorrelationSet)
            {
                if (wiringList.ContainsKey(correlationInfo.CorrelationID))
                {
                    lock (wiringList)
                    {
                        if (!wiringList.ContainsKey(correlationInfo.CorrelationID))
                        {
                            continue;
                        }

                        var dynamicWireDelegate = wiringList[correlationInfo.CorrelationID];
                        eventStub.RemoveHandler(correlationInfo.DelegateMemberName, dynamicWireDelegate);
                        wiringList.Remove(correlationInfo.CorrelationID);

                        var dynamicWire = DynamicWireFactory.GetDynamicWire(dynamicWireDelegate);
                        if (dynamicWire != null)
                        {
                            dynamicWire.Dispose();
                        }
                    }

                    _host.OnSubscriptionRemoved(new SubscriptionEventArgs
                    {
                        ComponentType      = type,
                        DelegateMemberName = correlationInfo.DelegateMemberName,
                        CorrelationID      = correlationInfo.CorrelationID,
                    });
                }
            }

            if (currentSession != null)
            {
                currentSession.UntrackRemoteSubscriptions(delegateCorrelationSet);
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Creates wires between client component and server component.
        /// </summary>
        /// <param name="type">Implementation type of the server component.</param>
        /// <param name="eventStub"><see cref="EventStub"/> with cached subscriptions.</param>
        /// <param name="delegateCorrelationSet">Correlation set (say how to wire)</param>
        /// <param name="wiringList">Collection of built wires</param>
        private void CreateClientServerWires(Type type, EventStub eventStub, List <DelegateCorrelationInfo> delegateCorrelationSet, Dictionary <Guid, Delegate> wiringList)
        {
            if (delegateCorrelationSet == null)
            {
                return;
            }

            foreach (var correlationInfo in delegateCorrelationSet)
            {
                if (wiringList.ContainsKey(correlationInfo.CorrelationID))
                {
                    continue;
                }

                if (ServerSession.CurrentSession == null)
                {
                    throw new InvalidSessionException(string.Format(LanguageResource.InvalidSessionException_SessionIDInvalid, "(null)"));
                }

                var dynamicWire = DynamicWireFactory.CreateDynamicWire(type, correlationInfo.DelegateMemberName, correlationInfo.IsEvent);
                dynamicWire.Interceptor = correlationInfo.ClientDelegateInterceptor;

                if (correlationInfo.IsEvent)
                {
                    var dynamicEventWire = (DynamicEventWireBase)dynamicWire;
                    dynamicEventWire.EventFilter = correlationInfo.EventFilter;

                    // add session validation handler and unsubscription callback
                    var sessionId      = ServerSession.CurrentSession.SessionID;
                    var sessionManager = _host.SessionManager;
                    dynamicEventWire.ValidateSession    = () => sessionManager.ExistSession(sessionId);
                    dynamicEventWire.CancelSubscription = () => eventStub.RemoveHandler(correlationInfo.DelegateMemberName, dynamicEventWire.InDelegate);

                    eventStub.AddHandler(correlationInfo.DelegateMemberName, dynamicEventWire.InDelegate);
                    wiringList.Add(correlationInfo.CorrelationID, dynamicEventWire.InDelegate);
                }
                else
                {
                    eventStub.AddHandler(correlationInfo.DelegateMemberName, dynamicWire.InDelegate);
                    wiringList.Add(correlationInfo.CorrelationID, dynamicWire.InDelegate);
                }
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates wires between client component and server component.
        /// </summary>
        /// <param name="type">Implementation type of the server component.</param>
        /// <param name="eventStub"><see cref="EventStub"/> with cached subscriptions.</param>
        /// <param name="delegateCorrelationSet">Correlation set (say how to wire)</param>
        /// <param name="wiringList">Collection of built wires</param>
        private void CreateClientServerWires(Type type, EventStub eventStub, IEnumerable <DelegateCorrelationInfo> delegateCorrelationSet, Dictionary <Guid, Delegate> wiringList)
        {
            if (delegateCorrelationSet == null)
            {
                return;
            }

            var currentSession = ServerSession.CurrentSession;

            if (currentSession == null)
            {
                throw new InvalidSessionException(string.Format(LanguageResource.InvalidSessionException_SessionIDInvalid, "(null)"));
            }

            foreach (var correlationInfo in delegateCorrelationSet)
            {
                if (wiringList.ContainsKey(correlationInfo.CorrelationID))
                {
                    continue;
                }

                var dynamicWire = DynamicWireFactory.CreateDynamicWire(type, correlationInfo.DelegateMemberName, correlationInfo.IsEvent);
                dynamicWire.Interceptor = correlationInfo.ClientDelegateInterceptor;

                lock (wiringList)
                {
                    if (wiringList.ContainsKey(correlationInfo.CorrelationID))
                    {
                        continue;
                    }

                    if (correlationInfo.IsEvent)
                    {
                        var dynamicEventWire = (DynamicEventWireBase)dynamicWire;
                        dynamicEventWire.EventFilter = correlationInfo.EventFilter;

                        // add session validation handler and unsubscription callback
                        var sessionId      = currentSession.SessionID;
                        var sessionManager = _host.SessionManager;
                        dynamicEventWire.ValidateSession    = () => sessionManager.ExistSession(sessionId);
                        dynamicEventWire.CancelSubscription = ex =>
                        {
                            eventStub.RemoveHandler(correlationInfo.DelegateMemberName, dynamicEventWire.InDelegate);
                            wiringList.Remove(correlationInfo.CorrelationID);
                            currentSession.DecrementRemoteSubscriptionCounter();
                            _host.OnSubscriptionCanceled(new SubscriptionEventArgs
                            {
                                ComponentType      = type,
                                DelegateMemberName = correlationInfo.DelegateMemberName,
                                CorrelationID      = correlationInfo.CorrelationID,
                                Exception          = ex
                            });
                        };

                        eventStub.AddHandler(correlationInfo.DelegateMemberName, dynamicEventWire.InDelegate);
                        wiringList.Add(correlationInfo.CorrelationID, dynamicEventWire.InDelegate);
                    }
                    else
                    {
                        eventStub.AddHandler(correlationInfo.DelegateMemberName, dynamicWire.InDelegate);
                        wiringList.Add(correlationInfo.CorrelationID, dynamicWire.InDelegate);
                    }
                }

                currentSession.IncrementRemoteSubscriptionCounter();
                _host.OnSubscriptionAdded(new SubscriptionEventArgs
                {
                    ComponentType      = type,
                    DelegateMemberName = correlationInfo.DelegateMemberName,
                    CorrelationID      = correlationInfo.CorrelationID,
                });
            }
        }