Esempio n. 1
0
 /// <summary>
 /// 构造函数。
 /// </summary>
 public TestShellMain()
 {
     try
     {
         //服务名称。
         this.ServiceName = ServiceConfig.ModuleConfig.ServiceName;
         //服务日志初始化。
         this.servlog = new WinServiceLog(ServiceConfig.ModuleConfig);
         this.servlog.LogRecordEvent += this.LogRecord;
         //初始化服务任务集合。
         this.allJobsCache = Hashtable.Synchronized(new Hashtable());
     }
     catch (Exception ex)
     {
         //错误日志记录。
         this.servlog.ErrorLog(ex);
     }
     finally
     {
         //定时器初始化。
         this.mTimer = new System.Timers.Timer();
         this.mTimer.AutoReset = true;
         this.mTimer.Enabled = false;
         this.mTimer.Interval = ModuleConst.CONST_DOU_TIMEINTERVAL;
         this.mTimer.Elapsed += this.OnTimerElapsed;
     }
 }
Esempio n. 2
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="conf"></param>
 /// <param name="log"></param>
 /// <param name="source"></param>
 public SyncDataStu(SyncJobConfigurations conf, WinServiceLog log, IDataSync source)
     : base(conf, log, source)
 {
     this.unitsEntity = new UnitsEntity(this.Config.ModuleDefaultDatabase, this.Log);
     this.classesEntity = new ClassesEntity(this.Config.ModuleDefaultDatabase, this.Log);
     this.stusEntity = new StudentsEntity(this.Config.ModuleDefaultDatabase, this.Log);
     this.classStusEntity = new ClassStudentEntity(this.Config.ModuleDefaultDatabase, this.Log);
     this.roleEmpsEntity = new DbModuleEntity<SecurityRoleEmployee>(this.Config.ModuleDefaultDatabase, this.Log);
     this.roleId = this.Config.StudentUserRoleID;
 }
Esempio n. 3
0
 /// <summary>
 /// 构造函数。
 /// </summary>
 public ServiceMain(WinServiceLog servlog)
     : base()
 {
     try
     {
         this.ServiceLog = servlog;
         this.Runing = false;
         //服务名称。
         this.ServiceName = ServiceConfig.ModuleConfig.ServiceName;
         //初始化主定时器.
         this.timer = new System.Timers.Timer(ModuleConst.CONST_DOU_TIMEINTERVAL);
         this.timer.Elapsed += this.ServiceTimerMain;
         this.timer.Enabled = false;
     }
     catch (Exception e)
     {
         servlog.ErrorLog(e);
     }
 }
