Exemple #1
0
 public Executor(IScriptConfig cfg)
 {
     ddns   = new DDNS(Encoding.UTF8);
     config = new UserConfig(cfg)
     {
         nsBuffer = ddns.NSBuffer
     };
     project = new Project(config.script.ProjectDTE, config.script.ProjectsMBE);
 }
Exemple #2
0
        public void Run()
        {
            log.Write("SLOONG_DDNS Service Start.");
            try
            {
                // Get param from Registry
                // Check interval time. default is 60 second
                string access_key_id     = reg.GetValue("AccessKeyID", "");
                string access_key_secret = reg.GetValue("AccessKeySecret", "");
                string domain_name       = reg.GetValue("DomainName", "");
                string record_name       = reg.GetValue("RecordName", "");
                string ddns_Type         = reg.GetValue("DDNSType", "");

                if (string.IsNullOrEmpty(access_key_id) ||
                    string.IsNullOrEmpty(access_key_secret) ||
                    string.IsNullOrEmpty(domain_name) ||
                    string.IsNullOrEmpty(record_name) ||
                    string.IsNullOrEmpty(ddns_Type))
                {
                    log.Write("Param error.", LogLevel.Error);
                    Environment.Exit(1);
                }
                var refresh_time = reg.GetValue("IPRefreshTime", "");
                if (string.IsNullOrWhiteSpace(refresh_time))
                {
                    _IPRefreshTime = DateTime.MinValue;
                }
                else if (!DateTime.TryParse(refresh_time, out _IPRefreshTime))
                {
                    log.Write("Try parse IPRefreshTime fialed. the value is:" + refresh_time, LogLevel.Warn);
                    _IPRefreshTime = DateTime.MinValue;
                }

                // ip lift time, unit is hour, but we need check it beforehand. so need convert to mintue.
                _IP_Life_Time    = Convert.ToInt32(reg.GetValue("IPLifeTime", "24")) * 60;
                _Beforehand_Time = Convert.ToInt32(reg.GetValue("BeforehandTime", "30"));
                _IP_Life_Time    = _IP_Life_Time - _Beforehand_Time;
                // Time is minute. so need convert to millisecond.
                _Low_Interval  = Convert.ToInt32(reg.GetValue("LowInterval", "60"));
                _High_Interval = Convert.ToInt32(reg.GetValue("HighInterval", "5"));

                //log.Write(string.Format("Work params:IPLifeTime[{}]", _IP_Life_Time), LogLevel.Debug);

                if (ddns_Type == "AliDDNS")
                {
                    iDDNS = new AliDDNS();
                }
                else
                {
                    log.Write("No support ddns type.", LogLevel.Error);
                    Environment.Exit(1);
                }

                iDDNS.Initialize(access_key_id, access_key_secret, domain_name, record_name, log);

                /*var timer1 = new System.Timers.Timer();
                 * timer1.Interval = 3000;  //设置计时器事件间隔执行时间
                 * timer1.Elapsed += new System.Timers.ElapsedEventHandler(OnTimer);
                 * timer1.Enabled = true;*/

                _Running         = true;
                _WorkThread      = new Thread(WorkLoop);
                _WorkThread.Name = "Work Thread";
                _WorkThread.Start();
            }
            catch (Exception e)
            {
                log.Write(e.ToString(), LogLevel.Fatal);
            }
        }