Exemplo n.º 1
0
        /// <summary>
        /// Loads all <see cref="Feed"/>s stored in <see cref="IFeedCache"/> into memory.
        /// </summary>
        /// <param name="cache">The <see cref="IFeedCache"/> to load <see cref="Feed"/>s from.</param>
        /// <returns>The parsed <see cref="Feed"/>s. Damaged files are logged and skipped.</returns>
        /// <exception cref="IOException">A problem occured while reading from the cache.</exception>
        /// <exception cref="UnauthorizedAccessException">Read access to the cache is not permitted.</exception>
        public static IEnumerable <Feed> GetAll([NotNull] this IFeedCache cache)
        {
            #region Sanity checks
            if (cache == null)
            {
                throw new ArgumentNullException("cache");
            }
            #endregion

            var feeds = new List <Feed>();
            foreach (var feedUri in cache.ListAll())
            {
                try
                {
                    feeds.Add(cache.GetFeed(feedUri));
                }
                #region Error handling
                catch (KeyNotFoundException)
                {
                    // Feed file no longer exists
                }
                catch (InvalidDataException ex)
                {
                    Log.Error(ex);
                }
                #endregion
            }
            return(feeds);
        }
Exemplo n.º 2
0
    /// <summary>
    /// Loads all <see cref="Feed"/>s stored in <see cref="IFeedCache"/> into memory.
    /// </summary>
    /// <param name="cache">The <see cref="IFeedCache"/> to load <see cref="Feed"/>s from.</param>
    /// <returns>The parsed <see cref="Feed"/>s. Damaged files are logged and skipped.</returns>
    /// <exception cref="IOException">A problem occurred while reading from the cache.</exception>
    /// <exception cref="UnauthorizedAccessException">Read access to the cache is not permitted.</exception>
    public static IEnumerable <Feed> GetAll(this IFeedCache cache)
    {
        #region Sanity checks
        if (cache == null)
        {
            throw new ArgumentNullException(nameof(cache));
        }
        #endregion

        var feeds = new List <Feed>();
        foreach (var feedUri in cache.ListAll())
        {
            try
            {
                var feed = cache.GetFeed(feedUri);
                if (feed != null)
                {
                    feeds.Add(feed);
                }
            }
            #region Error handling
            catch (InvalidDataException ex)
            {
                Log.Error(ex);
            }
            #endregion
        }
        return(feeds);
    }
Exemplo n.º 3
0
        /// <summary>
        /// Creates a new interface dialog.
        /// </summary>
        /// <param name="interfaceUri">The interface to modify the preferences for.</param>
        /// <param name="solveCallback">Called after <see cref="InterfacePreferences"/> have been changed and the <see cref="ISolver"/> needs to be rerun.</param>
        /// <param name="feedCache">The feed cache used to retrieve feeds for additional information about implementations.</param>
        private InterfaceDialog([NotNull] FeedUri interfaceUri, [NotNull] Func <Selections> solveCallback, [NotNull] IFeedCache feedCache)
        {
            #region Sanity checks
            if (interfaceUri == null)
            {
                throw new ArgumentNullException("interfaceUri");
            }
            if (solveCallback == null)
            {
                throw new ArgumentNullException("solveCallback");
            }
            if (feedCache == null)
            {
                throw new ArgumentNullException("feedCache");
            }
            #endregion

            InitializeComponent();
            comboBoxStability.Items.AddRange(new object[] { Resources.UseDefaultSetting, Stability.Stable, Stability.Testing, Stability.Developer });
            dataColumnUserStability.Items.AddRange(Stability.Unset, Stability.Preferred, Stability.Packaged, Stability.Stable, Stability.Testing, Stability.Developer);

            _interfaceUri  = interfaceUri;
            _mainFeed      = feedCache.GetFeed(_interfaceUri);
            _solveCallback = solveCallback;
            _feedCache     = feedCache;
        }
Exemplo n.º 4
0
 private Feed LoadLocal(FeedUri feedUri)
 {
     if (File.Exists(feedUri.LocalPath))
     {
         // Use cache even for local files since there may be in-memory caching
         try
         {
             return(_feedCache.GetFeed(feedUri));
         }
         #region Error handling
         catch (InvalidDataException ex)
         {
             // Wrap exception since only certain exception types are allowed
             throw new IOException(ex.Message, ex);
         }
         #endregion
     }
     throw new FileNotFoundException(string.Format(Resources.FileNotFound, feedUri.LocalPath), feedUri.LocalPath);
 }
Exemplo n.º 5
0
        public IEnumerable <Implementation> GetImplementations([NotNull] IEnumerable <ImplementationSelection> selections)
        {
            #region Sanity checks
            if (selections == null)
            {
                throw new ArgumentNullException("selections");
            }
            #endregion

            foreach (var selection in selections)
            {
                yield return(selection.ID.StartsWith(ExternalImplementation.PackagePrefix)
                    ? _packageManager.Lookup(selection)
                    : _feedCache.GetFeed(selection.FromFeed ?? selection.InterfaceUri)[selection.ID].CloneImplementation());
            }
        }
