コード例 #1
0
        void Dispose(bool disposing)
        {
            if (disposing)
            {
                if (Sponsors.Count > 0)
                {
                    foreach (LifetimeSponsor sponsor in Sponsors)
                    {
                        sponsor.Dispose();
                    }
                }

                if (_interrogationProxy != null)
                {
                    try
                    {
                        _interrogationProxy.Dispose();
                        System.Runtime.Remoting.RemotingServices.Disconnect(_interrogationProxy);
                    }
                    catch { }
                    _interrogationProxy = null;
                }

                if (_appDomain != null)
                {
                    AppDomain.Unload(_appDomain);
                }
            }
        }
コード例 #2
0
        public IEnumerable <IModelTermProvider> Interrogate()
        {
            if (!File.Exists(PackagePath))
            {
                throw new FileNotFoundException("The file: " + Path.GetFileName(PackagePath) + " was not found in " + Path.GetDirectoryName(PackagePath) + ".");
            }

            string         domainName = Path.GetFileNameWithoutExtension(PackagePath);
            AppDomainSetup setupInfo  = new AppDomainSetup();

            setupInfo.ApplicationName = domainName;
            setupInfo.ApplicationBase = AppDomainBase;
            _appDomain = AppDomain.CreateDomain(domainName, AppDomain.CurrentDomain.Evidence, setupInfo);

            Type proxyType = typeof(PackageInterrogationProxy);

            _interrogationProxy = (PackageInterrogationProxy)_appDomain.CreateInstanceFrom(proxyType.Assembly.Location, proxyType.FullName).Unwrap();

            return(_interrogationProxy.Interrogate(PackagePath).Select(
                       termProvider => {
                System.Runtime.Remoting.Lifetime.ILease leaseObj = System.Runtime.Remoting.RemotingServices.GetLifetimeService((ProxyModelTermProvider)termProvider) as System.Runtime.Remoting.Lifetime.ILease;
                if (leaseObj != null)
                {
                    Sponsors.Add(new LifetimeSponsor(leaseObj));
                }

                return termProvider;
            }
                       ));
        }