public ICollection <FeedCache> GetContent(int collectionId)
        {
            ICollection <FeedCache> contentCache      = new List <FeedCache>();
            DBContentCollection     contentCollection = uow.ContentCollections.GetWithInclude(c => c.ContentCollectionId == collectionId, c => c.Feeds).FirstOrDefault();

            if (contentCollection != null)
            {
                foreach (DBFeed feed in contentCollection.Feeds)
                {
                    ObjectCache cache = MemoryCache.Default;
                    var         key   = feed.FeedId.ToString();
                    FeedCache   fc    = cache[key] as FeedCache;

                    if (fc == null)
                    {
                        bool readed = fReader.getFeedsContent(feed.URL, out fc);
                        if (readed)
                        {
                            CacheItemPolicy cacheItemPolicy = new CacheItemPolicy();
                            cacheItemPolicy.AbsoluteExpiration = DateTime.Now.AddMinutes(10.00);
                            cache.Set(key, fc, cacheItemPolicy);
                            contentCache.Add(fc);
                        }
                    }
                    else
                    {
                        contentCache.Add(fc);
                    }
                }
            }

            return(contentCache);
        }
Esempio n. 2
0
        private Selections Solve(Requirements requirements)
        {
            var selections = Solver.Solve(requirements);

            if (FeedManager.ShouldRefresh || SelectionsManager.GetUncachedSelections(selections).Any())
            {
                FeedManager.Stale   = false;
                FeedManager.Refresh = true;
                selections          = Solver.Solve(requirements);
                FeedManager.Refresh = false;
            }

            try
            {
                selections.Name = FeedCache.GetFeed(selections.InterfaceUri).Name;
            }
            #region Error handling
            catch (KeyNotFoundException)
            {
                // Fall back to using feed file name
                selections.Name = selections.InterfaceUri.ToString().GetRightPartAtLastOccurrence('/');
            }
            #endregion

            return(selections);
        }
Esempio n. 3
0
        /// <inheritdoc/>
        public override ExitCode Execute()
        {
            var feeds = FeedCache.ListAll().Select(x => x.ToStringRfc());

            if (AdditionalArgs.Count > 0)
            {
                feeds = feeds.Where(x => x.ContainsIgnoreCase(AdditionalArgs[0]));
            }

            Handler.Output(Resources.FeedsCached, feeds);
            return(ExitCode.OK);
        }
Esempio n. 4
0
        /// <summary>
        /// Shows a list of changes found by the update process.
        /// </summary>
        protected override ExitCode ShowOutput()
        {
            var builder = new StringBuilder();

            foreach (var oldImplementation in _oldSelections.Implementations)
            {
                var interfaceUri = oldImplementation.InterfaceUri;

                var newImplementation = Selections.GetImplementation(interfaceUri);
                if (newImplementation == null)
                { // Implementation removed
                    builder.AppendLine(Resources.NoLongerUsed + interfaceUri);
                }
                else if (oldImplementation.Version != newImplementation.Version)
                { // Implementation updated
                    builder.AppendLine(interfaceUri + ": " + oldImplementation.Version + " -> " + newImplementation.Version);
                }
            }
            foreach (var newImplementation in Selections.Implementations)
            {
                var interfaceUri = newImplementation.InterfaceUri;
                if (!_oldSelections.ContainsImplementation(interfaceUri))
                { // Implementation added
                    builder.AppendLine(interfaceUri + ": new -> " + newImplementation.Version);
                }
            }

            // Detect replaced feeds
            try
            {
                var feed = FeedCache.GetFeed(Requirements.InterfaceUri);
                if (feed.ReplacedBy != null)
                {
                    builder.AppendLine(string.Format(Resources.FeedReplaced, Requirements.InterfaceUri, feed.ReplacedBy.Target));
                }
            }
            catch (KeyNotFoundException)
            {
            }

            if (builder.Length == 0)
            {
                Handler.OutputLow(Resources.NoUpdatesFound, Resources.NoUpdatesFound);
                return(ExitCode.NoChanges);
            }
            else
            {
                Handler.Output(Resources.ChangesFound, builder.ToString());
                return(ExitCode.OK);
            }
        }
    public DiskFeedCacheTest()
    {
        // Create a temporary cache
        _tempDir = new TemporaryDirectory("0install-test-feeds");
        _cache   = new FeedCache(_tempDir, new Mock <IOpenPgp>().Object);

        // Add some dummy feeds to the cache
        _feed1     = FeedTest.CreateTestFeed();
        _feed1.Uri = FeedTest.Test1Uri;
        _feed1.SaveXml(Path.Combine(_tempDir, _feed1.Uri.Escape()));

        var feed2 = FeedTest.CreateTestFeed();

        feed2.Uri = FeedTest.Test2Uri;
        feed2.SaveXml(Path.Combine(_tempDir, feed2.Uri.Escape()));
        File.WriteAllText(Path.Combine(_tempDir, "http_invalid"), "");
    }
