Exemple #1
0
        private void DeserializeSchemsHistory()
        {
            using (var streamReader = new StreamReader(Path.Combine(HistoryDataPath, HistoryCacheFile)))
            {
                var xmlSerializer = new XmlSerializer(typeof(Histories));
                var histories     = xmlSerializer.Deserialize(streamReader) as Histories;

                if (histories == null)
                {
                    throw new InvalidOperationException("The History Chace File Is Corrupted. It was deleted!");
                }

                Schemes.Clear();
                History.Clear();
                foreach (var history in histories.AllHistories)
                {
                    var scheme = SchemeCache.ByTitle(history.Scheme.Title);

                    // Is this update necessary? Maybe the scheme was changed and so the history gets updated?
                    history.Scheme = scheme;

                    Schemes.Add(history.Scheme, history);
                    History.Add(history);
                }
            }
        }
        public async Task Refresh()
        {
            IsCacheRefreshing = true;

            var schemes = await StudioStylesService.AllAsync();

            Schemes.Clear();
            foreach (var scheme in schemes)
            {
                Schemes.Add(scheme);
            }

            LastRefresh = DateTime.Now;

            SerializeCachedSchemes(false);

            IsCacheRefreshing      = false;
            IsImageCacheRefreshing = true;

            await CheckSchemes(false);

            SerializeCachedSchemes(true);

            IsCacheValid           = true;
            IsImageCacheRefreshing = false;
        }
        public async Task Check()
        {
            var schemesCachePath = Path.Combine(SchemesDataPath, schemesCacheFile);

            try
            {
                if (File.Exists(schemesCachePath))
                {
                    IsCacheRefreshing = true;

                    var schemes = DeserializeCachedSchemes();

                    IsCacheValid = DateTime.Now.Subtract(schemes.LastRefresh).Days <= 10;

                    Schemes.Clear();
                    foreach (var scheme in schemes.AllSchemes)
                    {
                        Schemes.Add(scheme);
                    }

                    IsCacheRefreshing      = false;
                    IsImageCacheRefreshing = true;

                    await CheckSchemes(schemes.ImagesFinished);

                    SerializeCachedSchemes(true);

                    IsImageCacheRefreshing = false;
                }
                else
                {
                    IsCacheValid      = false;
                    IsCacheRefreshing = false;
                }
            }
            catch (InvalidOperationException)
            {
                IsCacheValid      = false;
                IsCacheRefreshing = false;

                File.Delete(schemesCachePath);
            }
            catch (XmlException)
            {
                IsCacheValid      = false;
                IsCacheRefreshing = false;

                File.Delete(schemesCachePath);
            }
        }