Exemplo n.º 1
0
 public ActivitySubscriber(ActivitySubscriberConfig subscriberConfig)
 {
     Guard.ArgumentNotNull <ActivitySubscriberConfig>(subscriberConfig);
     Guard.ArgumentNotEmpty(subscriberConfig.Name);
     this.subscriberConfig = subscriberConfig;
     this.activityFilter   = new ActivityFilterList(subscriberConfig.ActivityFilters);
 }
        private IActivityDispatcher BuildDispatcher(ActivitySubscriberConfig subscriberConfig)
        {
            if (string.IsNullOrEmpty(subscriberConfig.DispatcherImpl))
            {
                throw new DispatcherTypeNotSpecifiedException(subscriberConfig.Name);
            }
            Type dispatcherType = Type.GetType(subscriberConfig.DispatcherImpl);

            if (dispatcherType == null)
            {
                throw new TypeNotFoundException(subscriberConfig.DispatcherImpl);
            }
            ConstructorInfo ctor = dispatcherType.GetConstructor(new Type[]
            {
                typeof(ActivitySubscriberConfig)
            });

            if (ctor == null)
            {
                throw new DispatcherTypeInvalidException(subscriberConfig.DispatcherImpl);
            }
            return((IActivityDispatcher)ctor.Invoke(new object[]
            {
                subscriberConfig
            }));
        }
 public EsbInterfaceActivitySubscriber(ActivitySubscriberConfig subscriberConfig)
     : base(subscriberConfig)
 {
     Guard.ArgumentIsTrue(subscriberConfig.SubscriberType == ActivitySubscriberType.ESBInterface, "Wrong subscriber type: " + subscriberConfig.SubscriberType + ", must be ESBInterface");
     Guard.ArgumentNotEmpty(subscriberConfig.EsbInterfaceType);
     Guard.ArgumentNotEmpty(subscriberConfig.EsbMethod);
     this.esbInterfaceType = subscriberConfig.EsbInterfaceType;
     this.esbMethod        = subscriberConfig.EsbMethod;
 }
        private void ReloadConfig(object sender, EventArgs e)
        {
            List <IActivityDispatcher> dispatchers = new List <IActivityDispatcher>(this.activityDispatchers);
            ActivityEngineConfig       config      = BaseConfig <ActivityEngineConfig> .Instance;
            List <IActivityDispatcher> removeList  = new List <IActivityDispatcher>();

            foreach (IActivityDispatcher dispatcher4 in dispatchers)
            {
                if (!(dispatcher4 is EsbInterfaceActivityDispatcher) && !(dispatcher4 is RestfulActivityDispatcher))
                {
                    if (!config.ActivitySubscribers.Contains(dispatcher4.Name))
                    {
                        removeList.Add(dispatcher4);
                    }
                    else
                    {
                        ActivitySubscriberConfig subscriberConfig = config.GetActivitySubscriberConfig(dispatcher4.Name);
                        if (subscriberConfig.SubscriberType != ActivitySubscriberType.LocalDispatcher || !dispatcher4.GetType().AssemblyQualifiedName.StartsWith(subscriberConfig.DispatcherImpl ?? string.Empty))
                        {
                            removeList.Add(dispatcher4);
                        }
                    }
                }
            }
            foreach (IActivityDispatcher dispatcher2 in removeList)
            {
                dispatchers.Remove(dispatcher2);
            }
            foreach (IActivityDispatcher dispatcher in dispatchers)
            {
                Util.ExecuteWithCatch(delegate
                {
                    dispatcher.ReloadConfig();
                }
                                      );
            }
            Dictionary <string, string> map = new Dictionary <string, string>(dispatchers.Count);

            foreach (IActivityDispatcher dispatcher3 in dispatchers)
            {
                map.Add(dispatcher3.Name, string.Empty);
            }
            foreach (ActivitySubscriberConfig subscriber in config.ActivitySubscribers)
            {
                if (subscriber.SubscriberType == ActivitySubscriberType.LocalDispatcher && !map.ContainsKey(subscriber.Name))
                {
                    Util.ExecuteWithCatch(delegate
                    {
                        dispatchers.Add(this.BuildDispatcher(subscriber));
                    }
                                          );
                }
            }
            this.activityDispatchers = dispatchers;
        }
 public AbstractActivityDispatcher(ActivitySubscriberConfig subscriberConfig)
 {
     Guard.ArgumentNotNull <ActivitySubscriberConfig>(subscriberConfig);
     Guard.ArgumentNotEmpty(subscriberConfig.Name);
     this.Name           = subscriberConfig.Name;
     this.Enabled        = subscriberConfig.Enabled;
     this.activityFilter = new ActivityFilterList(subscriberConfig.ActivityFilters);
     this.activityQueue  = new PersistentQueueProcessor <Activity>(subscriberConfig.Name, TryHandleActivity);
     if (this.Enabled)
     {
         this.activityQueue.Start();
     }
 }
 public RestfulActivitySubscriber(ActivitySubscriberConfig subscriberConfig)
     : base(subscriberConfig)
 {
     Guard.ArgumentIsTrue(subscriberConfig.SubscriberType == ActivitySubscriberType.RESTful, "Wrong subscriber type: " + subscriberConfig.SubscriberType + ", must be RESTful");
     Guard.ArgumentNotEmpty(subscriberConfig.RestUrl);
     this.serializer = new JsonSerializer();
     if (subscriberConfig.JsonDateTimeFormat == JsonDateTimeFormat.IsoDateTime)
     {
         IsoDateTimeConverter converter = new IsoDateTimeConverter();
         converter.DateTimeFormat = "yyyy-MM-dd HH:mm:ss";
         this.serializer.Converters.Add(converter);
     }
     this.targetUrl = subscriberConfig.RestUrl;
 }
        public virtual void ReloadConfig()
        {
            ActivitySubscriberConfig subscriberConfig = BaseConfig <ActivityEngineConfig> .Instance.GetActivitySubscriberConfig(this.Name);

            if (subscriberConfig == null)
            {
                this.Enabled = false;
                this.activityQueue.Stop();
                return;
            }
            this.Enabled        = subscriberConfig.Enabled;
            this.activityFilter = new ActivityFilterList(subscriberConfig.ActivityFilters);
            if (this.Enabled)
            {
                this.activityQueue.Start();
                return;
            }
            this.activityQueue.Stop();
        }