Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private List<DownloadFile> downloadFiles;
- public List<DownloadFile> DownloadFiles
- {
- get { return downloadFiles; }
- set
- {
- downloadFiles = value;
- OnPropertyChanged("DownloadFiles");
- }
- }
- private ExtractImages ei;
- private List<string> newList;
- private List<string> countryList;
- public RelayCommand DownloadCommand { get; set; }
- public RelayCommand OpenFileCommand { get; set; }
- public static DownloadFileViewModel SharedViewModel()
- {
- return _viewModel ?? (_viewModel = new DownloadFileViewModel());
- }
- private DownloadFileViewModel()
- {
- DownloadCommand = new RelayCommand(Download, CanDownload);
- OpenFileCommand = new RelayCommand(OpenFile, CanOpenFile);
- DownloadFiles = new List<DownloadFile>();
- newList = new List<string>();
- countryList = new List<string>();
- ei = new ExtractImages();
- ei.Init();
- if (countryList.Count() == 0)
- {
- foreach (ExtractImages.Continent continent in ei.world.continents)
- {
- //Console.WriteLine(continent.name);
- foreach (ExtractImages.Country country in continent.countries)
- {
- if (country.name == "Israel")
- {
- foreach (string imageUri in country.imageUrls)
- {
- countryList.Add(imageUri);
- DownloadFiles.Add(new DownloadFile { Uri = imageUri });
- }
- }
- else
- {
- //Console.WriteLine(country.name);
- foreach (string imageUri in country.imageUrls)
- {
- //Console.WriteLine(imageUri);
- newList.Add(imageUri);
- }
- }
- }
- }
- }
- DownloadFiles.Add(new DownloadFile { Uri = imageUri });
- DownloadFiles.Add(new DownloadFile { Uri = "http://www.auby.no/files/video_tests/h264_720p_hp_5.1_6mbps_ac3_unstyled_subs_planet.mkv" });
- 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" });
- DownloadFiles.Add(new DownloadFile { Uri = "http://www.auby.no/files/video_tests/h264_720p_hp_5.1_6mbps_ac3_unstyled_subs_planet.mkv" });
- DownloadFiles.Add(new DownloadFile { Uri = "http://www.auby.no/files/video_tests/h264_720p_mp_3.1_3mbps_aac_shrinkage.mp4" });
- DownloadFiles.Add(new DownloadFile { Uri = "http://www.auby.no/files/video_tests/h264_720p_hp_5.1_6mbps_ac3_planet.mp4" });
- http://www.sat24.com/image2.ashx?region=is&time=201701232030&ir=true
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Linq;
- using System.Net;
- using System.Text;
- using System.Threading.Tasks;
- using AsynchronousDownloader.ViewModel;
- namespace AsynchronousDownloader.Model
- {
- public class DownloadFile : INotifyPropertyChanged
- {
- private string filename;
- public string Filename
- {
- get { return filename; }
- set
- {
- filename = value;
- OnPropertyChanged("Filename");
- }
- }
- private string downloadLocation;
- public string DownloadLocation
- {
- get { return downloadLocation; }
- set
- {
- downloadLocation = value;
- OnPropertyChanged("DownloadLocation");
- }
- }
- private string uri;
- public string Uri
- {
- get { return uri; }
- set
- {
- uri = value;
- Filename = value.Split('/').Last();
- FileSize = CalculateFileSize(value);
- OnPropertyChanged("Uri");
- }
- }
- private string downloadPercentageString;
- public string DownloadPercentageString
- {
- get { return downloadPercentageString; }
- set
- {
- downloadPercentageString = value;
- OnPropertyChanged("DownloadPercentageString");
- }
- }
- private int downloadPercentage;
- public int DownloadPercentage
- {
- get { return downloadPercentage; }
- set
- {
- downloadPercentage = value;
- OnPropertyChanged("DownloadPercentage");
- }
- }
- private string downloadTime;
- public string DownloadTime
- {
- get { return downloadTime; }
- set
- {
- downloadTime = value;
- OnPropertyChanged("DownloadTime");
- }
- }
- private string downloadSpeed;
- public string DownloadSpeed
- {
- get { return downloadSpeed; }
- set
- {
- downloadSpeed = value;
- OnPropertyChanged("DownloadSpeed");
- }
- }
- private string fileSize;
- public string FileSize
- {
- get { return fileSize; }
- set
- {
- fileSize = value;
- OnPropertyChanged("FileSize");
- }
- }
- private DownloadStatus downloadStatus;
- public DownloadStatus DownloadStatus
- {
- get { return downloadStatus; }
- set
- {
- downloadStatus = value;
- DownloadFileViewModel.CanDownload(this);
- OnPropertyChanged("DownloadStatus");
- }
- }
- public event PropertyChangedEventHandler PropertyChanged;
- public void OnPropertyChanged(string propertyName)
- {
- if (this.PropertyChanged != null)
- this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
- }
- private string CalculateFileSize(string uri)
- {
- HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
- req.Method = "HEAD";
- HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
- return string.Format("{0} MB", Math.Round((double)resp.ContentLength / 1048576, 2));
- }
- }
- public enum DownloadStatus
- {
- NotDownloaded,
- Downloading,
- Downloaded
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement