Ejemplo n.º 1
0
 /// <summary>
 /// 把TseJob放到Queue內
 /// </summary>
 /// <param name="job"></param>
 private void AddJob(TseJob job)
 {
     if (job != null)
     {
         Console.WriteLine("[ AddJob ] 把任務類型[ {0} ]的任務加入到Queue裡面", job.JobType.ToUpper());
         this._jobQueue.Enqueue(job);
         return;
     }
 }
Ejemplo n.º 2
0
        public void SetCompleteJob(TseJob job)
        {
            Console.WriteLine("[ SetCompleteJob ] 準備把任務[ {0} ]設定為完成", job.MainDirName);
            JobCreator creator = null;

            if (this._jobCreatorMap.TryGetValue(job.CreatorType, out creator))
            {
                creator.AddCompleteJob(job);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Timer Thread在約3到5分鐘內會執行一次這個Method
        /// </summary>
        /// <param name="state"></param>
        private void DoTseJob(object state)
        {
            TseJob job = null;

            if (this._jobQueue.TryDequeue(out job))
            {
                Console.WriteLine("[ DoTseJob ] 從Queue裡面取得一個任務,並準備開始執行這項任務 T: {0}", DateTime.Now.ToString("HH:mm:ss fff"));
                try
                {
                    this._doJobTimes += 1;
                    HttpSender     sender = new HttpSender(job.Url);
                    ResponseResult result = sender.SendRequest(HttpRequestMethod.Get, "", job.HttpHeader);
                    if (result.IsResultError == false)
                    {
                        //Save data to folder
                        FileInfo fi = new FileInfo(job.FilePath);
                        if (fi.Exists == false)
                        {
                            Directory.CreateDirectory(fi.Directory.FullName);
                        }
                        using (StreamWriter sw = new StreamWriter(job.FilePath, false, Encoding.UTF8))
                        {
                            sw.Write(result.ResponseBody);
                        }
                        job.IsComplete = true;
                        job.WithErr    = false;
                        this._creatorFactory.SetCompleteJob(job);
                    }

                    if (this._doJobTimes > 2)
                    {
                        this._timerThread.Change(new TimeSpan(0, 0, GetNextSecond()), new TimeSpan(0, 0, GetNextSecond()));
                        ResetDoJobTimes();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine("+---------------------------------------------------------");
                    Console.WriteLine("|EE        EEEE        EE    EEEEEEEEEEEE    EEEEEEEEEE");
                    Console.WriteLine("| RR      RR  RR      RR          RR         RR");
                    Console.WriteLine("|  RR    RR    RR    RR           RR         RRRRRR");
                    Console.WriteLine("|   OO  OO      OO  OO            OO         OO");
                    Console.WriteLine("|    RRRR        RRRR             RR         RR");
                    Console.WriteLine("+---------------------------------------------------------");
                    job.IsComplete = false;
                    job.WithErr    = true;
                    Console.WriteLine(e.Message);
                    Console.Write(e.StackTrace);
                }
            }
            else
            {
                this._timerThread.Change(1000, _baseSecond * 1000);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 定時產生一個任務
        /// </summary>
        /// <param name="state"></param>
        public void CreateJob(object state)
        {
            Console.WriteLine("[ CreateJob ] Thread Timer 開始定時產生一個TseJob");

            JobCreator creator = null;

            do
            {
                creator = this._creatorFactory.RandomProduce();
                if (creator != null)
                {
                    TseJob aJob = null;
                    do
                    {
                        aJob = creator.CreateJob();
                    } while (aJob == null);

                    AddJob(aJob);
                }
            } while (creator == null);
        }
Ejemplo n.º 5
0
 public abstract void AddCompleteJob(TseJob job);