예제 #1
0
 /// <summary>
 ///  读取配置文件,支持动态配置
 /// </summary>
 private void WorkerScan()
 {
     if (Directory.Exists(confDir))
     {
         try
         {
             var files = Directory.GetFiles(confDir);
             foreach (var file in files)
             {
                 var conf = new WorkerConf();
                 if (conf.LoadFromFile(file))
                 {
                     if (workers.ContainsKey(conf.Name))
                     {
                         Log.Debug($"{conf.Name} already exist ,skip !");
                         continue;
                     }
                     var worker = new TimerWorker(conf);
                     workers.Add(conf.Name, worker);
                     worker.Run();
                 }
             }
         } catch (Exception ex)
         {
             Log.Warn($"Load conf error : {ex.Message} , skip");
         }
     }
 }
예제 #2
0
 public TimerWorker(WorkerConf workerConf)
 {
     Conf           = workerConf;
     timer          = new Timer();
     timer.Elapsed += Work;
     timer.Interval = 2000;
 }
예제 #3
0
 public void CopyFromOther(WorkerConf conf)
 {
     File            = conf.File;
     Interval        = conf.Interval;
     AccessKeyId     = conf.AccessKeyId;
     AccessKeySecret = conf.AccessKeySecret;
     DomainName      = conf.DomainName;
     SubDomainName   = conf.SubDomainName;
     Type            = conf.Type;
     TTL             = conf.TTL;
     Line            = conf.Line;
     GetIpUrls       = conf.GetIpUrls;
 }
예제 #4
0
 public void CopyFromOther(WorkerConf conf)
 {
     File            = conf.File;
     Interval        = conf.Interval;
     AccessKeyId     = conf.AccessKeyId;
     AccessKeySecret = conf.AccessKeySecret;
     DomainName      = conf.DomainName;
     SubDomainNames  = new List <string>();
     foreach (var item in conf.SubDomainNames)
     {
         SubDomainNames.Add(item);
     }
     Type      = conf.Type;
     TTL       = conf.TTL;
     Line      = conf.Line;
     GetIpUrls = conf.GetIpUrls;
 }
예제 #5
0
        private void OnConfCreated(object sender, FileSystemEventArgs e)
        {
            string file = e.FullPath ?? "";

            if (string.IsNullOrWhiteSpace(file))
            {
                return;
            }
            int count = 0;

            while (!file.IsFileReady())
            {
                if (!File.Exists(file))
                {
                    return;
                }
                Thread.Sleep(100);
                if (++count >= 50)
                {
                    return;
                }
            }
            WorkerConf conf = new WorkerConf();

            if (!conf.LoadFromFile(file))
            {
                return;
            }
            if (workers.ContainsKey(conf.Name))
            {
                Log.Debug($"{conf.Name} already exist ,skip !");
                return;
            }
            var worker = new TimerWorker(conf);

            workers.Add(conf.Name, worker);
            worker.Run();
        }