WorkWithPages.cs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Net;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. using System.Windows.Threading;
  8. using Test6_mod.ViewModels.Exceptions;
  9. using Test6_mod.ViewModels.Event;
  10. using Test6_mod.Models;
  11. namespace Test6_mod.ViewModels.UI
  12. {
  13. public class WorkWithPages
  14. {
  15. public event EventHandler<AddInfoEventArgs> ThreadStop;
  16. public event EventHandler<AddInfoEventArgs> FinalThreadsAll;
  17. private MultiDownload md;
  18. private int GetCount(int c)
  19. {
  20. switch (c)
  21. {
  22. case 0:
  23. throw new MultiDownloadIsNullExeption();
  24. case 1:
  25. return 1;
  26. case 2:
  27. return 2;
  28. case 3:
  29. return 3;
  30. default:
  31. return 3;
  32. }
  33. }
  34. private void StartPage_StartScan(in StartScanUrlEventArgs e)
  35. {
  36. md = new MultiDownload(GetCount(e.ListURL.Count), e.ListURL);
  37. int j = 0;
  38. foreach (var i in e.ListURL)
  39. {
  40. if (!i.IsStatus)
  41. j += 1;
  42. }
  43. md.StartDownloading(j);
  44. }
  45. public WorkWithPages() { }
  46. public WorkWithPages(StartScanUrlEventArgs e)
  47. {
  48. StartPage_StartScan(e);
  49. md.ThreadStopInfo += MultiDownload_ThreadStopInfo;
  50. md.FinalThreadInfo += Md_FinalThreadInfo;
  51. }
  52. private void Md_FinalThreadInfo(object sender, FinishScanEventArgs e)
  53. {
  54. FinalThreadsAll(this, new AddInfoEventArgs());
  55. }
  56. private void MultiDownload_ThreadStopInfo(object sender, ThreadFinishInfoEventArgs e)
  57. {
  58. ThreadStop(this, new AddInfoEventArgs(e.Msg));
  59. }
  60. }
  61. }