DownloadFile() public method

public DownloadFile ( Uri u ) : void
u System.Uri
return void
Beispiel #1
0
        private void DownloadNext()
        {
            if (requests.Count <= 0) return;
            var im = requests.Peek();
            var a = new Uri(im);

            var dc = new DownloadCache();

            if (dc.ExistsLocal(a))
            {
                dc.DownloadFileCompleted += (e, f) =>
                {
                    if (requests.Any()) requests.Pop();
                    Execute.OnUIThread(() =>
                    {
                        if ((f.Bytes.Count() <= 0)) return;
                        i.Source = LoadImage(f.Bytes);
                        i.Opacity = 1;
                    });
                };

                dc.DownloadFile(a);
            }
            else
            {
                if (busy) return;
                Console.WriteLine(@"Starting download: " + a.AbsoluteUri);

                busy = true;
                dc.DownloadFileCompleted += (e, f) =>
                {
                    busy = false;
                    if (requests.Count > 0) requests.Pop();
                    Execute.OnUIThread(() =>
                    {
                        if ((f.Bytes != null && f.Bytes.Count() > 0) &&
                            GetImage(AppState.TimelineManager.FocusTime) == im)
                        {
                            i.Source = LoadImage(f.Bytes);
                            i.Opacity = 1;
                        }
                    });
                    DownloadNext();
                };

                dc.DownloadFile(a);
                if (GetImage(AppState.TimelineManager.FocusTime) == im)
                {
                    i.Opacity = 0.5;
                }
            }
        }
Beispiel #2
0
 private void AppState_CreateCache(object sender, EventArgs e) {
     ThreadPool.QueueUserWorkItem(delegate {
         var d = AppState.TimelineManager.Start;
         while (d < AppState.TimelineManager.End) {
             try {
                 var a = new Uri(GetImage(d));
                 d = d.AddMinutes(interval);
                 var dc = new DownloadCache();
                 if (dc.ExistsLocal(a)) continue;
                 Console.WriteLine(@"Downloading: " + a.AbsolutePath);
                 dc.DownloadFile(a);
                 Thread.Sleep(250);
             }
             catch (Exception ex) {
                 Logger.Log("FlexibleRadarContent", ex.Message, "Error creating cache", Logger.Level.Error, true);
             }
         }
     });
 }