コード例 #1
0
        private void LoadApplicationAssemblies()
        {
            var exeRoot     = Path.GetDirectoryName(typeof(SiloAssemblyLoader).GetTypeInfo().Assembly.Location);
            var appRoot     = Path.Combine(exeRoot, "Applications");
            var cwd         = Directory.GetCurrentDirectory();
            var directories = new Dictionary <string, SearchOption>
            {
                { exeRoot, SearchOption.TopDirectoryOnly },
                { appRoot, SearchOption.AllDirectories }
            };

            if (!directories.ContainsKey(cwd))
            {
                directories.Add(cwd, SearchOption.TopDirectoryOnly);
            }

            AssemblyLoaderPathNameCriterion[] excludeCriteria =
            {
                AssemblyLoaderCriteria.ExcludeResourceAssemblies,
                AssemblyLoaderCriteria.ExcludeSystemBinaries()
            };
            AssemblyLoaderReflectionCriterion[] loadCriteria =
            {
                AssemblyLoaderReflectionCriterion.NewCriterion(
                    TypeUtils.IsConcreteGrainClass,
                    "Assembly does not contain any acceptable grain types."),
                AssemblyLoaderCriteria.LoadTypesAssignableFrom(
                    typeof(IProvider))
            };

            discoveredAssemblyLocations = AssemblyLoader.LoadAssemblies(directories, excludeCriteria, loadCriteria, logger);
        }
コード例 #2
0
        private void LoadApplicationAssemblies()
        {
            var exeRoot     = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
            var appRoot     = Path.Combine(exeRoot, "Applications");
            var directories = new Dictionary <string, SearchOption>
            {
                { exeRoot, SearchOption.TopDirectoryOnly },
                { appRoot, SearchOption.AllDirectories }
            };

            AssemblyLoaderPathNameCriterion[] excludeCriteria =
            {
                AssemblyLoaderCriteria.ExcludeResourceAssemblies,
                AssemblyLoaderCriteria.ExcludeSystemBinaries()
            };
            AssemblyLoaderReflectionCriterion[] loadCriteria =
            {
                AssemblyLoaderReflectionCriterion.NewCriterion(
                    TypeUtils.IsConcreteGrainClass,
                    "Assembly does not contain any acceptable grain types."),
                AssemblyLoaderCriteria.LoadTypesAssignableFrom(
                    typeof(IProvider))
            };

            AssemblyLoader.LoadAssemblies(directories, excludeCriteria, loadCriteria, logger);
        }
コード例 #3
0
        public static T LoadAndCreateInstance <T>(string assemblyName, TraceLogger logger) where T : class
        {
            try
            {
                var exeRoot = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                var dirs    = new Dictionary <string, SearchOption>
                {
                    { exeRoot, SearchOption.TopDirectoryOnly }
                };

                AssemblyLoaderPathNameCriterion[] includeCriteria =
                {
                    AssemblyLoaderCriteria.IncludeFileNames(new[] { assemblyName })
                };
                AssemblyLoaderReflectionCriterion[] loadCriteria =
                {
                    AssemblyLoaderCriteria.LoadTypesAssignableFrom(typeof(T))
                };

                var discoveredAssemblyLocations = LoadAssemblies(dirs, includeCriteria, loadCriteria, logger);

                if (discoveredAssemblyLocations.Count == 0)
                {
                    var error = String.Format("Failed to LoadAndCreateInstance for type {0} from assembly {1}. " +
                                              "Make sure this assembly is in your current executing directory and the type is defined there.",
                                              typeof(T).FullName, assemblyName);
                    throw new OrleansException(error);
                }

                if (discoveredAssemblyLocations.Count > 1)
                {
                    var error = String.Format("Type {0} was found more than once in assembly {1}.", typeof(T).FullName, assemblyName);
                    throw new OrleansException(error);
                }

                var foundType = TypeUtils.GetTypes(discoveredAssemblyLocations, type => typeof(T).IsAssignableFrom(type)).First();

                return((T)Activator.CreateInstance(foundType, true));
            }
            catch (Exception exc)
            {
                logger.Error(ErrorCode.Loader_LoadAndCreateInstance_Failure, exc.Message, exc);
                throw;
            }
        }
コード例 #4
0
        private void LoadApplicationAssemblies()
        {
            AssemblyLoaderPathNameCriterion[] excludeCriteria =
            {
                AssemblyLoaderCriteria.ExcludeResourceAssemblies,
                AssemblyLoaderCriteria.ExcludeSystemBinaries()
            };
            AssemblyLoaderReflectionCriterion[] loadCriteria =
            {
                AssemblyLoaderReflectionCriterion.NewCriterion(
                    TypeUtils.IsConcreteGrainClass,
                    "Assembly does not contain any acceptable grain types."),
                AssemblyLoaderCriteria.LoadTypesAssignableFrom(
                    typeof(IProvider))
            };

            discoveredAssemblyLocations = AssemblyLoader.LoadAssemblies(directories, excludeCriteria, loadCriteria, logger);
        }