Esempio n. 1
0
        /// <summary>
        /// Initializes a new instance of <see cref="AssemblyProvider"/>
        /// </summary>
        public AssemblyProvider(_AppDomain appDomain, IAssemblyFilters assemblyFilters)
        {
            _appDomain              = appDomain;
            _assemblyFilters        = assemblyFilters;
            appDomain.AssemblyLoad += AssemblyLoaded;

            Populate();
        }
Esempio n. 2
0
        public void LoadFromAppDomain(_AppDomain appDomain)
        {
            if (appDomain == null)
            {
                throw new ArgumentNullException("appDomain");
            }

            _types.AddRange(appDomain
                            .GetAssemblies()
                            .SelectMany(item => item.GetTypes()));
        }
Esempio n. 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FluentTypeBuilder"/> class.
        /// </summary>
        /// <param name="appDomain">
        /// The app domain.
        /// </param>
        public FluentTypeBuilder(_AppDomain appDomain)
        {
            AppDomain = appDomain;

            Interfaces   = new List <Type>();
            BaseType     = typeof(object);
            TypeName     = "FluentTypeBuilder";
            AssemblyName = new AssemblyName {
                Name = "FluentTypeBuilder"
            };
            MakeBuilders();
        }
Esempio n. 4
0
        // https://stackoverflow.com/questions/33890264/enumerate-all-appdomains-without-mscoree/33894441#33894441

        public static IEnumerable <__AppDomain> EnumAppDomains()
        {
            // Obtain ICLRMetaHost interface
            object objHost;
            int    hr = CLRCreateInstance(ref CLSID_CLRMetaHost, ref IID_CLRMetaHost, out objHost);

            if (hr < 0)
            {
                throw new COMException("Cannot create meta host", hr);
            }
            var host = (ICLRMetaHost)objHost;

            // Obtain ICLRRuntimeInfo interface
            var  vers       = Environment.Version;
            var  versString = string.Format("v{0}.{1}.{2}", vers.Major, vers.Minor, vers.Build);
            var  objRuntime = host.GetRuntime(versString, ref IID_CLRRuntimeInfo);
            var  runtime    = (ICLRRuntimeInfo)objRuntime;
            bool started;
            uint flags;

            runtime.IsStarted(out started, out flags);
            if (!started)
            {
                throw new COMException("CLR not started??");
            }

            // Obtain legacy ICorRuntimeHost interface and iterate appdomains
            var    V2Host = (ICorRuntimeHost)runtime.GetInterface(ref CLSID_CorRuntimeHost, ref IID_CorRuntimeHost);
            IntPtr hDomainEnum;

            V2Host.EnumDomains(out hDomainEnum);
            for (; ;)
            {
                _AppDomain domain = null;
                V2Host.NextDomain(hDomainEnum, out domain);
                if (domain == null)
                {
                    break;
                }
                yield return(domain);
            }
            V2Host.CloseEnum(hDomainEnum);
        }
        private static void ObtainProcessDispatcher()
        {
            byte[] data = SNINativeMethodWrapper.GetData();
            if (data == null)
            {
                Bid.NotificationsTrace("<sc.SqlDependency.ObtainProcessDispatcher|DEP> nativeStorage null, obtaining dispatcher AppDomain and creating ProcessDispatcher.\n");
                _AppDomain defaultAppDomain = SNINativeMethodWrapper.GetDefaultAppDomain();
                if (defaultAppDomain != null)
                {
                    ObjectHandle handle = CreateProcessDispatcher(defaultAppDomain);
                    if (handle != null)
                    {
                        SqlDependencyProcessDispatcher dispatcher = (SqlDependencyProcessDispatcher)handle.Unwrap();
                        if (dispatcher != null)
                        {
                            _processDispatcher = dispatcher.SingletonProcessDispatcher;
                            ObjRef          objRef     = GetObjRef(_processDispatcher);
                            BinaryFormatter formatter2 = new BinaryFormatter();
                            MemoryStream    stream     = new MemoryStream();
                            GetSerializedObject(objRef, formatter2, stream);
                            SNINativeMethodWrapper.SetData(stream.GetBuffer());
                            return;
                        }
                        Bid.NotificationsTrace("<sc.SqlDependency.ObtainProcessDispatcher|DEP|ERR> ERROR - ObjectHandle.Unwrap returned null!\n");
                        throw ADP.InternalError(ADP.InternalErrorCode.SqlDependencyObtainProcessDispatcherFailureObjectHandle);
                    }
                    Bid.NotificationsTrace("<sc.SqlDependency.ObtainProcessDispatcher|DEP|ERR> ERROR - AppDomain.CreateInstance returned null!\n");
                    throw ADP.InternalError(ADP.InternalErrorCode.SqlDependencyProcessDispatcherFailureCreateInstance);
                }
                Bid.NotificationsTrace("<sc.SqlDependency.ObtainProcessDispatcher|DEP|ERR> ERROR - unable to obtain default AppDomain!\n");
                throw ADP.InternalError(ADP.InternalErrorCode.SqlDependencyProcessDispatcherFailureAppDomain);
            }
            Bid.NotificationsTrace("<sc.SqlDependency.ObtainProcessDispatcher|DEP> nativeStorage not null, obtaining existing dispatcher AppDomain and ProcessDispatcher.\n");
            BinaryFormatter formatter = new BinaryFormatter();
            MemoryStream    stream2   = new MemoryStream(data);

            _processDispatcher = GetDeserializedObject(formatter, stream2);
            Bid.NotificationsTrace("<sc.SqlDependency.ObtainProcessDispatcher|DEP> processDispatcher obtained, ID: %d\n", _processDispatcher.ObjectID);
        }
