internal void InterceptService(object service, bool add)
        {
            bool isDataExchangeService = false;

            Type[] interfaceTypes = service.GetType().GetInterfaces();
            foreach (Type type in interfaceTypes)
            {
                object[] attributes = type.GetCustomAttributes(typeof(ExternalDataExchangeAttribute), false);
                if (attributes.Length == 0)
                {
                    continue;
                }

                if (this.Runtime != null && this.Runtime.GetService(type) != null && add)
                {
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, SR.GetString(SR.Error_ExternalDataExchangeServiceExists), type));
                }

                isDataExchangeService = true;
                EventInfo[] events = type.GetEvents();
                if (events == null)
                {
                    continue;
                }

                foreach (EventInfo e in events)
                {
                    WorkflowMessageEventHandler handler = null;
                    int hash = type.GetHashCode() ^ e.Name.GetHashCode();
                    lock (handlersLock)
                    {
                        if (!this.eventHandlers.ContainsKey(hash))
                        {
                            handler = new WorkflowMessageEventHandler(type, e, this.enqueueMessageWrapper);
                            this.eventHandlers.Add(hash, handler);
                        }
                        else
                        {
                            handler = this.eventHandlers[hash];
                        }
                    }
                    AddRemove(service, handler.Delegate, add, e.Name);
                }
            }
            if (!isDataExchangeService)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, SR.GetString(SR.Error_ServiceMissingExternalDataExchangeInterface)));
            }
        }
Example #2
0
        internal void InterceptService(object service, bool add)
        {
            bool flag = false;

            foreach (Type type in service.GetType().GetInterfaces())
            {
                if (type.GetCustomAttributes(typeof(ExternalDataExchangeAttribute), false).Length != 0)
                {
                    if (((base.Runtime != null) && (base.Runtime.GetService(type) != null)) && add)
                    {
                        throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, SR.GetString("Error_ExternalDataExchangeServiceExists"), new object[] { type }));
                    }
                    flag = true;
                    EventInfo[] events = type.GetEvents();
                    if (events != null)
                    {
                        foreach (EventInfo info in events)
                        {
                            WorkflowMessageEventHandler handler = null;
                            int key = type.GetHashCode() ^ info.Name.GetHashCode();
                            lock (this.handlersLock)
                            {
                                if (!this.eventHandlers.ContainsKey(key))
                                {
                                    handler = new WorkflowMessageEventHandler(type, info, this.enqueueMessageWrapper);
                                    this.eventHandlers.Add(key, handler);
                                }
                                else
                                {
                                    handler = this.eventHandlers[key];
                                }
                            }
                            this.AddRemove(service, handler.Delegate, add, info.Name);
                        }
                    }
                }
            }
            if (!flag)
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, SR.GetString("Error_ServiceMissingExternalDataExchangeInterface"), new object[0]));
            }
        }
        internal void InterceptService(object service, bool add)
        {
            bool isDataExchangeService = false;
            Type[] interfaceTypes = service.GetType().GetInterfaces();
            foreach (Type type in interfaceTypes)
            {
                object[] attributes = type.GetCustomAttributes(typeof(ExternalDataExchangeAttribute), false);
                if (attributes.Length == 0)
                    continue;

                if (this.Runtime != null && this.Runtime.GetService(type) != null && add)
                    throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, SR.GetString(SR.Error_ExternalDataExchangeServiceExists), type));

                isDataExchangeService = true;
                EventInfo[] events = type.GetEvents();
                if (events == null)
                    continue;

                foreach (EventInfo e in events)
                {
                    WorkflowMessageEventHandler handler = null;
                    int hash = type.GetHashCode() ^ e.Name.GetHashCode();
                    lock (handlersLock)
                    {
                        if (!this.eventHandlers.ContainsKey(hash))
                        {
                            handler = new WorkflowMessageEventHandler(type, e, this.enqueueMessageWrapper);
                            this.eventHandlers.Add(hash, handler);
                        }
                        else
                        {
                            handler = this.eventHandlers[hash];
                        }
                    }
                    AddRemove(service, handler.Delegate, add, e.Name);
                }
            }
            if (!isDataExchangeService)
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, SR.GetString(SR.Error_ServiceMissingExternalDataExchangeInterface)));
        }
 internal void InterceptService(object service, bool add)
 {
     bool flag = false;
     foreach (Type type in service.GetType().GetInterfaces())
     {
         if (type.GetCustomAttributes(typeof(ExternalDataExchangeAttribute), false).Length != 0)
         {
             if (((base.Runtime != null) && (base.Runtime.GetService(type) != null)) && add)
             {
                 throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, SR.GetString("Error_ExternalDataExchangeServiceExists"), new object[] { type }));
             }
             flag = true;
             EventInfo[] events = type.GetEvents();
             if (events != null)
             {
                 foreach (EventInfo info in events)
                 {
                     WorkflowMessageEventHandler handler = null;
                     int key = type.GetHashCode() ^ info.Name.GetHashCode();
                     lock (this.handlersLock)
                     {
                         if (!this.eventHandlers.ContainsKey(key))
                         {
                             handler = new WorkflowMessageEventHandler(type, info, this.enqueueMessageWrapper);
                             this.eventHandlers.Add(key, handler);
                         }
                         else
                         {
                             handler = this.eventHandlers[key];
                         }
                     }
                     this.AddRemove(service, handler.Delegate, add, info.Name);
                 }
             }
         }
     }
     if (!flag)
     {
         throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, SR.GetString("Error_ServiceMissingExternalDataExchangeInterface"), new object[0]));
     }
 }