예제 #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);
        }
예제 #2
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);
     }
 }