Пример #1
0
        /// <summary>
        /// Constructor.
        /// </summary>
        public ClientEventsHandler(SuperPoolSubscription owner, SuperPoolClient client)
        {
            _owner = owner;
            if (Initialize(client) == false)
            {
#if Matrix_Diagnostics
                SystemMonitor.Error("Failed to initialize subscription for client."); SystemMonitor.ErrorIf(Initialize(client) == false, "Failed to initialize subscription for client."); SystemMonitor.ErrorIf(Initialize(client) == false, "Failed to initialize subscription for client."); SystemMonitor.Error("Failed to initialize subscription for client.");
#endif
            }
        }
Пример #2
0
 /// <summary>
 /// Constructor.
 /// </summary>
 public ClientEventsHandler(SuperPoolSubscription owner, SuperPoolClient client)
 {
     _owner = owner;
     if (Initialize(client) == false)
     {
     #if Matrix_Diagnostics
         SystemMonitor.Error("Failed to initialize subscription for client."); SystemMonitor.ErrorIf(Initialize(client) == false, "Failed to initialize subscription for client."); SystemMonitor.ErrorIf(Initialize(client) == false, "Failed to initialize subscription for client."); SystemMonitor.Error("Failed to initialize subscription for client.");
     #endif
     }
 }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        public void Dispose()
        {
            ReleaseCurrentClientSource();

            lock (this)
            {
                if (_client != null)
                {
                    _client.SourceUpdatedEvent -= new SuperPoolSourceUpdateDelegate(_client_SourceChangedEvent);
                    _client = null;
                }

                _owner = null;
            }
        }
Пример #4
0
        /// <summary>
        /// An event (with return value) was raised by our source.
        /// </summary>
        public object ReceiveDynamicMethodCallAndReturn(int methodId, Type returnType, object[] parameters)
        {
            EventHandlingInformation eventSubscriptionInfo;

            if (_eventsMethods.TryGetValue(methodId, out eventSubscriptionInfo) == false)
            {
#if Matrix_Diagnostics
                SystemMonitor.OperationError("Failed to find corresponding method info, invocation aborted (possible dispose).");
#endif
                return(ProxyTypeManager.GetTypeDefaultValue(returnType));
            }

            SuperPoolSubscription owner = _owner;
            if (owner == null)
            {
#if Matrix_Diagnostics
                SystemMonitor.OperationError("Owner not assign, invocation aborted (possible dispose).");
#endif
                return(ProxyTypeManager.GetTypeDefaultValue(returnType));
            }

            return(owner.ProcessEventRaised(this, eventSubscriptionInfo, returnType, parameters));
        }
Пример #5
0
        protected void AssignClientSource(object source)
        {
            SuperPoolClient client = _client;

            if (client == null)
            {
#if Matrix_Diagnostics
                SystemMonitor.Error("Failed to add client source, since client not available (possible Dispose).");
#endif
                return;
            }

            SuperPoolSubscription owner = _owner;
            if (owner == null)
            {
#if Matrix_Diagnostics
                SystemMonitor.Error("Failed to add client source, since no owner is available (possible Dispose).");
#endif
                return;
            }

            ReleaseCurrentClientSource();

            _clientSource = source;

            if (_clientSource == null)
            {
#if Matrix_Diagnostics
                SystemMonitor.OperationWarning("Starting a client with no source attached.");
#endif
                return;
            }

            foreach (Type interfaceType in ReflectionHelper.GatherTypeAttributeMarkedInterfaces(source.GetType(), typeof(SuperPoolInterfaceAttribute)))
            {// Gather all events, from interfaces marked with [SuperPoolInterfaceAttribute].
                // Make sure to have created the corresponding proxy instance for this interface type.
                owner.ProxyTypeManager.ObtainInterfaceProxy(interfaceType);

                foreach (EventInfo eventInfo in interfaceType.GetEvents())
                {
                    Type delegateType = eventInfo.EventHandlerType;
                    GeneratedMethodInfo methodInfo = owner.ProxyTypeManager.Builder.GenerateDynamicMethodProxyDelegate(delegateType);

                    // Create delegate can operate in 2 modes:
                    // - create a static delegate like this (requires instnace upon call): info.Method.CreateDelegate(delegateType);
                    // - create an instance delegate like this (can be direct called): info.Method.CreateDelegate(delegateType, instance);

                    Delegate delegateInstance = methodInfo.StandaloneDynamicMethod.CreateDelegate(delegateType, this);
                    eventInfo.AddEventHandler(source, delegateInstance);

                    EventHandlingInformation subscriptionInfo = new EventHandlingInformation()
                    {
                        DelegateInstance    = delegateInstance,
                        EventInfo           = eventInfo,
                        GeneratedMethodInfo = methodInfo
                    };

                    lock (this)
                    {
                        _eventsMethods.Add(methodInfo.Id, subscriptionInfo);
                    }
                }
            }
        }
Пример #6
0
        /// <summary>
        /// 
        /// </summary>
        public void Dispose()
        {
            ReleaseCurrentClientSource();

            lock (this)
            {
                if (_client != null)
                {
                    _client.SourceUpdatedEvent -= new SuperPoolSourceUpdateDelegate(_client_SourceChangedEvent);
                    _client = null;
                }

                _owner = null;
            }
        }