Esempio n. 1
0
        private async static Task <bool> DownloadWeather(FileSet set, string path)
        {
            using (var client = new WebClient())
            {
                try
                {
                    await client.DownloadFileTaskAsync(new Uri($"http://www.meteo.pl/um/metco/mgram_pict.php?ntype=0u&fdate={set.Date.ToString("yyyyMMddHH", IC)}&row={set.Location.Y.ToString(IC)}&col={set.Location.X.ToString(IC)}&lang=pl"), path);

                    return(true);
                }
                catch (System.Net.WebException Ex)
                {
                    Logging.Log(Ex.ToString());
                    return(false);
                }
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Sets image backing WeatherImage to image backed by provided FileSet
 /// </summary>
 /// <param name="set">Image source</param>
 private void SetWeatherSource(FileSet set)
 {
     lock (SyncObject2)
     {
         if ((set != null && set.Status == FileSet.DownloadStatus.Downloaded) && ((Displayed == null) || (Displayed != null && ((Displayed.Location == SelectedLocation && set.Date > Displayed.Date) || (Displayed.Location != SelectedLocation)))))
         {
             if (Displayed != null)
             {
                 Displayed.Status = FileSet.DownloadStatus.Downloaded;
             }
             set.Status = FileSet.DownloadStatus.IsDisplayed;
             Displayed  = set;
             var uriWeather      = new Uri(FileSet.GetFilename(set));
             var uriWeatherLocal = new Uri(uriWeather.LocalPath);
             var Bitmap          = new BitmapImage(uriWeatherLocal);
             Bitmap.Freeze();
             WeatherImage.Dispatcher.BeginInvoke(new Action(() => WeatherImage.Source = Bitmap));
             SetTimeline(set.Date);
         }
     }
 }
Esempio n. 3
0
 /// <summary>
 /// Removes outdated and damaged files
 /// </summary>
 /// <param name="path">Path to folder</param>
 public static void RemoveOutdatedFiles(string path)
 {
     foreach (var file in GetOutdatedAndDamagedFiles(path))
     {
         var set = FileHandler.FileList.Where(x => x == file);
         if (set.Count() != 0)
         {
             set.Single().Status = FileSet.DownloadStatus.ToBeDeleted;
         }
         else
         {
             try
             {
                 File.Delete(FileSet.GetFilename(file));
             }
             catch (IOException Ex)
             {
                 Logging.Log(Ex.ToString());
             }
         }
     }
 }
Esempio n. 4
0
 private void OnChange(object sender, ListChangedEventArgs e)
 {
     lock (SyncObject)
     {
         if (e.CollectionChangedEventArgs != null && e.PropertyChangedEventArgs == null)
         {
             NotifyCollectionChangedEventArgs args = e.CollectionChangedEventArgs;
             if (args.Action == NotifyCollectionChangedAction.Add)
             {
                 foreach (FileSet set in args.NewItems)
                 {
                     if (set.Status == FileSet.DownloadStatus.ToBeDownloaded)
                     {
                         var task = new Task <bool>(() => { return(WeatherDownloader.DownloadAndVerify(set).Result); });
                         task.Start();
                         return;
                     }
                     else if (set.Status == FileSet.DownloadStatus.Downloaded)
                     {
                         return;
                     }
                     else
                     {
                         throw new ArgumentException();
                     }
                 }
             }
             else if (args.Action == NotifyCollectionChangedAction.Replace)
             {
                 throw new NotImplementedException();
             }
             else if (args.Action == NotifyCollectionChangedAction.Remove)
             {
                 foreach (FileSet set in args.OldItems)
                 {
                     try
                     {
                         File.Delete(FileSet.GetFilename(set));
                     }catch (IOException Ex)
                     {
                         Logging.Log(Ex.ToString());
                     }
                 }
             }
             else
             {
                 throw new ArgumentException();
             }
         }
         else if (e.PropertyChangedEventArgs != null && e.CollectionChangedEventArgs == null)
         {
             if (!Enum.TryParse(e.PropertyChangedEventArgs.PropertyName, out FileSet.DownloadStatus previousStatus))
             {
                 throw new InvalidOperationException();
             }
             FileSet set = (FileSet)sender;
             if (set.Status == FileSet.DownloadStatus.Downloaded && previousStatus == FileSet.DownloadStatus.ToBeDownloaded)
             {
                 WeatherFileDownloaded(set, EventArgs.Empty);
                 InternetConnection(set, EventArgs.Empty);
                 return;
             }
             else if (set.Status == FileSet.DownloadStatus.ToBeDeleted)
             {
                 FileList.Remove(set);
                 return;
             }
             else if (set.Status == FileSet.DownloadStatus.IsDisplayed && previousStatus == FileSet.DownloadStatus.Downloaded)
             {
                 return;
             }
             else if (set.Status == FileSet.DownloadStatus.Downloaded && previousStatus == FileSet.DownloadStatus.IsDisplayed)
             {
                 return;
             }
             else if (set.Status == FileSet.DownloadStatus.DownloadFailed && previousStatus == FileSet.DownloadStatus.ToBeDownloaded)
             {
                 WeatherFileDownloaded(set, EventArgs.Empty);
                 NoInternetConnection(set, EventArgs.Empty);
                 return;
             }
             else if (set.Status == FileSet.DownloadStatus.NoWeatherFile && previousStatus == FileSet.DownloadStatus.ToBeDownloaded)
             {
                 WeatherFileDownloaded(set, EventArgs.Empty);
                 InternetConnection(set, EventArgs.Empty);
                 set.Status = FileSet.DownloadStatus.ToBeDeleted;
                 return;
             }
             else if (set.Status == FileSet.DownloadStatus.ToBeDownloaded && previousStatus == FileSet.DownloadStatus.DownloadFailed)
             {
                 var task = new Task <bool>(() => { return(WeatherDownloader.DownloadAndVerify(set).Result); });
                 task.Start();
                 return;
             }
             else
             {
                 throw new InvalidOperationException();
             }
         }
         else
         {
             throw new ArgumentException();
         }
     }
 }
Esempio n. 5
0
 public static string GetName(FileSet set) => GetName(set.Location, set.Date);
Esempio n. 6
0
 public bool CompareLocationAndDate(FileSet other)
 {
     return(this.Location == other.Location && this.Date == other.Date);
 }
Esempio n. 7
0
 public bool Equals(FileSet other)
 {
     return(this == other);
 }