Ejemplo n.º 1
0
        /// <summary>
        /// Finds all classes in the loaded domain, that can be assigned to the specified 'Type'
        /// </summary>
        public static List <Type> FindClassesImplementing(AssemblyCatalogue catalogue, Type type)
        {
            var result        = new List <Type>();
            var iassemblyName = type.GetTypeInfo().Assembly.GetName().Name;

            foreach (var a in catalogue) //check all types in the assemblies that reference the 'type's assembly and that can be assigned to 'type'
            {
                if (a.GetName().Name != iassemblyName && !(a.GetReferencedAssemblies().Any(x => x.Name == iassemblyName)))
                {
                    continue;
                }

                try
                {
                    var types = a.GetTypes().Where(t => IsAssignableStandard(t, type));
                    result.AddRange(types);
                }
                catch (ReflectionTypeLoadException tle)
                {
                    throw new Exception(string.Join(", ", tle.LoaderExceptions.Select(x => x.Message)) + " This is normally due to an installation issue or missing extension.");
                }
                catch (Exception e)
                {
                    throw new Exception("Problem loading types: " + e);
                }
            }
            return(result);
        }
Ejemplo n.º 2
0
        private static IEnumerable <Type> GetTypes(AssemblyCatalogue assemblyCatalogue)
        {
            var result = new List <Type>();
            var t      = typeof(IncludeInTypeCatalogueAttribute);

            foreach (var a in assemblyCatalogue)
            {
                if (FilterTypeCatalogueAttribute && a.CustomAttributes.All(x => x.AttributeType != t))
                {
                    continue;
                }
                try
                {
                    result.AddRange(a.GetTypes());
                }
                catch (ReflectionTypeLoadException tle)
                {
                    var msgs = tle.LoaderExceptions.Select(x => x.Message).ToList();
                    msgs.Add("In " + a.GetName());
                    throw new Exception(string.Join(", ", msgs) + " This is normally due to an installation issue or missing extension.");
                }
                catch (Exception e)
                {
                    throw new Exception("Problem loading types: " + e);
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
 public ExtensionManager(ServerContext context)
 {
     Context    = context;
     Config     = Context.Config.PackageConfig;
     Instances  = new ExtensionList(this);
     Assemblies = context.Assemblies;
     Types      = context.Types;
 }
Ejemplo n.º 4
0
 public ExtensionManager(ServerContext context)
 {
     _context   = context;
     _config    = context.Config.PackageConfig;
     Assemblies = new AssemblyCatalogue(this);
     Types      = new TypeCatalogue(this);
     Update();
 }
Ejemplo n.º 5
0
        public ServerContext(string configPath, IMessenger m)
        {
            configPath = configPath.ResolveSpecial();

            PlatformCurrent = OsInformation.GetPlatform();

            _testing = this; //todo: hack for now.

            if (string.IsNullOrWhiteSpace(configPath))
            {
                throw new ArgumentException($"\'{nameof(configPath)}\' cannot be empty.");
            }

            Assemblies = new AssemblyCatalogue();
            Types      = new TypeCatalogue(Assemblies);

            ConfigDirectoryInfo = new FileInfo(Path.GetFullPath(configPath)).Directory;
            Config = PrimeServerConfig.Get(Path.GetFullPath(configPath));
            M      = m;
            Users  = new Users(this);
            Public = new PublicContext(this);
        }
Ejemplo n.º 6
0
 public TypeCatalogue(AssemblyCatalogue assemblyCatalogue) : base(GetTypes(assemblyCatalogue), t => t.GetStrongHash())
 {
     _assemblies = assemblyCatalogue;
 }