基本信息
源码名称:C#自动更新服务(本地服务安装)
源码大小:1.21M
文件格式:.zip
开发语言:C#
更新时间:2015-03-11
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300

本次赞助数额为: 3 元 
   源码介绍


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Common.WinService;
using Common.Log;
using System.Threading;
using Common.Net;
using System.Text.RegularExpressions;
namespace Collection.AutoRunner
{
    //获取学生信息
    public class Service_Update_Data : IWindowsService
    {
        private ILogWriter _logWriter = null;
        private const string logCategory = "Services.Info";
        private string logInfoSource = "Update_Data";
        private const string logErrorCategory = "Services.Error";
        private const string logErrorSource = "Update_Data_Error";
        private bool BeStop = true;
        private System.Timers.Timer timer = null;
        public void Start(Common.Log.ILogWriter logWriter, string gameCode)
        {
            gameCode = gameCode.ToUpper();
            logInfoSource = gameCode;
            _logWriter = logWriter;
            BeStop = false;
            StartRequestData();
        }
        int stata = 0;
        private void StartRequestData()
        {
            try
            {
                #region 配置
                //时间频率
                var UpdateStudentSpan = ServiceHelper.GetInterval("UpdateData");
                //更新学生开始时间
                var studentbegintime = ServiceHelper.GetInterval("StudentBeginTime");
                //更新学生结束时间
                var studentendtime = ServiceHelper.GetInterval("StudentEndTime");    
                //是否更新学生基本信息:true为更新 false为不更新
                var IsUpdateStudnet =Convert.ToBoolean(ServiceHelper.GetSystemConfig("IsUpdateStudnet"));                
                #endregion
                timer = ServiceHelper.ExcuteByTimer(UpdateStudentSpan, () =>
                {
                    int timeHour = DateTime.Now.Hour;
                    if (timeHour == 3)
                        stata = 0;
                    #region 更新学生基本信息
                    if (studentbegintime <= timeHour && timeHour < studentendtime && stata == 0 && IsUpdateStudnet)
                    {
                        stata = 1;
                        StudentInfo();
                    }
                    else
                    {
                        this.WriteLog("还未到获取学生基本信息的时间段内... ");
                    }
                    #endregion      
                    StartRequestData();
                });

            }
            catch (Exception ex)
            {
                this.WriteLog("获取学生信息数据出错 - " ex.Message);
            }
        }
        private void StudentInfo()
        {
            int repeatTimes = 0;
            try
            {
                this.WriteLog("开始获取学生信息数据....");      
                this.WriteLog("学生信息数据获取完成....");
            }
            catch (Exception ex)
            {
                this.WriteLog("获取学生信息数据出错 - DoWork -" ex.Message);
                if (repeatTimes == 0)
                {
                    repeatTimes ;
                    StudentInfo();
                }
            }
        }
        public void Stop()
        {
            BeStop = true;
            if (timer != null)
                timer.Stop();
        }
        public void WriteError(string log)
        {
            _logWriter.Write(logErrorCategory, logErrorSource, LogType.Error, "自动获取学生信息数据异常", log);
        }
        public void WriteLog(string log)
        {
            _logWriter.Write(logCategory, logInfoSource, LogType.Information, "自动获取学生信息数据", log);
        }
    }
}