Ejemplo n.º 1
0
        public static void Setup()
        {
            var assambly = Assembly.GetAssembly(typeof(Program));
            var config   = Configuration.Create()
                           .UseAutofac()
                           .RegisterCommonComponents()
                           .UseLog4Net()
                           .UseJsonNet()
                           .UseMassTransit(new[] { assambly })
                           .UseKafka();

            using (var log = ObjectContainer.Current.BeginLifetimeScope())
            {
                _logger = log.Resolve <ILoggerFactory>().Create(typeof(Program).Name);
            }
            //config.SetDefault<IRequestClient<Request, RequestResult>, RequestClient<Request, RequestResult>>();
            using (var scope = ObjectContainer.BeginLifetimeScope())
            {
                _bus = scope.Resolve <IBus>();
            }
            using (var scope = ObjectContainer.BeginLifetimeScope())
            {
                //_eventBus = scope.Resolve<IEventBus>();
                _conn   = scope.Resolve <IConnectionPool>();
                factory = scope.Resolve <IConsumerClientFactory>();
            }
        }
Ejemplo n.º 2
0
        public static Configuration UseRabbitMQ(this Configuration configuration, Action <Setting> rabbitmqSetting = null)
        {
            using (var scope = ObjectContainer.BeginLifetimeScope())
            {
                var logger         = scope.Resolve <ILoggerFactory>();
                var jsonSerializer = scope.Resolve <IJsonSerializer>();
                var setting        = new Setting();
                rabbitmqSetting(setting);

                var factory = new ConnectionFactory()
                {
                    HostName    = setting.HostName,
                    Port        = setting.Port,
                    VirtualHost = setting.VirtualHost,
                    UserName    = setting.UserName,
                    Password    = setting.Password,
                    AutomaticRecoveryEnabled   = setting.AutomaticRecoveryEnabled,
                    RequestedConnectionTimeout = setting.RequestedConnectionTimeout
                };
                DefaultRabbitMQPersistentConnection conn = new DefaultRabbitMQPersistentConnection(factory, logger, jsonSerializer);

                configuration = configuration.SetDefault <IRabbitMQPersistentConnection, DefaultRabbitMQPersistentConnection>(conn);
            }
            return(configuration);
        }
Ejemplo n.º 3
0
        public static void Setup()
        {
            var assambly = Assembly.GetAssembly(typeof(Program));
            var config   = ESS.FW.Common.Configurations.Configuration.Create()
                           .UseAutofac()
                           .RegisterCommonComponents()
                           //.UseEntLibLog()
            ;

            //config.SetDefault<IConsumeObserver, ConsumeObserver>(LifeStyle.Transient);

            //config.SetDefault<IIdGenerator, IdGeneratorRepository>(LifeStyle.Transient);

            //config.UseEfRepository(typeof(JztDbContext));

            config.SetDefault <ILoggerFactory, LoggerFactory>();
            var busConfig = new BusConfig()
            {
                Ip       = "10.3.5.95",
                UserName = "******",
                Password = "******"
            };

            config.UseMassTransit(busConfig, new[] { assambly });

            using (var scope = ObjectContainer.BeginLifetimeScope())
            {
                _bus = scope.Resolve <IBus>();
            }
        }
Ejemplo n.º 4
0
 static ExceptionHandler()
 {
     using (var scope = ObjectContainer.BeginLifetimeScope())
     {
         _logger = scope.Resolve <ILoggerFactory>().Create(typeof(ExceptionHandler));
     }
 }