Exemplo n.º 6
0
        private IEnumerable <SelectionCandidate> GenerateDummyCandidates(FeedUri feedUri)
        {
            if (feedUri.IsFromDistribution)
            {
                return(Enumerable.Empty <SelectionCandidate>());
            }

            try
            {
                var feed            = _feedCache.GetFeed(feedUri);
                var feedPreferences = FeedPreferences.LoadForSafe(feedUri);
                return(feed.Elements.OfType <Implementation>().Select(implementation => GenerateDummyCandidate(feedUri, feedPreferences, implementation)));
            }
            #region Error handling
            catch (KeyNotFoundException)
            {
                return(Enumerable.Empty <SelectionCandidate>());
            }
            #endregion
        }
Exemplo n.º 7
0
 private Feed LoadCached(FeedUri feedUri)
 {
     try
     {
         var feed = _feedCache.GetFeed(feedUri);
         Stale |= IsStale(feedUri);
         return(feed);
     }
     #region Error handling
     catch (InvalidDataException ex)
     {
         // Wrap exception since only certain exception types are allowed
         throw new IOException(ex.Message, ex);
     }
     catch (KeyNotFoundException ex)
     {
         // Wrap exception since only certain exception types are allowed
         throw new IOException(ex.Message, ex);
     }
     #endregion
 }
Exemplo n.º 8
0
        /// <inheritdoc/>
        public Feed GetFeed(FeedUri feedUri)
        {
            #region Sanity checks
            if (feedUri == null)
            {
                throw new ArgumentNullException("feedUri");
            }
            #endregion

            string key = feedUri.Escape();
            lock (_feedDictionary)
            {
                if (!_feedDictionary.ContainsKey(key))
                { // Add to memory cache if missing
                    Feed feed = _backingCache.GetFeed(feedUri);
                    _feedDictionary.Add(key, feed);
                    return(feed);
                }

                // Get from memory cache
                return(_feedDictionary[key]);
            }
        }
Exemplo n.º 9
0
        private void BuildTable()
        {
            tableLayout.Controls.Clear();
            tableLayout.RowStyles.Clear();

            tableLayout.RowCount = _selections.Implementations.Count;
            for (int i = 0; i < _selections.Implementations.Count; i++)
            {
                // Lines have a fixed height but a variable width
                tableLayout.RowStyles.Add(new RowStyle(SizeType.Absolute, 54 * AutoScaleDimensions.Height / 13F));

                // Get feed for each selected implementation
                var implementation = _selections.Implementations[i];
                var feed           = _feedCache.GetFeed(implementation.FromFeed ?? implementation.InterfaceUri);

                // Display application name and implementation version
                tableLayout.Controls.Add(new Label {
                    Text = feed.Name, Dock = DockStyle.Fill, TextAlign = ContentAlignment.MiddleLeft
                }, 0, i);
                tableLayout.Controls.Add(new Label {
                    Text = (implementation.Version == null ? null : implementation.Version.ToString()), Dock = DockStyle.Fill, TextAlign = ContentAlignment.MiddleLeft
                }, 1, i);
            }
        }
Exemplo n.º 10
0
        private async Task <SpotlightFeedReader> InitializeAsync_(IFeedCache <string> cache)
        {
            // DEBUGGING ONLY: a hardcoded delay to make sure the loading page is working correctly
            //await Task.Run(() =>
            //{
            //    Thread.Sleep(5000);
            //});

            // if the cache has not yet been initialized, initialize it
            if (cache == null)
            {
                cache = await SpotlightFeedCacheFactory.CreateSpotlightFeedCache();
            }

            m_cache = cache;

            SpotlightItemRoot root = null;

            // try to load the feed from the web first
            var json = await LoadJsonFromWeb_(m_url);

            if (json != null)
            {
                // try to deserialize
                root = await DeserializeJson_(json);

                if (root == null)
                {
                    // invalid json, clear it and try to fetch from cache
                    json = null;
                }
                else
                {
                    // if there are web-based images, download them and re-serialize to json
                    json = await SerializeJsonWithLocalImages_(root);

                    // store the result back in cache; at this point we know we have valid json
                    await cache.PutFeedAsync(json);
                }
            }

            // if we didn't get a valid feed from the web, try to fetch from cache
            if (json == null)
            {
                json = cache.GetFeed();
                if (json != null)
                {
                    // try to deserialize
                    root = await DeserializeJson_(json);

                    if (root == null)
                    {
                        json = null;
                    }
                }
            }

            m_root = root;

            return(this);
        }