Beispiel #1
0
        public MainWindow()
        {
            InitializeComponent();

            System.IO.Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Meteo App");
            FolderPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Meteo App";
            var htmlPath = FolderPath + "\\Html";

            Directory.CreateDirectory(htmlPath);
            FileSet.FolderPath = FolderPath;

            XManager      = new XMLManager(FolderPath);
            Handler       = new FileHandler(FolderPath);
            LegendHandler = new LegendHandler(FolderPath);
            MapGen        = new MapGenerator(htmlPath);
            Files         = FileHandler.FileList;
            //TODO: sprawdizić które się pokrywają z lokacjami z XManager AllLocations i ustawić name i Update odpowiednio
            FileHandler.WeatherFileDownloaded += OnWeatherFileDownloaded;
            FileHandler.InternetConnection    += OnMeteoConnection;
            FileHandler.NoInternetConnection  += OnNoMeteoConnection;
            NewestWeatherDate = XManager.ReadLastUpdateDate();
            FolderManager.CheckNewestWeather(XManager.DefaultLocation, NewestWeatherDate);

            Locations                    = new ObservableCollection <Location>(XManager.AllLocations.ToList());
            CityList.ItemsSource         = Locations;
            SelectedLocation             = XManager.DefaultLocation;
            CityList.SelectedIndex       = Locations.IndexOf(SelectedLocation);
            Locations.CollectionChanged += new System.Collections.Specialized.NotifyCollectionChangedEventHandler(OnUpdateLocations);

            if (Files.Where(x => x.Location == SelectedLocation && x.Date == NewestWeatherDate).Count() == 0)
            {
                Files.Add(new FileSet(SelectedLocation, NewestWeatherDate, FileSet.DownloadStatus.ToBeDownloaded));
            }
            SetWeatherSource(Files.Where(x => x.Location == SelectedLocation && x.Status == FileSet.DownloadStatus.Downloaded).OrderByDescending(x => x.Date).FirstOrDefault());

            LegendHandler.LegendDownloaded += OnLegendDownloaded;
            if (!LegendHandler.CheckForLegendInFolder(FolderPath))
            {
                LegendHandler.DownloadAndSaveLegend();
            }
            else
            {
                SetLegendSource();
            }

            UpdateTimer          = new System.Windows.Threading.DispatcherTimer();
            UpdateTimer.Tick    += UpdateDispatcherTimer_Tick;
            UpdateTimer.Interval = new TimeSpan(0, 10, 0);
            UpdateTimer.Start();

            CleanupTimer          = new System.Windows.Threading.DispatcherTimer();
            CleanupTimer.Tick    += CleanupDispatcherTimer_Tick;
            CleanupTimer.Interval = new TimeSpan(0, 15, 0);
            CleanupTimer.Start();

            NoInternetTimer          = new System.Windows.Threading.DispatcherTimer();
            NoInternetTimer.Tick    += NoInternetTimer_Tick;
            NoInternetTimer.Interval = new TimeSpan(0, 1, 0);
        }
Beispiel #2
0
 private void CleanupDispatcherTimer_Tick(object sender, EventArgs e)
 {
     if (!Files.Any(x => x.Status == FileSet.DownloadStatus.ToBeDownloaded || x.Status == FileSet.DownloadStatus.ToBeDeleted))
     {
         FolderManager.RemoveOutdatedFiles(FolderPath);
     }
     MapGenerator.Cleanup(FolderPath);
 }
Beispiel #3
0
 private void UpdateDispatcherTimer_Tick(object sender, EventArgs e)
 {
     lock (SyncObject2)
     {
         CheckForNewestWeatherFiles();
         FolderManager.CheckNewestWeather(SelectedLocation, NewestWeatherDate);
         SetTimeline(Files.Where(x => x.Status == FileSet.DownloadStatus.IsDisplayed).Single().Date);
     }
 }
Beispiel #4
0
 /// <param name="path">Path to folder with program data.</param>
 public FileHandler(string path)
 {
     Path = path;
     FileList.CollectionChanged   += OnFileListCollectionchanged;
     FileList.ItemPropertyChanged += OnItemPropertyChanged;
     InternetConnection           += OnInternetConnection;
     NoInternetConnection         += OnNoInternetConnection;
     foreach (var set in FolderManager.CheckFolder(Path))
     {
         FileList.Add(set);
     }
 }