Beispiel #1
0
 /// <summary>
 ///-
 /// </summary>
 ///<param name="configFile"></param>
 ///<param name="configFileChangedEventHandler"></param>
 public ConfigFileWatcher(string configFile, ConfigFileChangedEventHandler configFileChangedEventHandler)
 {
     AttachWatcher(new FileInfo(configFile));
     _timer = new Timer(new TimerCallback(configFileChangedEventHandler), configFile, Timeout.Infinite, Timeout.Infinite);
 }
Beispiel #2
0
		private CacheSettings()
		{
			// 从缓存配置文件中获取缓存名称
			this.InitFromConfiguration(this.ConfigService.GetConfiguration(ConfigFileType.Cache));

			this.configFileChangedEventHandler = new ConfigFileChangedEventHandler(this.configService_ConfigFileChanged);

			this.ConfigService.ConfigFileChanged += this.configFileChangedEventHandler;
		}
Beispiel #3
0
		/// <summary>
		/// 释放非托管资源。
		/// </summary>
		/// <param name="disposing"><b>true</b> 同时释放托管和非托管资源; <b>false</b> 只释放非托管资源。</param>
		protected virtual void Dispose(bool disposing)
		{
			if (!this.disposed)
			{
				if (disposing)
				{
					if (this.configFileChangedEventHandler != null)
					{
						this.ConfigService.ConfigFileChanged -= this.configFileChangedEventHandler;
						this.configFileChangedEventHandler = null;
					}

					if (this.localDataCacheFactory != null)
					{
						this.localDataCacheFactory.Dispose();
						this.localDataCacheFactory = null;
					}

					if (this.dataCacheFactory != null)
					{
						this.dataCacheFactory.Dispose();
						this.dataCacheFactory = null;
					}

					this.lock4distributeCaches.Dispose();
					this.lock4distributeCaches = null;

					if (this.distributeCaches != null)
					{
						this.distributeCaches.Clear();
						this.distributeCaches = null;
					}
				}
			}
			this.disposed = true;
		}
Beispiel #4
0
 /// <summary>
 ///-
 /// </summary>
 ///<param name="configFile"></param>
 ///<param name="configFileChangedEventHandler"></param>
 public ConfigFileWatcher(string configFile, ConfigFileChangedEventHandler configFileChangedEventHandler)
 {
     AttachWatcher(new FileInfo(configFile));
     _timer = new Timer(new TimerCallback(configFileChangedEventHandler), configFile, Timeout.Infinite, Timeout.Infinite);
 }
Beispiel #5
0
		/// <summary>
		/// 启动服务管理器。
		/// </summary>
		public void Start()
		{
			if (!this.started)
			{
				lock (this.syncObject)
				{
					if (!this.started)
					{
						try
						{
							this.tasks = CreateTasks(this.taskTypes, this.taskTypeInstances);

							// 打开新的宿主
							for (int i = 0; i < this.tasks.Length; i++)
							{
								try
								{
									if (this.tasks[i] is IIntervalTask)
									{
										((IIntervalTask)this.tasks[i]).Start();

										XMS.Core.Container.LogService.Info(String.Format("成功启动名称为 {0} 的任务", this.tasks[i].Name), LogCategory.Task);
									}
									else
									{
										this.tasks[i].Execute(null);
									}

								}
								catch (Exception err)
								{
									XMS.Core.Container.LogService.Warn(String.Format("在启动任务的过程中发生错误,该任务的名称为 {0}", this.tasks[i].Name),
										LogCategory.Task, err);
								}
							}

							if (this.configFileChangedEventHandler == null)
							{
								this.configFileChangedEventHandler = new ConfigFileChangedEventHandler(this.configService_ConfigFileChanged);
							}

							XMS.Core.Container.ConfigService.ConfigFileChanged += this.configFileChangedEventHandler;

							this.started = true;
						}
						catch (Exception err2)
						{
							XMS.Core.Container.LogService.Warn("在启动任务管理器的过程中发生错误", XMS.Core.Logging.LogCategory.Task, err2);
						}
						finally
						{
							this.StartTrace();
						}
					}
				}
			}
		}
Beispiel #6
0
		/// <summary>
		/// 释放非托管资源。
		/// </summary>
		/// <param name="disposing"><b>true</b> 同时释放托管和非托管资源; <b>false</b> 只释放非托管资源。</param>
		protected virtual void Dispose(bool disposing)
		{
			if (!this.disposed)
			{
				if (disposing)
				{
					if (this.configFileChangedEventHandler != null)
					{
						this.ConfigService.ConfigFileChanged -= this.configFileChangedEventHandler;
						this.configFileChangedEventHandler = null;
					}

					this.distributeCacheSetting.Dispose();
				}
			}
			this.disposed = true;
		}
Beispiel #7
0
		private CacheSettings()
		{
			this.LocalCacheName = "local";

			this.DistributeCacheName = RunContext.AppName + "_" + RunContext.AppVersion;

			// 从缓存配置文件中获取缓存名称
			this.InitFromConfiguration(this.ConfigService.GetConfiguration(ConfigFileType.Cache));

			this.configFileChangedEventHandler = new ConfigFileChangedEventHandler(this.configService_ConfigFileChanged);

			this.ConfigService.ConfigFileChanged += this.configFileChangedEventHandler;
		}
		/// <summary>
		/// 启动服务管理器。
		/// </summary>
		public void Start()
		{
			if (!this.started)
			{
				lock (this.syncObject)
				{
					if (!this.started)
					{
						try
						{
							this.hosts = CreateServiceHosts(this.serviceTypes);

							// 打开新的宿主
							for (int i = 0; i < this.hosts.Length; i++)
							{
								try
								{
									this.hosts[i].Open();

									XMS.Core.Container.LogService.Info(String.Format("成功启动类型为 {0} 的服务", this.hosts[i].ServiceType.FullName), LogCategory.ServiceHost);
								}
								catch (Exception err)
								{
									try
									{
										this.hosts[i].Abort();
									}
									catch { }

									XMS.Core.Container.LogService.Warn(String.Format("在启动服务的过程中发生错误,该服务的类型为 {0}", this.hosts[i].ServiceType.FullName),
										LogCategory.ServiceHost, err);
								}
							}

							if (this.configFileChangedEventHandler == null)
							{
								this.configFileChangedEventHandler = new ConfigFileChangedEventHandler(this.configService_ConfigFileChanged);
							}

							XMS.Core.Container.ConfigService.ConfigFileChanged += this.configFileChangedEventHandler;

							this.started = true;
						}
						catch (Exception err2)
						{
							XMS.Core.Container.LogService.Warn("在启动服务管理器的过程中发生错误", LogCategory.ServiceHost, err2);
						}
					}
				}
			}
		}