Esempio n. 1
0
        public void Do()
        {
            //
            DownloaderQueue downloaderQueue = new DownloaderQueue();
            int             downloadCount   = 0;
            int             ingoreCount     = 0;

            //
            List <Downloader> downloaders = ParseTaskXml();

            for (int i = 0; i < downloaders.Count; i++)
            {
                //
                Downloader downloader = downloaders[i];

                //
                FileInfo fi = new FileInfo(task + "\\" + downloader.FilePath + downloader.FileName);
                if (fi.Exists && (fi.Length == downloader.FileSize))
                {
                    ingoreCount++;
                    continue;
                }

                //
                downloaderQueue.Add(downloader);
                downloadCount++;
            }
            System.Console.WriteLine(string.Format("Load task:{0} ingore:{1}", downloadCount, ingoreCount));

            //
            List <Thread> threads = new List <Thread>();

            for (int i = 0; i < 10; i++)
            {
                Thread thread = new Thread(delegate()
                {
                    while (true)
                    {
                        Downloader downloader = downloaderQueue.Get();
                        if (downloader == null)
                        {
                            break;
                        }
                        downloader.Do(task);
                    }
                }
                                           );
                thread.Start();
                threads.Add(thread);
            }

            //
            for (int i = 0; i < threads.Count; i++)
            {
                threads[i].Join();
            }

            //
            int missingCount = 0;

            for (int i = 0; i < downloaders.Count; i++)
            {
                //
                Downloader downloader = downloaders[i];

                //
                FileInfo fi = new FileInfo(task + "\\" + downloader.FilePath + downloader.FileName);
                if (!fi.Exists || (fi.Length != downloader.FileSize))
                {
                    missingCount++;
                    System.Console.WriteLine(string.Format("Missing: {0}", downloader.Url));
                }
            }

            //
            if (missingCount > 0)
            {
                Console.WriteLine(string.Format("RunTask [{0}] Complete!", task));
                Console.WriteLine(string.Format("missing {0} file{1}, Please retry.", missingCount, (missingCount > 1 ? "s" : "")));
                return;
            }

            //
            Console.WriteLine(string.Format("RunTask [{0}] Complete!", task));
        }
Esempio n. 2
0
		public void Do()
		{
			//
			DownloaderQueue downloaderQueue = new DownloaderQueue();
			int downloadCount = 0;
			int ingoreCount = 0;

			//
			List<Downloader> downloaders = ParseTaskXml();
			for (int i = 0; i < downloaders.Count; i++)
			{
				//
				Downloader downloader = downloaders[i];

				//
				FileInfo fi = new FileInfo(task + "\\" + downloader.FilePath + downloader.FileName);
				if (fi.Exists && (fi.Length == downloader.FileSize))
				{
					ingoreCount++;
					continue;
				}
				
				//
				downloaderQueue.Add(downloader);
				downloadCount++;
			}
			System.Console.WriteLine(string.Format("Load task:{0} ingore:{1}", downloadCount, ingoreCount));

			//
			List<Thread> threads = new List<Thread>();
			for (int i = 0; i < 10; i++)
			{
				Thread thread = new Thread(delegate()
					{
						while (true)
						{
							Downloader downloader = downloaderQueue.Get();
							if (downloader == null)
							{
								break;
							}
							downloader.Do(task);
						}
					}
				);
				thread.Start();
				threads.Add(thread);
			}

			//
			for (int i = 0; i < threads.Count; i++)
			{
				threads[i].Join();
			}

			//
			int missingCount = 0;
			for (int i = 0; i < downloaders.Count; i++)
			{
				//
				Downloader downloader = downloaders[i];

				//
				FileInfo fi = new FileInfo(task + "\\" + downloader.FilePath + downloader.FileName);
				if (!fi.Exists || (fi.Length != downloader.FileSize))
				{
					missingCount++;
					System.Console.WriteLine(string.Format("Missing: {0}", downloader.Url));
				}
			}

			//
			if (missingCount > 0)
			{
				Console.WriteLine(string.Format("RunTask [{0}] Complete!", task));
				Console.WriteLine(string.Format("missing {0} file{1}, Please retry.", missingCount, (missingCount > 1 ? "s" : "")));
				return;
			}

			//
			Console.WriteLine(string.Format("RunTask [{0}] Complete!", task));
		}