コード例 #1
0
        /// <summary>
        /// Invoked once to force load all assemblies into an analysis unit
        /// </summary>
        private void LoadAllAssembliesAndSetAssemblyResolver()
        {
            this._loadedAssemblies = new Dictionary <Assembly, bool>();

            foreach (string assemblyName in this._assembliesToLoad)
            {
                Assembly assembly = AssemblyUtilities.LoadAssembly(assemblyName, this._logger);
                if (assembly != null)
                {
                    // The bool value indicates whether this assembly should be searched for a DomainService
                    this._loadedAssemblies[assembly] = TypeUtility.CanContainDomainServiceImplementations(assembly);
                }
            }

            AssemblyUtilities.SetAssemblyResolver(this._loadedAssemblies.Keys);
        }
コード例 #2
0
        private static void EnsureDomainServiceTypes()
        {
            if (DomainServiceVirtualPathProvider.domainServiceTypes != null)
            {
                return;
            }

            Dictionary <string, Type> types = new Dictionary <string, Type>(StringComparer.OrdinalIgnoreCase);

            Type domainServiceBaseType        = typeof(DomainService);
            IEnumerable <Assembly> assemblies = BuildManager.GetReferencedAssemblies().Cast <Assembly>();

            foreach (Assembly assembly in assemblies)
            {
                if (!TypeUtility.CanContainDomainServiceImplementations(assembly))
                {
                    continue;
                }

                Type[] exportedTypes = null;
                try
                {
                    exportedTypes = assembly.GetExportedTypes();
                }
                catch (ReflectionTypeLoadException ex)
                {
                    exportedTypes = ex.Types;
                }
                catch (Exception ex)
                {
                    if (ex.IsFatal())
                    {
                        throw;
                    }
                    // If we're unable to load the assembly, ignore it for now.
                }

                if (exportedTypes != null)
                {
                    foreach (Type exportedType in exportedTypes)
                    {
                        if (exportedType.IsAbstract || exportedType.IsInterface || exportedType.IsValueType || !domainServiceBaseType.IsAssignableFrom(exportedType))
                        {
                            continue;
                        }

                        if (TypeDescriptor.GetAttributes(exportedType)[typeof(EnableClientAccessAttribute)] == null)
                        {
                            continue;
                        }

                        string name = GetCanonicalFileName(exportedType);
                        if (types.ContainsKey(name))
                        {
                            throw new InvalidOperationException(String.Format(CultureInfo.CurrentCulture, Resource.DomainServiceVirtualPathProvider_DuplicateDomainServiceName, exportedType.AssemblyQualifiedName, types[name].AssemblyQualifiedName));
                        }
                        types.Add(name, exportedType);
                    }
                }
            }

            DomainServiceVirtualPathProvider.domainServiceTypes = types;
        }