Esempio n. 4
0
        /// <summary>
        /// 同步数据。
        /// </summary>
        /// <param name="log">服务日志对象。</param>
        public void Sync(WinServiceLog log)
        {
            try
            {
                if (this.DataPoxy == null)
                {
                    return;
                }

                this.logBuilder = new StringBuilder(this.SyncName);
                this.insertBuilder = new StringBuilder("新增" + this.SyncName + "数据:");
                this.updateBuilder = new StringBuilder("更新" + this.SyncName + "数据:");
                this.hiddenBuilder = new StringBuilder("隐藏" + this.SyncName + "数据:");
                this.insertCount = this.updateCount = this.hiddenCount = 0;

                this.DataSync(this.logBuilder, this.insertBuilder, this.updateBuilder, this.hiddenBuilder,
                    this.insertCount, this.updateCount, this.hiddenCount);
            }
            catch (Exception e)
            {
                this.AppendLog(this.logBuilder, string.Format("发生异常:{0}\r\n{1}\r\n{2}", e.Message, e.Source, e.StackTrace));
                throw e;
            }
            finally
            {
                this.AppendLog(this.logBuilder, null);
                StringBuilder sb = new StringBuilder();
                if (insertCount > 0)
                {
                    this.AppendLog(this.logBuilder, this.insertBuilder.ToString());
                    sb.AppendFormat("共新增:{0};", insertCount);
                }
                if (updateCount > 0)
                {
                    this.AppendLog(this.logBuilder, this.updateBuilder.ToString());
                    sb.AppendFormat("共更新:{0};", updateCount);
                }
                if (hiddenCount > 0)
                {
                    this.AppendLog(this.logBuilder, this.hiddenBuilder.ToString());
                    sb.AppendFormat("共隐藏:{0};", hiddenCount);
                }
                if (sb.Length > 0)
                {
                    this.AppendLog(this.logBuilder, sb.ToString());
                }
                if (log != null)
                {
                    log.ContentLog(this.logBuilder.ToString());
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="conf"></param>
 /// <param name="log"></param>
 /// <param name="source"></param>
 public SyncDataClass(SyncJobConfigurations conf, WinServiceLog log, IDataSync source)
     : base(conf, log, source)
 {
     this.unitsEntity = new UnitsEntity(this.Config.ModuleDefaultDatabase, this.Log);
     this.classesEntity = new ClassesEntity(this.Config.ModuleDefaultDatabase, this.Log);
 }
Esempio n. 6
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="conf"></param>
 /// <param name="log"></param>
 /// <param name="source"></param>
 public SyncDataUnit(SyncJobConfigurations conf, WinServiceLog log, IDataSync source)
     : base(conf, log, source)
 {
     this.unitEntity = new UnitsEntity(conf.ModuleDefaultDatabase, log);
 }
Esempio n. 7
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="conf"></param>
 /// <param name="log"></param>
 /// <param name="source"></param>
 public SyncData(SyncJobConfigurations conf,WinServiceLog log, IDataSync source)
 {
     this.Config = conf;
     this.Log = log;
     this.Source = source;
 }
Esempio n. 8
0
        /// <summary>
        /// 应用程序的主入口点。
        /// </summary>
        /// <param name="args">命令行参数。</param>
        public static void Main(string[] args)
        {
            WinServiceLog servLog = null;
            try
            {
                servLog = new WinServiceLog(ServiceConfig.ModuleConfig);
                string svcName = ServiceConfig.ModuleConfig.ServiceName;
                bool startService = true;

                #region 安装与卸载服务.
                if (args != null && args.Length > 0)
                {
                    string assemblyName = Assembly.GetExecutingAssembly().ManifestModule.Name;
                    switch (args[0].ToLower())
                    {
                        case "-i":
                        case "-install":
                            {
                                #region 安装服务.
                                try
                                {
                                    servLog.ContentLog(string.Format("开始安装[{0}]服务...", svcName));
                                    if (ServiceIsExisted(svcName))
                                    {
                                        servLog.ContentLog(string.Format("服务[{0}]已经存在,无需重复安装。", svcName));
                                        break;
                                    }
                                    ManagedInstallerClass.InstallHelper(new string[] { assemblyName });
                                    ServiceController sc = new ServiceController(svcName);
                                    sc.Start();
                                    servLog.ContentLog(string.Format("安装服务[{0}]成功。", svcName));

                                    startService = true;
                                }
                                catch (Exception e)
                                {
                                    startService = false;
                                    servLog.ContentLog(string.Format("安装[{0}]服务失败[{1}]。", svcName, e.Message));
                                    servLog.ErrorLog(e);
                                }
                                #endregion
                            }
                            break;
                        case "-u":
                        case "-uninstall":
                            {
                                #region 卸载服务.
                                try
                                {
                                    if (ServiceIsExisted(svcName))
                                    {
                                        servLog.ContentLog(string.Format("开始卸载{0}服务...", svcName));
                                        ManagedInstallerClass.InstallHelper(new string[] { "/u", assemblyName });
                                        servLog.ContentLog(string.Format("卸载[{0}]服务成功。", svcName));
                                    }
                                    else
                                    {
                                        servLog.ContentLog(string.Format("服务{0}已经卸载。", svcName));
                                    }

                                }
                                catch (Exception e)
                                {
                                    servLog.ContentLog(string.Format("卸载[{0}]服务失败[{1}]。", svcName, e.Message));
                                    servLog.ErrorLog(e);
                                }
                                finally
                                {
                                    startService = false;
                                }
                                #endregion
                            }
                            break;
                        default:
                            {
                                servLog.ContentLog(string.Format("命令 {0} 不存在。", args));
                                startService = false;
                            }
                            break;
                    }
                }
                #endregion

                //运行服务.
                if (startService)
                {
                    servLog.ContentLog(string.Format("开始启动[{0}]服务...", svcName));
                    ServiceBase.Run(new ServiceBase[] { new ServiceMain(servLog) });
                    servLog.ContentLog(string.Format("[{0}]服务启动成功。", svcName));
                }
            }
            catch (Exception e)
            {
                if (servLog != null)
                {
                    servLog.ErrorLog(new Exception("Windows服务壳程序入口异常:" + e.Message, e));
                }
                else
                {
                    WriteExceptionLog(typeof(Program), new Exception("Windows服务壳程序入口异常:" + e.Message, e));
                }
            }
        }
 /// <summary>
 /// 构造函数。
 /// </summary>
 /// <param name="winServiceJob">Job配置节名。</param>
 public JobConfiguration(string winServiceJob)
     : base(winServiceJob)
 {
     this.servLog = new WinServiceLog(ServiceConfig.ModuleConfig);
     this.jobLog = new WinServiceLog(this);
 }
Esempio n. 10
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="conf"></param>
 /// <param name="log"></param>
 /// <param name="source"></param>
 public SyncDataTea(SyncJobConfigurations conf, WinServiceLog log, IDataSync source)
     : base(conf, log, source)
 {
     this.unitsEntity = new UnitsEntity(this.Config.ModuleDefaultDatabase, log);
     this.teasEntity = new TeachersEntity(this.Config.ModuleDefaultDatabase, log);
 }