Пример #1
0
        /*
        private IEnumerable<SectionFeature> GetSectionsInternal()
        {
            var feeds = CoApp.SystemFeeds;

            feeds.ContinueOnFail(e =>
                                     {
                                         throw e.Unwrap();
                                     });

            return feeds.Continue(enumerable =>
                {
                    var hmmm = new List<FeedAndPackages>()
                    foreach
                    var getFeedPackages =
                        enumerable.Select(s =>new FeedAndPackages {Feed=s,
                            Packages= CoApp.GetPackages("*", collectionFilter: p => p.HighestPackages(), locationFeed: s)});

                    return getFeedPackages.Select(t => t.Packages).ContinueAlways(
                        tasks => FeedsAndPackages(getFeedPackages));

                }
               ).Result;
        }*/
        public Task<SectionFeature> GetSectionFeatureForFeed(string feed)
        {
            return Task.Factory.StartNew(() =>
                                             {
                                                 CollectionFilter collectionFilter = null;
                                                 collectionFilter = collectionFilter.Then(p => p.HighestPackages());

                                                 var f = new FeedAndPackages
                                                             {
                                                                 Feed = feed,
                                                                 Packages =
                                                                     CoApp.GetPackages("*",
                                                                                       collectionFilter:
                                                                                           collectionFilter,
                                                                                       locationFeed: feed)
                                                             };
                                                 return CreateSectionFeature(f);
                                             });
        }
Пример #2
0
        private SectionFeature CreateSectionFeature(FeedAndPackages f)
        {
            if (!f.Packages.IsFaulted && !f.Packages.IsCanceled && f.Packages.Result.Any())
            {
                IEnumerable<Package> packages = f.Packages.Result;
                switch (packages.Count())
                {
                    case 1:
                        return new SectionFeature {Name = f.Feed, TopLeft = ProductInfo.FromIPackage(packages.First())};

                    case 2:
                        return new SectionFeature
                                   {
                                       Name = f.Feed,
                                       TopLeft = ProductInfo.FromIPackage(packages.First()),
                                       BottomLeft = ProductInfo.FromIPackage(packages.Skip(1).First())
                                   };

                    case 3:
                        return new SectionFeature
                                   {
                                       Name = f.Feed,
                                       TopLeft = ProductInfo.FromIPackage(packages.First()),
                                       BottomLeft = ProductInfo.FromIPackage(packages.Skip(1).First()),
                                       BottomCenter = ProductInfo.FromIPackage(packages.Skip(2).First())
                                   };

                    default:
                        return new SectionFeature
                                   {
                                       Name = f.Feed,
                                       TopLeft = ProductInfo.FromIPackage(packages.First()),
                                       BottomLeft = ProductInfo.FromIPackage(packages.Skip(1).First()),
                                       BottomCenter = ProductInfo.FromIPackage(packages.Skip(2).First()),
                                       BottomRight = ProductInfo.FromIPackage(packages.Skip(3).First())
                                   };
                }
            }
            return null;
        }