コード例 #1
0
        internal void Init(ServiceExecutionHost host, ServiceEnvironmentConfiguration envConfig, ServiceConfiguration config, SchedulingInfo schedulingInfo, Guid instanceID, Guid parentInstanceID)
        {
            Host             = host;
            this.Environment = new ServiceEnvironment(envConfig);

            this.InstanceID     = instanceID;
            this.Configuration  = config;
            this.SchedulingInfo = schedulingInfo;

            if (parentInstanceID != Guid.Empty)
            {
                this.ParentInstance = Environment.GetServiceInstance(parentInstanceID);
            }

            Current = this;

            // Monitor app domain-level events
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(this.DomainUnhandledException);
            AppDomain.CurrentDomain.DomainUnload       += new EventHandler(this.DomainUnload);

            StateInfo.TimeInitialized = DateTime.Now;
            StateInfo.State           = ServiceState.Ready;
            NotifyState();
        }
コード例 #2
0
 protected ServiceInstance NewChildService(ServiceConfiguration child)
 {
     return(Environment.NewServiceInstance(child, ServiceInstance.FromService(this)));
 }
 protected virtual void CopyConfigurationData(ServiceConfiguration sourceConfig, ServiceConfiguration targetConfig)
 {
 }
        internal ServiceConfiguration Derive(ServiceConfigurationLevel newLevel, object parent)
        {
            if (this.ConfigurationLevel == ServiceConfigurationLevel.Instance)
            {
                throw new ServiceConfigurationException("Cannot derive from an instance configuration.");
            }

            ServiceConfiguration config;

            try { config = (ServiceConfiguration)Activator.CreateInstance(this.GetType()); }
            catch (MissingMethodException) { throw new MissingMethodException("Sub-types of ServiceConfiguration require a parameterless constructor."); }

            // Inherit from parent
            config.BaseConfiguration = this;
            config._isEnabled        = true;
            config._isPublic         = this._isPublic;
            config._assemblyPath     = this._assemblyPath;
            config._serviceType      = this._serviceType;
            config._serviceName      = this._serviceName;
            config._hostName         = this._hostName;
            this.Limits.CopyTo(config.Limits);

            CopyConfigurationData(this, config);

            // Merge parameters
            foreach (var param in this.Parameters)
            {
                config.Parameters[param.Key] = param.Value;
            }

            // Associate with profile
            ServiceProfile profile = parent as ServiceProfile;

            if (this.Profile != null)
            {
                if (profile == null)
                {
                    profile = this.Profile;
                }
                else if (profile != this.Profile)
                {
                    // This should never happen because it is checked by ServiceProfile.DeriveConfiguration()
                    throw new ServiceConfigurationException("Profile mismatch - internal Derive should not be called this way");
                }
            }

            if (profile != null)
            {
                config.Profile            = profile;
                config.ConfigurationLevel = ServiceConfigurationLevel.Profile;

                // Deriving from a new profile, so merge parameters (if this.Profile is not null, parameters were already merged in a previous Derive())
                if (this.Profile == null)
                {
                    foreach (var param in profile.Parameters)
                    {
                        config.Parameters[param.Key] = param.Value;
                    }
                }
            }
            else
            {
                config.ConfigurationLevel = newLevel;
            }

            // Get scheduling rules only if this one is empty
            foreach (SchedulingRule rule in this.SchedulingRules)
            {
                config.SchedulingRules.Add(rule.Clone());
            }

            // Parameter inheritance from parent service configuration
            ServiceConfiguration parentInstanceConfig = parent as ServiceConfiguration;

            if (parentInstanceConfig != null)
            {
                // Ignore parameters that are already in the config
                foreach (var param in parentInstanceConfig.Parameters)
                {
                    if (!config.Parameters.ContainsKey(param.Key))
                    {
                        config.Parameters[param.Key] = param.Value;
                    }
                }
            }

            return(config);
        }
コード例 #5
0
 internal ServiceInstance NewServiceInstance(ServiceConfiguration configuration, ServiceInstance parent)
 {
     return(new ServiceInstance(configuration, this, parent));
 }
コード例 #6
0
 public ServiceInstance NewServiceInstance(ServiceConfiguration configuration)
 {
     return(NewServiceInstance(configuration, null));
 }