Esempio n. 1
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // set...
            // TODO: use typefinder...
//			this.listConnectionTypes.Items.Add(new ConnectionType(typeof(SqlServerConnection), "SQL Server"));
//			this.listConnectionTypes.Items.Add(new ConnectionType(typeof(OracleConnection), "Oracle"));
//			this.listConnectionTypes.Items.Add(new ConnectionType(typeof(MySqlConnection), "MySQL"));

            // mbr - 2008-08-31 - added typefinder for the others...
            TypeFinder finder = new TypeFinder(typeof(Connection));

            finder.AddAttributeSpecification(typeof(ConnectionAttribute), false);
            foreach (Type type in finder.GetTypes())
            {
                this.listConnectionTypes.Items.Add(new ConnectionType(type, Runtime.Current.GetDescription(type)));
            }

            // set...
            for (int index = 0; index < this.listConnectionTypes.Items.Count; index++)
            {
                if (((ConnectionType)this.listConnectionTypes.Items[index]).Type == typeof(SqlServerConnection))
                {
                    this.listConnectionTypes.SelectedIndex = index;
                    break;
                }
            }
        }
Esempio n. 2
0
        public static IServiceCollection AddEventBus(this IServiceCollection service)
        {
            //获取所有事件处理器,并将所有处理器进行依赖注入
            var types = TypeFinder.GetTypes(type => type.IsClass && type.GetInterface(typeof(IEventHandler <>).Name) != null);

            foreach (var type in types)
            {
                service.AddSingleton(type);
            }
            //注册全球事件总线
            service.AddSingleton <IEventBus, EventBus>(serviceProvider =>
            {
                var instance = new EventBus(serviceProvider);
                foreach (var type in types)
                {
                    foreach (var @interface in type.GetInterfaces())
                    {
                        if (@interface.Name == typeof(IEventHandler <>).Name)
                        {
                            //对事件处理器进行订阅
                            instance.Subscribe(@interface.GetGenericArguments()[0], type);
                        }
                    }
                }
                return(instance);
            });
            return(service);
        }
Esempio n. 3
0
 public bool Fill(string configName, string key, string data, ClientEndpointInfo info)
 {
     if (string.IsNullOrWhiteSpace(data))
     {
         return(false);
     }
     info.ContractType = Type.GetType(data, false);
     if ((info.ContractType == null) || !info.ContractType.IsInterface)
     {
         return(false);
     }
     try
     {
         info.ClientType = TypeFinder.GetTypes(info.ContractType.Assembly, info.ContractType).FirstOrDefault <Type>();
     }
     catch (Exception exception)
     {
         string log = exception.Message;
         // 写日志............
     }
     if (info.ClientType == null)
     {
         throw new InvalidOperationException(string.Format("您配置接口类型{0}不是Thrift生成的接口类型,请修改{1}节点", data, configName));
     }
     return(true);
 }
Esempio n. 4
0
 public static IContainer RegisterFromAssembly(this IContainer container, Assembly assembly)
 {
     foreach (Type type in TypeFinder.GetTypes(assembly))
     {
         AutoRegister(container, type);
     }
     return(container);
 }
Esempio n. 5
0
 public static IContainer RegisterFromProductName(this IContainer container, string productName)
 {
     Guard.ThrowIfArgumentIsNullOrEmpty(productName, "productName");
     foreach (Type type in TypeFinder.GetTypes(productName))
     {
         AutoRegister(container, type);
     }
     return(container);
 }
Esempio n. 6
0
 private static void ExecuteRegisterTypes()
 {
     Type[] typeArray = TypeFinder.GetTypes(typeof(IRegisterType)).ToArray <Type>();
     //ILog log = LogBuilder.Create("Cicada.Boot");
     object[] args = new object[] { typeArray.Length };
     //log.Trace("自动加载类型注册模块,共发现【{0}】个", args);
     foreach (Type type in typeArray)
     {
         object[] objArray2 = new object[] { type.FullName };
         //log.Trace("加载类型注册模块,类型:{0}", objArray2);
         ((IRegisterType)ContainerSingleton.Instance.Resolve(type)).RegisterTypes(ContainerSingleton.Instance);
     }
 }
Esempio n. 7
0
        /// <summary>
        /// Gets the control types for the given entity type.
        /// </summary>
        /// <param name="entityType"></param>
        /// <returns></returns>
        private static Type[] GetControlTypesForEntityType(Type entityType)
        {
            if (entityType == null)
            {
                throw new ArgumentNullException("entityType");
            }

            // get them...
            TypeFinder finder = new TypeFinder(typeof(Control));

            finder.AddAttributeSpecification(typeof(PropertyPageAttribute), false, "EntityType", entityType);

            // return...
            return(finder.GetTypes());
        }