Esempio n. 6
0
        public static object CreateApplicationHost(Type hostType, string virtualDir, string physicalDir)
        {
            if (physicalDir == null)
            {
                throw new NullReferenceException();
            }

            #region Prepare bin

            // Make sure physicalDir has file system semantics
            // and not uri semantics ( '\' and not '/' ).
            physicalDir = Path.GetFullPath(physicalDir);

            if (hostType == null)
            {
                throw new ArgumentException("hostType can't be null");
            }

            if (virtualDir == null)
            {
                throw new ArgumentNullException("virtualDir");
            }

            Evidence evidence = new Evidence(AppDomain.CurrentDomain.Evidence);

            //
            // Setup
            //
            AppDomainSetup setup = new AppDomainSetup();

            setup.ApplicationBase = physicalDir;

            string webConfig = FindWebConfig(physicalDir);

            if (webConfig == null)
            {
                webConfig = Path.Combine(physicalDir, DEFAULT_WEB_CONFIG_NAME);
            }
            setup.ConfigurationFile    = webConfig;
            setup.DisallowCodeDownload = true;

            string[] bindirPath = new string[1] {
                Path.Combine(physicalDir, "bin")
            };

            //string bindir;
            //foreach (string dir in HttpApplication.BinDirs)
            //{
            //    bindir = Path.Combine(physicalDir, dir);

            //    if (Directory.Exists(bindir))
            //    {
            //        bindirPath[0] = bindir;
            //        break;
            //    }
            //}

            setup.PrivateBinPath      = BuildPrivateBinPath(physicalDir, bindirPath);
            setup.PrivateBinPathProbe = "*";
            string dynamic_dir = null;
            string user        = Environment.UserName;
            int    tempDirTag  = 0;
            string dirPrefix   = String.Concat(user, "-temp-aspnet-");

            for (int i = 0; ; i++)
            {
                string d = Path.Combine(Path.GetTempPath(), String.Concat(dirPrefix, i.ToString("x")));

                try
                {
                    CreateDirectory(d);
                    string stamp = Path.Combine(d, "stamp");
                    CreateDirectory(stamp);
                    dynamic_dir = d;
                    try
                    {
                        Directory.Delete(stamp);
                    }
                    catch (Exception)
                    {
                        // ignore
                    }

                    tempDirTag = i.GetHashCode();
                    break;
                }
                catch (UnauthorizedAccessException)
                {
                    continue;
                }
            }
            //
            // Unique Domain ID
            //
            string domain_id = (virtualDir.GetHashCode() + 1 ^ physicalDir.GetHashCode() + 2 ^ tempDirTag).ToString("x");

            // This is used by mod_mono's fail-over support
            string domain_id_suffix = Environment.GetEnvironmentVariable("__MONO_DOMAIN_ID_SUFFIX");
            if (domain_id_suffix != null && domain_id_suffix.Length > 0)
            {
                domain_id += domain_id_suffix;
            }

            setup.ApplicationName = domain_id;
            setup.DynamicBase     = dynamic_dir;
            setup.CachePath       = dynamic_dir;

            string dynamic_base = setup.DynamicBase;
            if (CreateDirectory(dynamic_base) && (Environment.GetEnvironmentVariable("MONO_ASPNET_NODELETE") == null))
            {
                ClearDynamicBaseDirectory(dynamic_base);
            }

            #endregion

            //
            // Create app domain
            //
            // _AppDomain appdomain;
            var        domain    = AppDomain.CurrentDomain;
            bool       isDebug   = Debugger.IsAttached;
            _AppDomain appdomain = DebugDomain.CreateDomain(domain_id, evidence, setup);
            // string domain_id, object evidence, object setup);
            if (isDebug)
            {
                domain.SetData("DebugDomain", appdomain);
            }
            else
            {
                appdomain = AppDomain.CreateDomain(domain_id, evidence, setup);
                domain.SetData("DebugDomain", appdomain);
            }

            // Populate with the AppDomain data keys expected, Mono only uses a
            // few, but third party apps might use others:
            appdomain.SetData(".appDomain", "*");
            int l = physicalDir.Length;
            if (physicalDir[l - 1] != Path.DirectorySeparatorChar)
            {
                physicalDir += Path.DirectorySeparatorChar;
            }

            appdomain.SetData(".appPath", physicalDir);
            appdomain.SetData(".appVPath", virtualDir);
            appdomain.SetData(".appId", domain_id);
            appdomain.SetData(".domainId", domain_id);
            appdomain.SetData(".hostingVirtualPath", virtualDir);
            appdomain.SetData(".hostingInstallDir", Path.GetDirectoryName(typeof(Object).Assembly.CodeBase));
            appdomain.SetData("DataDirectory", Path.Combine(physicalDir, "App_Data"));
            appdomain.SetData(MonoHostedDataKey, "yes");

            try
            {
                appdomain.DoCallBack(SetHostingEnvironment);
            } catch (Exception err) { appdomain.SetData("load.Error", err); }

            if ((appdomain as AppDomain) != null)
            {
                return((appdomain as AppDomain).CreateInstanceAndUnwrap(hostType.Module.Assembly.FullName, hostType.FullName));
            }

            return // (appdomain as DebugDomain)
                   (AppDomain.CurrentDomain
                    .CreateInstanceAndUnwrap(hostType.Module.Assembly.FullName, hostType.FullName));
        }
 private static ObjectHandle CreateProcessDispatcher(_AppDomain masterDomain)
 {
     return masterDomain.CreateInstance(_assemblyName, _typeName);
 }
 private static ObjectHandle CreateProcessDispatcher(_AppDomain masterDomain)
 {
     return(masterDomain.CreateInstance(_assemblyName, _typeName));
 }