Example #1
0
        private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
        {
            Action Finish = () =>
            {
                Status = e.Error == null ? DownloadStatus.Ready : DownloadStatus.Failed;
                App.DownloadManager.DownloadList.Remove(this);
                if (Status == DownloadStatus.Ready)
                {
                    if ((URLCollection == null) || (!URLCollection.Any(c => App.DownloadManager.DownloadList.Any(d => d.URL == c)))) // if there are no files left to download from this collection, then call the callback-function.
                    {
                        string[] Files;
                        if (URLCollection == null)
                        {
                            Files    = new string[1];
                            Files[0] = System.IO.Path.Combine(Folder, DownloadsViewModel.GetFileNameFromURL(URL));
                        }
                        else
                        {
                            Files = new string[URLCollection.Length];
                            for (int i = 0; i < URLCollection.Length; i++)
                            {
                                Files[i] = System.IO.Path.Combine(Folder, DownloadsViewModel.GetFileNameFromURL(URLCollection[i]));
                            }
                        }

                        Callback(Files, State);
                    }
                }
            };

            if (UIContext != null)
            {
                UIContext.Post(d => Finish(), null);
            }
        }
Example #2
0
 internal SearchResult(string URL, string Category, Action <string[], object> Callback, object State)
 {
     UIContext     = SynchronizationContext.Current;
     URLs          = new string[1];
     URLs[0]       = URL;
     Name          = DownloadsViewModel.GetFileNameFromURL(URL);
     this.Callback = Callback;
     this.State    = State;
     this.Category = Category;
     GetSize();
 }
Example #3
0
        internal DownloadEntry(string URL, string Folder, string[] URLCollection, Action <string[], object> Callback, object State)
        {
            UIContext          = SynchronizationContext.Current;
            this.URL           = URL;
            this.Callback      = Callback;
            this.State         = State;
            this.URLCollection = URLCollection;
            this.Folder        = Folder;
            Directory.CreateDirectory(Folder);
            Name = DownloadsViewModel.GetFileNameFromURL(URL);
            Uri Uri = new Uri(URL);

            Status = DownloadStatus.Downloading;
            new Thread(() =>
            {
                Size = DownloadsViewModel.GetFileLengthFromURL(URL);

                Client = new MyWebClient();
                Client.DownloadFileCompleted   += Client_DownloadFileCompleted;
                Client.DownloadProgressChanged += Client_DownloadProgressChanged;
                Client.DownloadFileAsync(Uri, Path.Combine(Folder, DownloadsViewModel.GetFileNameFromURL(Uri.LocalPath)), null);
            }).Start();
        }