Ejemplo n.º 5
0
        public void DropDb()
        {
            IList <string> sqlToDrop = new List <string>()
            {
                //GetDbFile("drop\\oracle.drop.case.engine-tb_bpm_.sql"),
                //GetDbFile("drop\\oracle.drop.case.history-tb_bpm_.sql"),
                //GetDbFile("drop\\oracle.drop.decision.engine-tb_bpm_.sql"),
                //GetDbFile("drop\\oracle.drop.decision.history-tb_bpm_.sql"),
                //GetDbFile("drop\\oracle.drop.identity-tb_bpm_.sql"),
                GetDbFile("drop\\oracle.drop.engine-tb_bpm_.sql"),
            };

            using (IScope scope = ObjectContainer.BeginLifetimeScope())
            {
                DbContext uof = scope.Resolve <DbContext>();
                foreach (var item in sqlToDrop)
                {
                    try
                    {
                        uof.Database.ExecuteSqlCommand(item);
                    }
                    catch (System.Exception e)
                    {
                        Log.LogDebug("数据表删除失败", e.Message);
                    }
                }
                uof.SaveChanges();
            }
        }
Ejemplo n.º 6
0
 public ExpressionTranslator()
 {
     using (var scope = ObjectContainer.BeginLifetimeScope())
     {
         _logger = scope.Resolve <ILoggerFactory>().CreateLogger(GetType());
     }
 }
Ejemplo n.º 7
0
        private static void SetLookupValue(object m, Dictionary <PropertyInfo, LookupQueryAttribute> lookups)
        {
            if (m == null)
            {
                return;
            }
            foreach (var lookup in lookups)
            {
                var attr        = lookup.Value;
                var serviceType = GetServiceType(attr.ServiceType);
                var method      = GetMethod(attr);

                var parameter = new ArrayList();

                if (!string.IsNullOrEmpty(attr.PropertyName))
                {
                    var propertyNames = attr.PropertyName.Split(',');

                    foreach (var name in propertyNames)
                    {
                        var property =
                            GetProperties(TypeUtils.GetPureType(m.GetType())).FirstOrDefault(c => c.Name == name);

                        if (property == null)
                        {
                            continue;
                        }

                        var value = property.GetValue(m);
                        parameter.Add(value?.ToString() ?? "");
                    }

                    //var properties =
                    //    GetProperties(TypeUtils.GetPureType(m.GetType()))
                    //        .Where(c => propertyNames.Any(t => t == c.Name));

                    //foreach (var p in properties)
                    //{
                    //    parameter.Add(p.GetValue(m));
                    //}
                }

                if (!string.IsNullOrEmpty(attr.ConstValue))
                {
                    parameter.AddRange(attr.ConstValue.Split(','));
                }
                //TODO 可能有性能问题
                using (var scope = ObjectContainer.BeginLifetimeScope())
                {
                    var service = scope.Resolve(serviceType);
                    Ensure.NotNull(service, "LookupQueryInterceptor - service:" + service);
                    var val = method.Invoke(service, parameter.ToArray());
                    if (lookup.Key.PropertyType.IsInstanceOfType(val))
                    {
                        lookup.Key.SetValue(m, val);
                    }
                }
            }
        }
Ejemplo n.º 8
0
 public void DeploymentEntityConvertTest()
 {
     using (var scope = ObjectContainer.BeginLifetimeScope())
     {
         var repository = scope.Resolve <IRepository <DeploymentEntity, string> >();
         var depls      = repository.GetAll().ToList();
         var str        = JsonConvert.SerializeObject(depls);
         var obj        = JsonConvert.DeserializeObject <IList <DeploymentEntity> >(str);
     }
 }
 public void Component_should_be_interceptor_by_measureInterceptor_and_logInterceptor()
 {
     if (ObjectContainer.Current == null)
     {
         Configurations.Configuration.Create().UseAutofac().RegisterCommonComponents();
     }
     using (var scope = ObjectContainer.BeginLifetimeScope())
     {
         ObjectContainer.RegisterComponent <MeasureAndLogComponent>();
         IPublicInterface obj = scope.Resolve <IPublicInterface>();
         Assert.AreEqual(13, obj.PublicMethod());
     }
 }
        public override object GetValue(ELContext context, object @base, object property)
        {
            if (property != null)
            {
                var @object = context.GetContext(typeof(IScope));
                if (@object != null)
                {
                    var  variableScope = (Dictionary <string, Type>)@object;
                    Type type;
                    variableScope.TryGetValue(property.ToString(), out type);
                    if (type != null)
                    {
                        if (IsResolvable(type))
                        {
                            if (Context.CommandContext.Scope != null)
                            {
                                if (Context.CommandContext.Scope.IsRegistered(type))
                                {
                                    var val = Context.CommandContext.Scope.Resolve(type);
                                    context.PropertyResolved = true;
                                    return(val);
                                }
                            }
                            else
                            {
                                using (var scope = ObjectContainer.BeginLifetimeScope())
                                {
                                    if (scope.IsRegistered(type))
                                    {
                                        var val = scope.Resolve(type);
                                        context.PropertyResolved = true;
                                        return(val);
                                    }
                                }
                            }
                        }
                    }
                }
            }

            return(null);
        }
        public void Component_should_be_interceptor_by_measureInterceptor()
        {
            Configurations.Configuration.Create().UseAutofac().RegisterCommonComponents();
            using (var scope = ObjectContainer.BeginLifetimeScope())
            {
                Stopwatch st = new Stopwatch();
                //ObjectContainer.Register<ILoggerFactory, EntLibLoggerFactory>();
                st.Start();
                ObjectContainer.RegisterComponent <MeasureComponent>();
                IPublicInterface obj = scope.Resolve <IPublicInterface>();
                Assert.AreEqual(12, obj.PublicMethod());


                ObjectContainer.RegisterComponent <MeasureComponent2>();
                obj = scope.Resolve <IPublicInterface>();
                Assert.AreEqual(12, obj.PublicMethod());
                st.Stop();
                Debug.WriteLine(st.Elapsed);
            }
        }
Ejemplo n.º 12
0
 protected internal virtual byte[] ReadSerializedValueFromFields(IValueFields valueFields)
 {
     if (valueFields.ByteArrayValue == null && !string.IsNullOrEmpty(valueFields.ByteArrayId))
     {
         if (context.Impl.Context.CommandContext != null)
         {
             var bytearr = context.Impl.Context.CommandContext.ByteArrayManager.Get(valueFields.ByteArrayId);
             valueFields.ByteArrayValue = bytearr.Bytes;
         }
         else
         {
             using (IScope scope = ObjectContainer.BeginLifetimeScope())
             {
                 IByteArrayManager manager = scope.Resolve <IByteArrayManager>();
                 var bytearr = manager.Get(valueFields.ByteArrayId);
                 valueFields.ByteArrayValue = bytearr.Bytes;
             }
         }
     }
     return(valueFields.ByteArrayValue);
 }
Ejemplo n.º 13
0
        public static void Setup()
        {
            var busConfig = new BusConfig()
            {
                Ip       = "10.3.5.95",
                UserName = "******",
                Password = "******"
            };
            var assambly = Assembly.GetAssembly(typeof(Program));
            var config   = ESS.FW.Common.Configurations.Configuration.Create()
                           .UseAutofac()
                           .RegisterCommonComponents();

            config.SetDefault <ILoggerFactory, LoggerFactory>();

            config.UseMassTransit(busConfig, new[] { assambly });

            using (var scope = ObjectContainer.BeginLifetimeScope())
            {
                _bus = scope.Resolve <ESS.FW.Common.ServiceBus.IBus>();
            }
        }
Ejemplo n.º 14
0
        public static Configuration UseRabbitMQ(this Configuration configuration, string hostName, string virtualHost, string userName, string passWord, int port = 5672)
        {
            using (var scope = ObjectContainer.BeginLifetimeScope())
            {
                var logger         = scope.Resolve <ILoggerFactory>();
                var jsonSerializer = scope.Resolve <IJsonSerializer>();

                var factory = new ConnectionFactory()
                {
                    HostName    = hostName ?? "localhost",
                    Port        = port,
                    VirtualHost = virtualHost ?? "/",
                    UserName    = userName ?? "guest",
                    Password    = passWord ?? "guest",
                    AutomaticRecoveryEnabled   = true,
                    RequestedConnectionTimeout = 15000
                };
                DefaultRabbitMQPersistentConnection conn = new DefaultRabbitMQPersistentConnection(factory, logger, jsonSerializer);

                configuration = configuration.SetDefault <IRabbitMQPersistentConnection, DefaultRabbitMQPersistentConnection>(conn);
            }
            return(configuration);
        }
Ejemplo n.º 15
0
 public virtual void SetByteArrayValue(byte[] bytes)
 {
     if (bytes != null)
     {
         if (byteArrayId != null && ResourceEntity != null)
         {
             byteArrayValue.Bytes = bytes;
         }
         else
         {
             DeleteByteArrayValue();
             //TODO 每次新建ResourceEntity?
             if (Context.CommandContext != null)
             {
                 byteArrayValue = new ResourceEntity(NameProvider.Name, bytes);
                 Context.CommandContext.ByteArrayManager.Add(byteArrayValue);
                 byteArrayId = byteArrayValue.Id;
             }
             else//TODO 不在cmd中
             {
                 using (IScope scope = ObjectContainer.BeginLifetimeScope())
                 {
                     IByteArrayManager manager = scope.Resolve <IByteArrayManager>();
                     byteArrayValue = new ResourceEntity(NameProvider.Name, bytes);
                     var bytearr = manager.Add(byteArrayValue);
                     byteArrayId = byteArrayValue.Id;
                 }
                 //throw new System.NotImplementedException("CommandContext is null");
             }
         }
     }
     else
     {
         DeleteByteArrayValue();
     }
 }
Ejemplo n.º 16
0
        public override CommandContext CreateCommandContext()
        {
            IScope scope = ObjectContainer.BeginLifetimeScope();

            return(new CommandContext(processEngineConfiguration, transactionContextFactory, scope));
        }
Ejemplo n.º 17
0
        private static void Main(string[] args)
        {
            Setup();

            while (true)
            {
                Console.WriteLine("Enter message (or quit to exit)");
                Console.Write("> ");
                var value = Console.ReadLine();

                if ("quit".Equals(value, StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }

                var message = new HpImplementation {
                    SystemVersion = value + "-" + DateTime.Now
                };
                if ("send".Equals(value, StringComparison.OrdinalIgnoreCase))
                {
                    _bus.Send("MassTransit.Tests.Consumer", message);
                }
                else if ("rr" == value)
                {
                    using (var scope = ObjectContainer.BeginLifetimeScope())
                    {
                        var client = scope.Resolve <ESS.FW.Common.ServiceBus.IRequestClient <Request, RequestResult> >();
                        Task.Run(() =>
                        {
                            var result =
                                client.Request("MassTransit.Tests.Consumer",
                                               new Request {
                                Message = "request"
                            }, new CancellationToken()).Result;
                            Console.WriteLine(result.Message);
                        });
                    }
                }
                //else if ("trans" == value)
                //    _bus.Publish(new TransactionEvent { Message = "transaction test" });
                else if ("order" == value)
                {
                    for (var i = 0; i < 100; i++)
                    {
                        _bus.Send("MassTransit.Tests.Consumer",
                                  new HpImplementation {
                            SystemVersion = i + "-" + DateTime.Now
                        }, true);
                    }
                }
                //else if ("orderp" == value)
                //    for (var i = 0; i < 100; i++)
                //        _bus.OrderPublish(
                //            new HpImplementation { SystemVersion = i + "-" + DateTime.Now });
                else if ("attr" == value)
                {
                    var msg = new AttributeEvent();
                    msg.Message = DateTime.Now.ToString();
                    _bus.Send("AttributeEvent", msg, true);
                }
                else
                {
                    _bus.Send("MassTransit.Tests.Consumer", message, true);
                }
            }

            Console.ReadKey();
        }
Ejemplo n.º 18
0
        public virtual CommandContext CreateCommandContext()
        {
            IScope scope = ObjectContainer.BeginLifetimeScope();

            return(new CommandContext(processEngineConfiguration, scope));
        }