Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new <see cref="Selections"/> control.
        /// </summary>
        public SelectionsControl()
        {
            InitializeComponent();
            CreateHandle();

            TaskControls = new TransparentCache <ManifestDigest, TaskControl>(CreateTaskControls);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Creates a new <see cref="SelectionCandidate"/> provider.
        /// </summary>
        /// <param name="config">User settings controlling network behaviour, solving, etc.</param>
        /// <param name="feedManager">Provides access to remote and local <see cref="Feed"/>s. Handles downloading, signature verification and caching.</param>
        /// <param name="store">Used to check which <see cref="Implementation"/>s are already cached.</param>
        /// <param name="packageManager">An external package manager that can install <see cref="PackageImplementation"/>s.</param>
        public SelectionCandidateProvider([NotNull] Config config, [NotNull] IFeedManager feedManager, [NotNull] IStore store, [NotNull] IPackageManager packageManager)
        {
            #region Sanity checks
            if (config == null)
            {
                throw new ArgumentNullException("config");
            }
            if (feedManager == null)
            {
                throw new ArgumentNullException("feedManager");
            }
            if (store == null)
            {
                throw new ArgumentNullException("store");
            }
            if (packageManager == null)
            {
                throw new ArgumentNullException("packageManager");
            }
            #endregion

            _config         = config;
            _isCached       = BuildCacheChecker(store);
            _packageManager = packageManager;
            _comparer       = new TransparentCache <FeedUri, SelectionCandidateComparer>(id => new SelectionCandidateComparer(config, _isCached, _interfacePreferences[id].StabilityPolicy, CultureInfo.CurrentUICulture));
            _feeds          = new TransparentCache <FeedUri, Feed>(feedManager.GetFeed);
        }
Ejemplo n.º 3
0
        public Bitmap GetTransparentBitmap(Rectangle section, bool flipX = false, bool flipY = false)
        {
            Bitmap bmp;

            if (TransparentCache.TryGetValue(new CacheKey(section, flipX, flipY), out bmp))
            {
                return(bmp);
            }
            else
            {
                if (TransparentBitmap == null)
                {
                    Reload(PaletteDataPath);
                }
                bmp = CropImage(TransparentBitmap, section);
                if (flipX)
                {
                    bmp.RotateFlip(RotateFlipType.RotateNoneFlipX);
                }
                if (flipY)
                {
                    bmp.RotateFlip(RotateFlipType.RotateNoneFlipY);
                }

                TransparentCache.Add(new CacheKey(section, flipX, flipY), bmp);
                return(bmp);
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Creates a new <see cref="SelectionCandidate"/> provider.
        /// </summary>
        /// <param name="config">User settings controlling network behaviour, solving, etc.</param>
        /// <param name="feedManager">Provides access to remote and local <see cref="Feed"/>s. Handles downloading, signature verification and caching.</param>
        /// <param name="store">Used to check which <see cref="Implementation"/>s are already cached.</param>
        /// <param name="packageManager">An external package manager that can install <see cref="PackageImplementation"/>s.</param>
        /// <param name="languages">The preferred languages for the implementation.</param>
        public SelectionCandidateProvider([NotNull] Config config, [NotNull] IFeedManager feedManager, [NotNull] IStore store, [NotNull] IPackageManager packageManager, [NotNull] LanguageSet languages)
        {
            #region Sanity checks
            if (config == null)
            {
                throw new ArgumentNullException(nameof(config));
            }
            if (feedManager == null)
            {
                throw new ArgumentNullException(nameof(feedManager));
            }
            if (store == null)
            {
                throw new ArgumentNullException(nameof(store));
            }
            if (packageManager == null)
            {
                throw new ArgumentNullException(nameof(packageManager));
            }
            if (languages == null)
            {
                throw new ArgumentNullException(nameof(languages));
            }
            #endregion

            _config         = config;
            _feedManager    = feedManager;
            _isCached       = BuildCacheChecker(store);
            _packageManager = packageManager;
            _comparer       = new TransparentCache <FeedUri, SelectionCandidateComparer>(id => new SelectionCandidateComparer(config, _isCached, _interfacePreferences[id].StabilityPolicy, languages));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a new <see cref="SelectionCandidate"/> provider.
        /// </summary>
        /// <param name="config">User settings controlling network behaviour, solving, etc.</param>
        /// <param name="feedManager">Provides access to remote and local <see cref="Feed"/>s. Handles downloading, signature verification and caching.</param>
        /// <param name="implementationStore">Used to check which <see cref="Implementation"/>s are already cached.</param>
        /// <param name="packageManager">An external package manager that can install <see cref="PackageImplementation"/>s.</param>
        public SelectionCandidateProvider(Config config, IFeedManager feedManager, IImplementationStore implementationStore, IPackageManager packageManager)
        {
            _config = config ?? throw new ArgumentNullException(nameof(config));
            if (feedManager == null)
            {
                throw new ArgumentNullException(nameof(feedManager));
            }
            if (implementationStore == null)
            {
                throw new ArgumentNullException(nameof(implementationStore));
            }
            _packageManager = packageManager ?? throw new ArgumentNullException(nameof(packageManager));

            _interfacePreferences    = new TransparentCache <FeedUri, InterfacePreferences>(InterfacePreferences.LoadForSafe);
            _externalImplementations = new Dictionary <string, ExternalImplementation>();
            _storeContains           = new TransparentCache <ManifestDigest, bool>(implementationStore.Contains);
            _feeds = new TransparentCache <FeedUri, Feed?>(feedUri =>
            {
                try
                {
                    var feed = feedManager[feedUri];
                    if (feed.MinInjectorVersion != null && ImplementationVersion.ZeroInstall < feed.MinInjectorVersion)
                    {
                        Log.Warn($"The Zero Install version is too old. The feed '{feedUri}' requires at least version {feed.MinInjectorVersion} but the installed version is {ImplementationVersion.ZeroInstall}. Try updating Zero Install.");
                        return(null);
                    }
                    return(feed);
                }
                catch (WebException ex)
                {
                    Log.Warn(ex);
                    return(null);
                }
            });
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a new <see cref="Selections"/> control.
        /// </summary>
        public SelectionsControl()
        {
            InitializeComponent();
            CreateHandle();

            TrackingControls = new TransparentCache<ManifestDigest, TaskControl>(CreateTrackingControl);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Creates a new composite implementation provider with a set of <see cref="IStore"/>s.
        /// </summary>
        /// <param name="stores">
        ///   A priority-sorted list of <see cref="IStore"/>s.
        ///   Queried last-to-first for adding new <see cref="Store.Model.Implementation"/>s, first-to-last otherwise.
        /// </param>
        public CompositeStore([NotNull, ItemNotNull] IEnumerable<IStore> stores)
        {
            #region Sanity checks
            if (stores == null) throw new ArgumentNullException("stores");
            #endregion

            _stores = stores.ToArray();
            _containsCache = new TransparentCache<ManifestDigest, bool>(manifestDigest => _stores.Any(store => store.Contains(manifestDigest)));
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Creates a new caching dectorator.
        /// </summary>
        /// <param name="inner">The inner <see cref="ICredentialProvider"/> to wrap.</param>
        public CachedCredentialProvider([NotNull] ICredentialProvider inner)
        {
            #region Sanity checks
            if (inner == null) throw new ArgumentNullException(nameof(inner));
            #endregion

            _inner = inner;
            _cache = new TransparentCache<Uri, NetworkCredential>(uri => inner.GetCredential(uri, null));
        }
Ejemplo n.º 9
0
 private void DisposeOpaqueCache()
 {
     if (null == TransparentCache)
     {
         return;
     }
     foreach (Bitmap b in TransparentCache.Values)
     {
         b?.Dispose();
     }
     TransparentCache.Clear();
 }
Ejemplo n.º 10
0
    /// <summary>
    /// Creates a new <see cref="SelectionCandidate"/> provider.
    /// </summary>
    /// <param name="config">User settings controlling network behaviour, solving, etc.</param>
    /// <param name="feedManager">Provides access to remote and local <see cref="Feed"/>s. Handles downloading, signature verification and caching.</param>
    /// <param name="implementationStore">Used to check which <see cref="Implementation"/>s are already cached.</param>
    /// <param name="packageManager">An external package manager that can install <see cref="PackageImplementation"/>s.</param>
    public SelectionCandidateProvider(Config config, IFeedManager feedManager, IImplementationStore implementationStore, IPackageManager packageManager)
    {
        _config         = config ?? throw new ArgumentNullException(nameof(config));
        _feedManager    = feedManager ?? throw new ArgumentNullException(nameof(feedManager));
        _packageManager = packageManager ?? throw new ArgumentNullException(nameof(packageManager));

        if (implementationStore == null)
        {
            throw new ArgumentNullException(nameof(implementationStore));
        }
        _storeContains = new(implementationStore.Contains);
    }
        /// <summary>
        /// Creates a new composite implementation store with a set of <see cref="IImplementationStore"/>s.
        /// </summary>
        /// <param name="innerStores">
        ///   A priority-sorted list of <see cref="IImplementationStore"/>s.
        ///   Queried last-to-first for adding new <see cref="Implementation"/>s, first-to-last otherwise.
        /// </param>
        public CompositeImplementationStore(IEnumerable <IImplementationStore> innerStores)
        {
            #region Sanity checks
            if (innerStores == null)
            {
                throw new ArgumentNullException(nameof(innerStores));
            }
            #endregion

            _innerStores   = innerStores.ToArray();
            _containsCache = new TransparentCache <ManifestDigest, bool>(manifestDigest => _innerStores.Any(x => x.Contains(manifestDigest)));
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates a new composite implementation provider with a set of <see cref="IStore"/>s.
        /// </summary>
        /// <param name="stores">
        ///   A priority-sorted list of <see cref="IStore"/>s.
        ///   Queried last-to-first for adding new <see cref="Implementation"/>s, first-to-last otherwise.
        /// </param>
        public CompositeStore([NotNull, ItemNotNull] IEnumerable <IStore> stores)
        {
            #region Sanity checks
            if (stores == null)
            {
                throw new ArgumentNullException(nameof(stores));
            }
            #endregion

            _stores        = stores.ToArray();
            _containsCache = new TransparentCache <ManifestDigest, bool>(manifestDigest => _stores.Any(store => store.Contains(manifestDigest)));
        }
        /// <summary>
        /// Returns a predicate that checks whether a given <see cref="Implementation"/> is cached in the <paramref name="store"/>
        /// (or has an <see cref="ImplementationBase.LocalPath"/> or <see cref="ExternalImplementation.IsInstalled"/>).
        /// </summary>
        private static Predicate<Implementation> BuildCacheChecker(IStore store)
        {
            var storeContainsCache = new TransparentCache<ManifestDigest, bool>(store.Contains);

            return implementation =>
            {
                if (!string.IsNullOrEmpty(implementation.LocalPath)) return true;

                var externalImplementation = implementation as ExternalImplementation;
                if (externalImplementation != null) return externalImplementation.IsInstalled;

                return storeContainsCache[implementation.ManifestDigest];
            };
        }
Ejemplo n.º 14
0
        public void Test()
        {
            int callCounter = 0;
            var cache = new TransparentCache<string, string>(input =>
            {
                callCounter++;
                return input + "X";
            });

            cache["input"].Should().Be("inputX");
            callCounter.Should().Be(1, because: "Should call retriever callback on first request");

            cache["input"].Should().Be("inputX");
            callCounter.Should().Be(1, because: "Should not call retriever callback again on subsequent requests");
        }
Ejemplo n.º 15
0
        private static Predicate <Implementation> BuildCacheChecker(IStore store)
        {
            var storeContainsCache = new TransparentCache <ManifestDigest, bool>(store.Contains);

            return(implementation =>
            {
                var externalImplementation = implementation as ExternalImplementation;
                if (externalImplementation != null)
                {
                    return externalImplementation.IsInstalled;
                }

                return storeContainsCache[implementation.ManifestDigest];
            });
        }
        /// <summary>
        /// Creates a new <see cref="SelectionCandidate"/> provider.
        /// </summary>
        /// <param name="config">User settings controlling network behaviour, solving, etc.</param>
        /// <param name="feedManager">Provides access to remote and local <see cref="Feed"/>s. Handles downloading, signature verification and caching.</param>
        /// <param name="store">Used to check which <see cref="Implementation"/>s are already cached.</param>
        /// <param name="packageManager">An external package manager that can install <see cref="PackageImplementation"/>s.</param>
        /// <param name="languages">The preferred languages for the implementation.</param>
        public SelectionCandidateProvider([NotNull] Config config, [NotNull] IFeedManager feedManager, [NotNull] IStore store, [NotNull] IPackageManager packageManager, [NotNull] LanguageSet languages)
        {
            #region Sanity checks
            if (config == null) throw new ArgumentNullException(nameof(config));
            if (feedManager == null) throw new ArgumentNullException(nameof(feedManager));
            if (store == null) throw new ArgumentNullException(nameof(store));
            if (packageManager == null) throw new ArgumentNullException(nameof(packageManager));
            if (languages == null) throw new ArgumentNullException(nameof(languages));
            #endregion

            _config = config;
            _feedManager = feedManager;
            _isCached = BuildCacheChecker(store);
            _packageManager = packageManager;
            _comparer = new TransparentCache<FeedUri, SelectionCandidateComparer>(id => new SelectionCandidateComparer(config, _isCached, _interfacePreferences[id].StabilityPolicy, languages));
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Creates a new caching dectorator.
 /// </summary>
 /// <param name="inner">The inner <see cref="ICredentialProvider"/> to wrap.</param>
 public CachedCredentialProvider([NotNull] ICredentialProvider inner)
 {
     _inner = inner ?? throw new ArgumentNullException(nameof(inner));
     _cache = new TransparentCache <Uri, NetworkCredential>(uri => inner.GetCredential(uri, null));
 }