Esempio n. 6
0
        static void Construct()
        {
            LrpClient         = CreateLocalClient(Signature.Value, "SoftFX.LlApi.");
            LrpLlCommonClient = CreateLocalClient(Financial.Generated.Signature.Value, "SoftFX.LlCommon.");

            Serializer = new Financial.Generated.Serializer(LrpLlCommonClient);

            Handle                 = new Handle(LrpClient);
            Params                 = new Params(LrpClient);
            Client                 = new ClientServer(LrpClient);
            ClientCache            = new ClientCache(LrpClient);
            FeedServer             = new FeedServer(LrpClient);
            FeedCache              = new FeedCache(LrpClient);
            TradeServer            = new TradeServer(LrpClient);
            TradeCache             = new TradeCache(LrpClient);
            Converter              = new Converter(LrpClient);
            TradeHistoryIterator   = new TradeHistoryIterator(LrpClient);
            DailySnapshotsIterator = new DailySnapshotsIterator(LrpClient);
            Library                = new Library(LrpClient);
        }
Esempio n. 7
0
        /// <summary>
        /// Runs <see cref="ISolver.Solve"/> (unless <see cref="SelectionsDocument"/> is <c>true</c>) and stores the result in <see cref="Selections"/>.
        /// </summary>
        /// <returns>The same result as stored in <see cref="Selections"/>.</returns>
        /// <exception cref="OperationCanceledException">The user canceled the task.</exception>
        /// <exception cref="WebException">A file could not be downloaded from the internet.</exception>
        /// <exception cref="IOException">An external application or file required by the solver could not be accessed.</exception>
        /// <exception cref="SolverException">The <see cref="ISolver"/> was unable to provide a set of <see cref="Selections"/> that fulfill the <see cref="Requirements"/>.</exception>
        protected virtual void Solve()
        {
            // TODO: Handle named apps

            // Don't run the solver if the user provided an external selections document
            if (SelectionsDocument)
            {
                return;
            }

            try
            {
                Selections = Solver.Solve(Requirements);
            }
            #region Error handling
            catch
            {
                // Suppress any left-over errors if the user canceled anyway
                Handler.CancellationToken.ThrowIfCancellationRequested();
                throw;
            }
            #endregion

            try
            {
                Selections.Name = FeedCache.GetFeed(Selections.InterfaceUri).Name;
            }
            #region Error handling
            catch (KeyNotFoundException)
            {
                // Fall back to using feed file name
                Selections.Name = Selections.InterfaceUri.ToString().GetRightPartAtLastOccurrence('/');
            }
            #endregion

            Handler.CancellationToken.ThrowIfCancellationRequested();
        }
Esempio n. 8
0
    /// <inheritdoc/>
    public override ExitCode Execute()
    {
        Solve();

        var exporter = new Exporter(Selections, Requirements.ForCurrentSystem().Architecture, _outputPath ?? throw new InvalidOperationException($"Must run {nameof(Parse)}() first."));

        exporter.ExportFeeds(FeedCache, OpenPgp);

        if (!_noImplementations)
        {
            DownloadUncachedImplementations();
            exporter.ExportImplementations(ImplementationStore, Handler);
        }

        if (FeedCache.GetFeed(Requirements.InterfaceUri) is {} feed)
        {
            exporter.ExportIcons(
                feed.Icons.Concat(feed.SplashScreens),
                IconStores.DesktopIntegration(Config, Handler, machineWide: false));
        }

        exporter.DeployImportScript();
        switch (_bootstrapType)
        {
        case BootstrapMode.Run:
            exporter.DeployBootstrapRun(Handler);
            break;

        case BootstrapMode.Integrate:
            exporter.DeployBootstrapIntegrate(Handler);
            break;
        }

        BackgroundSelfUpdate();

        return(ShowOutput());
    }
Esempio n. 9
0
File: Native.cs Progetto: ifzz/FDK
        static void Construct()
        {
            LrpClient = CreateLocalClient(Signature.Value, "SoftFX.LlApi.");
            LrpLlCommonClient = CreateLocalClient(Financial.Generated.Signature.Value, "SoftFX.LlCommon.");

            Serializer = new Financial.Generated.Serializer(LrpLlCommonClient);

            Handle = new Handle(LrpClient);
            Params = new Params(LrpClient);
            Client = new ClientServer(LrpClient);
            ClientCache = new ClientCache(LrpClient);
            FeedServer = new FeedServer(LrpClient);
            FeedCache = new FeedCache(LrpClient);
            TradeServer = new TradeServer(LrpClient);
            TradeCache = new TradeCache(LrpClient);
            Converter = new Converter(LrpClient);
            Iterator = new Iterator(LrpClient);
            Library = new Library(LrpClient);
        }