Esempio n. 8
0
        private static void ExecuteModules()
        {
            Type[] source = TypeFinder.GetTypes(typeof(IModuleType)).ToArray <Type>();
            //ILog log = LogBuilder.Create("Cicada.Boot");
            object[] args = new object[] { source.Length };
            //log.Trace("自动加载模块单元,共发现【{0}】个", args);
            IConfigsType config = ContainerSingleton.Instance.Resolve <IConfigsType>();

            foreach (IModuleType boot in (from impType in source.Where <Type>(new Func <Type, bool>(ModulesLoad.Where))
                                          .OrderBy <Type, int>(new Func <Type, int>(ModulesLoad.GetOrder))
                                          select(IModuleType) ContainerSingleton.Instance.Resolve(impType))
                     .ToArray <IModuleType>())
            {
                object[] objArray2 = new object[]
                {
                    boot.GetType().FullName
                };
                //log.Trace("加载模块,类型:{0}", objArray2);
                boot.Execute(config);
            }
        }
Esempio n. 9
0
        /// <summary>
        /// Creates ot updates the database.
        /// </summary>
        /// <param name="create"></param>
        /// <param name="checkOnly"></param>
        // mbr - 28-09-2007 - case 814 - added args.
        private DatabaseUpdateCheckResults CreateUpdateDatabase(IOperationItem operation, bool create, bool checkOnly,
                                                                DatabaseUpdateArgs args)
        {
            if (args == null)
            {
                throw new ArgumentNullException("args");
            }

            // operation...
            if (operation == null)
            {
                operation = new OperationItem();
            }

            // set...
            operation.Status = "Loading existing schema...";

            // database...
            SqlSchema databaseSchema = null;

            if (create)
            {
                databaseSchema = new SqlSchema();
            }
            else
            {
                if (args.Trace)
                {
                    this.LogInfo(() => "Loading schema...");
                }

                // mbr - 28-09-2007 - case 814 - defer to a method that can limit the types...
//				databaseSchema = Database.GetSchema();fic
                databaseSchema = this.GetSchema(args);
                if (databaseSchema == null)
                {
                    throw new InvalidOperationException("databaseSchema is null.");
                }
            }

            // Create an entity schema
            SqlSchema entitySchema = new SqlSchema();

            // Load all the entity types from the path
            ArrayList entityTypes = new ArrayList();

            // mbr - 02-10-2007 - for c7 - changed so that we can limit the entity types...
            if (args.LimitEntityTypes.Count == 0)
            {
                // mbr - 04-10-2007 - case 851 - do not do this behaviour (oddly both of these statements are
                // actually identical),
//				entityTypes.AddRange(EntityType.GetAllEntityTypes());
//				this.MergeEntityTypes(entityTypes, EntityType.LoadFromAttributes(AssemblyPath));
//				foreach(Assembly asm in this.Assemblies)
//					this.MergeEntityTypes(entityTypes, EntityType.LoadFromAttributes(asm));

                // load...
                this.MergeEntityTypes(entityTypes, EntityType.GetEntityTypes());
            }
            else
            {
                this.MergeEntityTypes(entityTypes, args.LimitEntityTypes);
            }

            // log...
            if (args.Trace)
            {
                this.LogInfo(() => string.Format("Found '{0}' entity types.", entityTypes.Count));
            }

            // steps...
            DatabaseUpdateStepCollection steps = new DatabaseUpdateStepCollection();

            if (args.AddArrayParameterUdts)
            {
                steps.Add(new AddArrayParameterUdtsUpdateStep());
            }

            SyncSchemaDatabaseUpdateStep syncStep = new SyncSchemaDatabaseUpdateStep();

            steps.Add(syncStep);

            // mbr - 02-03-2006 - we can have update steps that don't have an entity type...
            TypeFinder finder = new TypeFinder(typeof(DatabaseUpdateStep));

            finder.AddAttributeSpecification(typeof(DatabaseUpdateStepAttribute), false);
            Type[] stepTypes = finder.GetTypes();
            if (stepTypes == null)
            {
                throw new InvalidOperationException("stepTypes is null.");
            }

            // mbr - 02-10-2007 - for c7...
            if (Database.ExtensibilityProvider == null)
            {
                throw new InvalidOperationException("Database.ExtensibilityProvider is null.");
            }

            // Walk each entity type and add to entitySchema
            foreach (EntityType entityType in entityTypes)
            {
                // mbr - 14-12-2005 - should we do it?
                bool skip = entityType.Type.IsDefined(typeof(SkipDatabaseUpdateAttribute), false);

                // mbr - 2010-01-29 - changed the log here to allow db update to do named databases...
//				if(!(skip) && entityType.UsesDefaultDatabase)
                bool ok = false;
                if (!(skip))
                {
                    // no named database, and entity has no named database...
                    if (!(args.HasDatabaseName) && entityType.UsesDefaultDatabase)
                    {
                        ok = true;
                    }
                    else if (args.HasDatabaseName && string.Compare(entityType.DatabaseName, args.DatabaseName, true, Cultures.System) == 0)
                    {
                        ok = true;
                    }
                }
                else
                {
                    ok = false;
                }

                // do we do it?
                if (ok)
                {
                    if (args.Trace)
                    {
                        this.LogInfo(() => string.Format("Touching '{0}' ({1})...", entityType.Name, entityType.Type.Assembly.GetName().Name));
                    }

                    // add the base table...
                    SqlTable coreTable = SqlTable.GetTable(entitySchema, entityType);
                    if (coreTable == null)
                    {
                        throw new InvalidOperationException("coreTable is null.");
                    }
                    entitySchema.Tables.Add(coreTable);

                    // type...
                    Type type = entityType.Type;
                    if (type == null)
                    {
                        throw new InvalidOperationException("type is null.");
                    }

                    // reload it - something weird happens with these and they can't be used with the metadata so reload it so that we're
                    // certain we have the right ones...
                    type = Type.GetType(type.AssemblyQualifiedName, true, true);
                    if (type == null)
                    {
                        throw new InvalidOperationException("type is null.");
                    }

                    // mbr - 02-10-2007 - for c7 - add other tables that we need...
                    Database.ExtensibilityProvider.AddSchemaTables(entityType, type, coreTable, entitySchema);

                    // add the custom units...
                    foreach (Type stepType in stepTypes)
                    {
                        // get the attribute...
                        DatabaseUpdateStepAttribute[] attrs = (DatabaseUpdateStepAttribute[])stepType.GetCustomAttributes(typeof(DatabaseUpdateStepAttribute), true);
                        if (attrs == null)
                        {
                            throw new InvalidOperationException("attrs is null.");
                        }

                        // walk...
                        foreach (DatabaseUpdateStepAttribute attr in attrs)
                        {
                            if (attr.EntityType != null && attr.EntityType.IsAssignableFrom(type))
                            {
                                // create...
                                DatabaseUpdateStep step = (DatabaseUpdateStep)Activator.CreateInstance(stepType, new object[] { type });
                                if (step == null)
                                {
                                    throw new InvalidOperationException("step is null.");
                                }

                                // add..
                                steps.Add(step);
                            }
                        }
                    }
                }
                else
                {
                    if (args.Trace)
                    {
                        this.LogInfo(() => string.Format("Skipping '{0}'.", entityType.Name));
                    }
                }
            }

            // mbr - 02-10-2007 - for c7 - don't do custom steps if we're limiting entity types...
            if (args.LimitEntityTypes.Count == 0)
            {
                // do the ones that don't have entity types...
                foreach (Type stepType in stepTypes)
                {
                    // get the attribute...
                    DatabaseUpdateStepAttribute[] attrs = (DatabaseUpdateStepAttribute[])stepType.GetCustomAttributes(typeof(DatabaseUpdateStepAttribute), true);
                    if (attrs == null)
                    {
                        throw new InvalidOperationException("attrs is null.");
                    }

                    // walk...
                    foreach (DatabaseUpdateStepAttribute attr in attrs)
                    {
                        if (attr.EntityType == null)
                        {
                            // create...
                            DatabaseUpdateStep step = (DatabaseUpdateStep)Activator.CreateInstance(stepType);
                            if (step == null)
                            {
                                throw new InvalidOperationException("step is null.");
                            }

                            // add..
                            steps.Add(step);
                        }
                    }
                }
            }

            // get the work units...
            operation.Status = "Creating schema delta...";

            // mbr - 02-10-2007 - for c7 - changed to deferral.
//			syncStep.WorkUnits.AddRange(entitySchema.GetSchemaWorkUnits(databaseSchema, operation));
            syncStep.Initialize(entitySchema, databaseSchema);

            // run...
            if (!(checkOnly))
            {
                if (args.Trace)
                {
                    this.LogInfo(() => string.Format("Applying '{0}' steps...", steps.Count));
                }

                // context...
                DatabaseUpdateContext context = new DatabaseUpdateContext(operation, args.Trace);

                // mbr - 21-12-2005 - run the steps...
                foreach (DatabaseUpdateStep step in steps)
                {
                    try
                    {
                        if (args.Trace)
                        {
                            this.LogInfo(() => string.Format("Applying step: {0}", step));
                        }

                        // set...
                        operation.Status = string.Format("Running step '{0}'...", step);
                        step.Execute(context);
                    }
                    catch (Exception ex)
                    {
                        // log...
                        string message = string.Format("Failed database update when running step '{0}'.", step);
                        if (this.Log.IsErrorEnabled)
                        {
                            this.Log.Error(message, ex);
                        }

                        // throw...
                        throw new InvalidOperationException(message, ex);
                    }
                }
            }
            else
            {
                if (args.Trace)
                {
                    this.LogInfo(() => "Checking only -- not doing work.");
                }
            }

            if (args.Trace)
            {
                this.LogInfo(() => "Database update finished.");
            }

            this.OnUpdated();

            // return...
            return(new DatabaseUpdateCheckResults(steps));
        }