Пример #1
0
        /// <summary>启动</summary>
        public static void Start()
        {
            try
            {
                ServicesConfiguration configuration = ServicesConfigurationView.Instance.Configuration;

                foreach (NameTypeConfigurationElement service in configuration.Services)
                {
                    EventLogHelper.Information("正在创建服务【" + service.Name + "】。");

                    if (service.Type == null)
                    {
                        EventLogHelper.Error(string.Format("服务【{0}】初始化类型【{1}】失败,请确认配置是否正确。", service.Name, service.TypeName));
                    }
                    else
                    {
                        OpenHost(service.Type);
                    }
                }
            }
            catch (Exception ex)
            {
                EventLogHelper.Error(ex.ToString());

                throw ex;
            }
        }
        /// <summary>启动</summary>
        public static void Start()
        {
            try
            {
                ServicesConfiguration configuration = ServicesConfigurationView.Instance.Configuration;

                foreach (ServiceObserverConfigurationElement observer in configuration.Observers)
                {
                    IServiceObserver serviceObserver = (IServiceObserver)Assembly.Load(observer.TypeName.Substring(observer.TypeName.IndexOf(",") + 1).Trim()).CreateInstance(observer.TypeName.Substring(0, observer.TypeName.IndexOf(",")).Trim(), false, BindingFlags.Default, null, new object[] { observer.Name, observer.Args }, null, null);

                    EventLogHelper.Information("正在创建监听器【" + observer.Name + "】。");

                    if (serviceObserver == null)
                    {
                        EventLogHelper.Error(string.Format("监听器【{0}】初始化类型【{1}】失败,请确认配置是否正确。", observer.Name, observer.TypeName));
                    }
                    else
                    {
                        serviceObserver.Start();

                        serviceObservers.Add(serviceObserver);
                    }
                }
            }
            catch (Exception ex)
            {
                EventLogHelper.Error(ex.ToString());

                throw ex;
            }

            // -------------------------------------------------------
            // 设置定时器
            // -------------------------------------------------------

            timer.Enabled = true;

            timer.Interval = ServicesConfigurationView.Instance.TimerInterval * 1000;

            timer.Elapsed += delegate(object sender, ElapsedEventArgs e)
            {
                ServiceObserverManagement.Run();
            };

            timer.Start();
        }