Example #1
0
        public static AppDomain CreateDomain(ServicePackage package)
        {
            var setup = new AppDomainSetup();

            setup.ApplicationName = "Service" + "_" + Environment.TickCount;
            var serviceFile = new FileInfo(package.FullName);

            var appBase    = serviceFile.DirectoryName;
            var configFile = GetConfigFile(package, serviceFile);

            setup.ApplicationBase   = appBase;
            setup.ConfigurationFile = appBase != null && configFile != null
                ? Path.Combine(appBase, configFile)
                : configFile;

            var binPath = appBase;

            setup.PrivateBinPath = binPath;
            var domainName = "service-domain-" + package.Name;

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

            if (evidence.GetAssemblyEnumerator().Current == null)
            {
                var zone = new Zone(SecurityZone.MyComputer);
                evidence.AddHostEvidence(zone);
                var assembly = Assembly.GetExecutingAssembly();
                var url      = new Url(assembly.CodeBase);
                evidence.AddHostEvidence(url);
                var hash = new Hash(assembly);
                evidence.AddHostEvidence(hash);
            }

            return(AppDomain.CreateDomain(domainName, evidence, setup));
        }
Example #2
0
        public void Load(ServicePackage package)
        {
            Unload();
            _servicePackage = package;
            var domain = _domain = DomainManager.CreateDomain(package);
            var agent  = DomainAgent.CreateInstance(domain);

            _inner = agent.CreateRunner();
            _inner.Load(package);
            _unloaded = false;
        }
        public void Load(ServicePackage package)
        {
            services = null;
            var address = WcfServerSection.Current.Service.Address;

            if (string.IsNullOrEmpty(address))
            {
                package.BaseAddress = address;
            }
            _serviceAssembly = Assembly.LoadFile(package.AssemblyFile);

            var q = from c in _serviceAssembly.GetTypes()
                    let a = c.GetInterfaces().Where(RuntimeUnity.ValidateServiceInterface).ToArray()
                            where a.Length > 0
                            select new Service(package.Id, c, a, package.BaseAddress);

            services = q.ToArray();
        }
Example #4
0
        private static string GetConfigFile(ServicePackage package, FileInfo serviceFile)
        {
            string configFile;

            if (serviceFile.DirectoryName != null)
            {
                configFile = Path.Combine(serviceFile.DirectoryName, "app.config");
                if (File.Exists(configFile))
                {
                    return(configFile);
                }
                configFile = Path.Combine(serviceFile.DirectoryName,
                                          AppDomain.CurrentDomain.FriendlyName) + ".config";
                if (File.Exists(configFile))
                {
                    return(configFile);
                }
            }
            throw new ArgumentNullException("没有找到对应服务的配置文件:" + package.FullName);
        }
Example #5
0
 public ServiceRunner(ServicePackage package)
 {
     _servicePackage = package;
 }