Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.56 KB | None | 0 0
  1. private List<DownloadFile> downloadFiles;
  2. public List<DownloadFile> DownloadFiles
  3.  
  4. {
  5. get { return downloadFiles; }
  6. set
  7. {
  8. downloadFiles = value;
  9. OnPropertyChanged("DownloadFiles");
  10. }
  11. }
  12.  
  13. private ExtractImages ei;
  14. private List<string> newList;
  15. private List<string> countryList;
  16. public RelayCommand DownloadCommand { get; set; }
  17. public RelayCommand OpenFileCommand { get; set; }
  18.  
  19. public static DownloadFileViewModel SharedViewModel()
  20. {
  21. return _viewModel ?? (_viewModel = new DownloadFileViewModel());
  22. }
  23.  
  24. private DownloadFileViewModel()
  25. {
  26. DownloadCommand = new RelayCommand(Download, CanDownload);
  27. OpenFileCommand = new RelayCommand(OpenFile, CanOpenFile);
  28. DownloadFiles = new List<DownloadFile>();
  29.  
  30. newList = new List<string>();
  31. countryList = new List<string>();
  32. ei = new ExtractImages();
  33. ei.Init();
  34. if (countryList.Count() == 0)
  35. {
  36. foreach (ExtractImages.Continent continent in ei.world.continents)
  37. {
  38. //Console.WriteLine(continent.name);
  39. foreach (ExtractImages.Country country in continent.countries)
  40. {
  41. if (country.name == "Israel")
  42. {
  43. foreach (string imageUri in country.imageUrls)
  44. {
  45. countryList.Add(imageUri);
  46. DownloadFiles.Add(new DownloadFile { Uri = imageUri });
  47. }
  48. }
  49. else
  50. {
  51. //Console.WriteLine(country.name);
  52. foreach (string imageUri in country.imageUrls)
  53. {
  54. //Console.WriteLine(imageUri);
  55. newList.Add(imageUri);
  56. }
  57. }
  58. }
  59. }
  60. }
  61.  
  62. DownloadFiles.Add(new DownloadFile { Uri = imageUri });
  63.  
  64. DownloadFiles.Add(new DownloadFile { Uri = "http://www.auby.no/files/video_tests/h264_720p_hp_5.1_6mbps_ac3_unstyled_subs_planet.mkv" });
  65. DownloadFiles.Add(new DownloadFile { Uri = "http://www.auby.no/files/video_tests/h264_720p_hp_3.1_600kbps_aac_mp3_dual_audio_harry_potter.mkv" });
  66. DownloadFiles.Add(new DownloadFile { Uri = "http://www.auby.no/files/video_tests/h264_720p_hp_5.1_6mbps_ac3_unstyled_subs_planet.mkv" });
  67. DownloadFiles.Add(new DownloadFile { Uri = "http://www.auby.no/files/video_tests/h264_720p_mp_3.1_3mbps_aac_shrinkage.mp4" });
  68. DownloadFiles.Add(new DownloadFile { Uri = "http://www.auby.no/files/video_tests/h264_720p_hp_5.1_6mbps_ac3_planet.mp4" });
  69.  
  70. http://www.sat24.com/image2.ashx?region=is&time=201701232030&ir=true
  71.  
  72. using System;
  73. using System.Collections.Generic;
  74. using System.ComponentModel;
  75. using System.Linq;
  76. using System.Net;
  77. using System.Text;
  78. using System.Threading.Tasks;
  79. using AsynchronousDownloader.ViewModel;
  80.  
  81. namespace AsynchronousDownloader.Model
  82. {
  83. public class DownloadFile : INotifyPropertyChanged
  84. {
  85. private string filename;
  86. public string Filename
  87. {
  88. get { return filename; }
  89. set
  90. {
  91. filename = value;
  92. OnPropertyChanged("Filename");
  93. }
  94. }
  95.  
  96. private string downloadLocation;
  97. public string DownloadLocation
  98. {
  99. get { return downloadLocation; }
  100. set
  101. {
  102. downloadLocation = value;
  103. OnPropertyChanged("DownloadLocation");
  104. }
  105. }
  106.  
  107. private string uri;
  108. public string Uri
  109. {
  110. get { return uri; }
  111. set
  112. {
  113. uri = value;
  114. Filename = value.Split('/').Last();
  115. FileSize = CalculateFileSize(value);
  116. OnPropertyChanged("Uri");
  117. }
  118. }
  119.  
  120. private string downloadPercentageString;
  121. public string DownloadPercentageString
  122. {
  123. get { return downloadPercentageString; }
  124. set
  125. {
  126. downloadPercentageString = value;
  127. OnPropertyChanged("DownloadPercentageString");
  128. }
  129. }
  130.  
  131. private int downloadPercentage;
  132. public int DownloadPercentage
  133. {
  134. get { return downloadPercentage; }
  135. set
  136. {
  137. downloadPercentage = value;
  138. OnPropertyChanged("DownloadPercentage");
  139. }
  140. }
  141.  
  142. private string downloadTime;
  143. public string DownloadTime
  144. {
  145. get { return downloadTime; }
  146. set
  147. {
  148. downloadTime = value;
  149. OnPropertyChanged("DownloadTime");
  150. }
  151. }
  152.  
  153. private string downloadSpeed;
  154. public string DownloadSpeed
  155. {
  156. get { return downloadSpeed; }
  157. set
  158. {
  159. downloadSpeed = value;
  160. OnPropertyChanged("DownloadSpeed");
  161. }
  162. }
  163.  
  164. private string fileSize;
  165. public string FileSize
  166. {
  167. get { return fileSize; }
  168. set
  169. {
  170. fileSize = value;
  171. OnPropertyChanged("FileSize");
  172. }
  173. }
  174.  
  175. private DownloadStatus downloadStatus;
  176. public DownloadStatus DownloadStatus
  177. {
  178. get { return downloadStatus; }
  179. set
  180. {
  181. downloadStatus = value;
  182. DownloadFileViewModel.CanDownload(this);
  183. OnPropertyChanged("DownloadStatus");
  184. }
  185. }
  186.  
  187. public event PropertyChangedEventHandler PropertyChanged;
  188. public void OnPropertyChanged(string propertyName)
  189. {
  190. if (this.PropertyChanged != null)
  191. this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
  192. }
  193.  
  194. private string CalculateFileSize(string uri)
  195. {
  196. HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
  197. req.Method = "HEAD";
  198. HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
  199. return string.Format("{0} MB", Math.Round((double)resp.ContentLength / 1048576, 2));
  200. }
  201. }
  202.  
  203. public enum DownloadStatus
  204. {
  205. NotDownloaded,
  206. Downloading,
  207. Downloaded
  208. }
  209. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement