示例#1
0
 public EntitiesManager()
 {
     _entityTypesCache = new Lazy <List <Type> >(() =>
     {
         try
         {
             return(LibraryEnumeratorFactory.Enumerate <IEnumerable <Type> >(assembly => assembly.
                                                                             GetTypes().
                                                                             Where(x => !x.IsAbstract && typeof(UserEntity).IsAssignableFrom(x)).
                                                                             ToList()).
                    SelectMany(x => x).
                    ToList());
         }
         catch (Exception ex)
         {
             this.RegisterEvent(EventType.Error, "Ошибка загрузки списка типов пользовательских сущностей.", "Первичная загрузка.", null, ex);
             return(new List <Type>());
         }
     });
     AppDomain.CurrentDomain.AssemblyLoad += (a, e) => {
         try
         {
             var typesNew = e.LoadedAssembly.GetTypes().Where(x => !x.IsAbstract && typeof(UserEntity).IsAssignableFrom(x)).ToList();
             if (typesNew.Count > 0)
             {
                 _entityTypesCache.Value.AddRange(typesNew);
             }
         }
         catch (Exception ex)
         {
             this.RegisterEvent(EventType.Error, "Ошибка загрузки списка типов объектов пользователя", $"Из сборки '{e.LoadedAssembly.FullName}'.", null, ex);
         }
     };
 }
示例#2
0
        static FieldTypesCollection()
        {
            lock (SyncRoot)
            {
                UnknownField = new FieldTypes.UnknownFieldType();

                var fieldType = typeof(FieldType);
                LibraryEnumeratorFactory.Enumerate(assembly => assembly.
                                                   GetTypes().
                                                   Where(x => fieldType.IsAssignableFrom(x) && !x.IsAbstract && x.IsClass).
                                                   ForEach(x => RegisterFieldType(x)), null, LibraryEnumeratorFactory.EnumerateAttrs.ExcludeKnownExternal | LibraryEnumeratorFactory.EnumerateAttrs.ExcludeMicrosoft | LibraryEnumeratorFactory.EnumerateAttrs.ExcludeSystem);
            }
        }
示例#3
0
            /// <summary>
            /// См. <see cref="ModuleFactoryBase.OnIsSupported{TCoreComponentRequested}"/>.
            /// </summary>
            protected sealed override bool OnIsSupported <TCoreComponentRequested>()
            {
                var typesList = LibraryEnumeratorFactory.Enumerate <Type>(
                    assembly => Global.CheckIfIgnoredAssembly(assembly) ? null : assembly.GetTypes().Where(x => x.IsClass && !x.IsAbstract && typeof(TCoreComponentRequested).IsAssignableFrom(x) && x.GetConstructor(new Type[] { }) != null).FirstOrDefault(),
                    nameForLogging: $"{this.GetType().FullName}.OnIsSupported<{typeof(TCoreComponentRequested).FullName}>")
                                .Where(x => x != null);

                if (typesList.Count() > 0)
                {
                    _supportedTypes.Add(typesList.First());
                    return(true);
                }
                return(false);
            }
示例#4
0
        private IEnumerable <Type> GetObjectsTypesList()
        {
            var typesList = LibraryEnumeratorFactory.Enumerate(GetObjectTypesFromAssembly, nameForLogging: this.GetType().FullName + "." + nameof(GetObjectsTypesList)).SelectMany(x => x).ToList();

            return(typesList);
        }
示例#5
0
        /// <summary>
        /// </summary>
        public static bool Startup()
        {
            try
            {
                lock (SyncRoot)
                {
                    if (!_isInitialized)
                    {
                        var measure = new MeasureTime();

                        var entryAssembly = Assembly.GetEntryAssembly();
                        Debug.WriteLine("StartupFactory={0}", entryAssembly?.FullName);

                        if (IsDeveloperRuntime())
                        {
                            Debug.WriteLine("StartupEntryAssembly=null. Считаем, что загрузка произошла в VisualStudio и прекращаем привязку. Далее часть отладочной информации.");
                            _isInitialized = true;
                            return(false);
                        }

                        var loadedAssemblies = AppDomain.
                                               CurrentDomain.GetAssemblies().
                                               Where(x => Reflection.LibraryEnumerator.FilterDevelopmentRuntime(x.FullName, null));

                        PrepareAssembly(loadedAssemblies.ToArray());

                        Debug.WriteLine("Startup load assemblies ends with {0}ms", measure.Calculate().TotalMilliseconds);

                        /*
                         * Запускаем фабрики, если TraceCore.Startup.StartupFactory.Startup не вернуло false.
                         * */
                        LibraryEnumeratorFactory.Enumerate((assembly) =>
                        {
                            if (Global.CheckIfIgnoredAssembly(assembly))
                            {
                                return;
                            }

                            var t1 = typeof(SingletonBaseStartup <>);
                            var t2 = typeof(ProvidersFactoryStartup <,>);

                            var types = assembly.GetTypes()
                                        .Where(x => x.IsClass && !x.IsAbstract)
                                        .Where(x => x.IsAssignableToGenericType(t1) || x.IsAssignableToGenericType(t2))
                                        .ToList();

                            foreach (var type in types)
                            {
                                try
                                {
                                    var dd = (new Type[] { type }).ToList().Merge(type.GetBaseTypes())
                                             .Select(x => x.GetMethod("CreateInstanceInternal", BindingFlags.Static | BindingFlags.NonPublic))
                                             .Where(x => x != null)
                                             .FirstOrDefault();

                                    if (dd != null)
                                    {
                                        dd.Invoke(null, null);
                                    }
                                }
                                catch (Exception ex)
                                {
                                    Debug.WriteLine("Factory '{0}' init error: {1}", type.FullName, ex.Message);
                                }
                            }
                        }, null, LibraryEnumeratorFactory.EnumerateAttrs.ExcludeKnownExternal | LibraryEnumeratorFactory.EnumerateAttrs.ExcludeMicrosoft | LibraryEnumeratorFactory.EnumerateAttrs.ExcludeSystem, "StartupFactory.Factories", false);

                        Debug.WriteLine("Startup load factories ends with {0}ms", measure.Calculate().TotalMilliseconds);

                        AppDomain.CurrentDomain.AssemblyLoad += CurrentDomain_AssemblyLoad;

                        _isInitialized = true;
                    }
                }
            }
            catch { }

            return(true);
        }