public override BundleViewModel BuildEditorViewModel(BundlePart part)
        {
            var bvm = base.BuildEditorViewModel(part);
            LocalizationPart locPart = part.ContentItem.As <LocalizationPart>();

            if (_bundleProductLocalizationServices.ValidLocalizationPart(locPart))
            {
                List <ProductEntry> oldProducts = bvm.Products.ToList();
                bvm.Products = new List <ProductEntry>();
                foreach (var prodEntry in oldProducts)
                {
                    var item  = _contentManager.Get(prodEntry.ProductId);
                    var lPart = item.As <LocalizationPart>();
                    if (_bundleProductLocalizationServices.ValidLocalizationPart(lPart))
                    {
                        if (lPart.Culture != locPart.Culture)
                        {
                            prodEntry.DisplayText += T(" ({0})", lPart.Culture.Culture);
                        }
                    }
                    else
                    {
                        prodEntry.DisplayText += T(" (culture undefined)");
                    }
                    bvm.Products.Add(prodEntry);
                }
            }
            return(bvm);
        }
コード例 #2
0
ファイル: BundleService.cs プロジェクト: richinoz/Orchard1.6
 public IEnumerable<ProductPartQuantity> GetProductQuantitiesFor(BundlePart bundle) {
     var quantities = bundle.ProductQuantities.ToDictionary(q => q.ProductId, q => q.Quantity);
     var parts = _contentManager.GetMany<ProductPart>(quantities.Keys, VersionOptions.Published, QueryHints.Empty);
     return parts.Select(p => new ProductPartQuantity {
         Product = p,
         Quantity = quantities[p.ContentItem.Id]
     }).ToList();
 } 
コード例 #3
0
        public IEnumerable <ProductPartQuantity> GetProductQuantitiesFor(BundlePart bundle)
        {
            var quantities = bundle.ProductQuantities.ToDictionary(q => q.ProductId, q => q.Quantity);
            var parts      = _contentManager.GetMany <ProductPart>(quantities.Keys, VersionOptions.Published, QueryHints.Empty);

            return(parts.Select(p => new ProductPartQuantity {
                Product = p,
                Quantity = quantities[p.ContentItem.Id]
            }).ToList());
        }
コード例 #4
0
        public virtual IEnumerable <ProductPartQuantity> GetProductQuantitiesFor(BundlePart bundle)
        {
            var quantities = bundle.ProductQuantities.ToDictionary(q => q.ProductId, q => q.Quantity);
            var queryHints = new QueryHints()
                             .ExpandRecords <TitlePartRecord, MediaPartRecord>();
            var parts = _contentManager.GetMany <ProductPart>(quantities.Keys, VersionOptions.Published, queryHints);

            return(parts.Select(p => new ProductPartQuantity {
                Product = p,
                Quantity = quantities[p.ContentItem.Id]
            }).ToList());
        }
        protected override bool ConsiderProductValid(IContent prod, BundlePart part)
        {
            var settings = part.TypePartDefinition.Settings.GetModel <BundleProductLocalizationSettings>();
            var bundleProductQuantities = part.ProductQuantities.ToDictionary(pq => pq.ProductId, pq => pq.Quantity);
            LocalizationPart locPart    = part.ContentItem.As <LocalizationPart>();

            return                                                                             //Conditions under which we consider the product for the bundle:
                   (!settings.HideProductsFromEditor ||                                        //if we should not hide away products, they are all fine
                    !_bundleProductLocalizationServices.ValidLocalizationPart(locPart) ||      //if the bundle does not have a valid LocalizationPart, I have no criteria to hide products
                    bundleProductQuantities.ContainsKey(prod.ContentItem.Id) ||                //the product is in the bundle, so don't hide it
                    (
                        settings.HideProductsFromEditor &&                                     //should hide products in the "wrong" culture
                        !_bundleProductLocalizationServices.HasDifferentCulture(prod, locPart) //keep the products whose culture is not "wrong"
                    ));
        }
コード例 #6
0
ファイル: BundleService.cs プロジェクト: richinoz/Orchard1.6
 public BundleViewModel BuildEditorViewModel(BundlePart part) {
     var bundleProductQuantities = part.ProductQuantities.ToDictionary(pq => pq.ProductId, pq => pq.Quantity);
     return new BundleViewModel {
         Products = GetProducts()
             .Select(
                 p => new ProductEntry {
                     ProductId = p.ContentItem.Id,
                     Product = p,
                     Quantity = bundleProductQuantities.ContainsKey(p.Id) ? bundleProductQuantities[p.Id] : 0,
                     DisplayText = _contentManager.GetItemMetadata(p).DisplayText
                 }
             )
             .OrderBy(vm => vm.DisplayText)
             .ToList()
     };
 }
コード例 #7
0
        public BundleViewModel BuildEditorViewModel(BundlePart part)
        {
            var bundleProductQuantities = part.ProductQuantities.ToDictionary(pq => pq.ProductId, pq => pq.Quantity);

            return(new BundleViewModel {
                Products = GetProducts()
                           .Select(
                    p => new ProductEntry {
                    ProductId = p.ContentItem.Id,
                    Product = p,
                    Quantity = bundleProductQuantities.ContainsKey(p.Id) ? bundleProductQuantities[p.Id] : 0,
                    DisplayText = _contentManager.GetItemMetadata(p).DisplayText
                }
                    )
                           .OrderBy(vm => vm.DisplayText)
                           .ToList()
            });
        }
コード例 #8
0
        public virtual BundleViewModel BuildEditorViewModel(BundlePart part)
        {
            var bundleProductQuantities = part.ProductQuantities.ToDictionary(pq => pq.ProductId, pq => pq.Quantity);

            return(new BundleViewModel {
                Products = GetProducts()
                           .Where(p => ConsiderProductValid(p, part))
                           .Select(
                    p => {
                    var id = p.ContentItem.Id;
                    return new ProductEntry {
                        ProductId = id,
                        Product = p,
                        Quantity = bundleProductQuantities.ContainsKey(id) ? bundleProductQuantities[id] : 0,
                        DisplayText = _contentManager.GetItemMetadata(p).DisplayText
                    };
                }
                    )
                           .OrderBy(vm => vm.DisplayText)
                           .ToList()
            });
        }
コード例 #9
0
 protected virtual bool ConsiderProductValid(IContent prod, BundlePart part)
 {
     return(true);
 }
コード例 #10
0
        // returns list of materials
        public static void ReadBundleStream(EndianStream b_Stream, out List <string> materials, out List <string> gameObjects)
        {
            materials   = null;
            gameObjects = null;
            var header = b_Stream.ReadStringToNull();

            if (header == "UnityFS")
            {
                var ver1 = b_Stream.ReadInt32();
                var ver2 = b_Stream.ReadStringToNull();
                var ver3 = b_Stream.ReadStringToNull();

                long bundleSize = ver1 < 6 ? b_Stream.ReadInt32() : b_Stream.ReadInt64();

                var  cHdrSize    = b_Stream.ReadInt32();
                var  uHdrSize    = b_Stream.ReadInt32();
                var  hdrFlags    = b_Stream.ReadInt32();
                var  compression = hdrFlags & 0x3f;
                var  eofMetadata = (hdrFlags & 0x80) != 0;
                long pos         = 0;
                if (eofMetadata)
                {
                    pos = b_Stream.Position;
                    b_Stream.BaseStream.Seek(-cHdrSize, SeekOrigin.End);
                }
                var data = decompress(b_Stream.ReadBytes(cHdrSize), uHdrSize, compression);
                if (eofMetadata)
                {
                    b_Stream.Position = pos;
                }
                var hdr       = new EndianStream(new MemoryStream(data), EndianType.BigEndian);
                var guid      = hdr.ReadBytes(16);
                var numBlocks = hdr.ReadInt32();
                var blocks    = new BlockInfo[numBlocks];
                for (int i = 0; i < numBlocks; i++)
                {
                    var uSize = hdr.ReadInt32();
                    var cSize = hdr.ReadInt32();
                    var flags = hdr.ReadInt16();
                    blocks[i] = new BlockInfo()
                    {
                        uSize = uSize, cSize = cSize, flags = flags
                    };
                }
                var storage = new Storage(blocks, b_Stream);

                var numParts = hdr.ReadInt32();
                for (int i = 0; i < numParts; i++)
                {
                    var ofs    = hdr.ReadInt64();
                    var size   = hdr.ReadInt64();
                    var status = hdr.ReadInt32();
                    var name   = hdr.ReadStringToNull();
                    var part   = new BundlePart()
                    {
                        stream = new StreamPart(storage, ofs, size), name = name
                    };
                    if (i == 0) //(status & 4) != 0)
                    {
                        LoadAssetFile(new StreamPart(storage, ofs, size), out materials, out gameObjects);
                    }
                }
            }
            else
            {
                throw new Exception("Unknown header: " +
                                    (header[0] > 'A' && header[0] < 'Z' ?
                                     header.Substring(0, 8) :
                                     string.Join(" ", header.Substring(0, 8).ToCharArray().Select(c => ((int)c).ToString("X2")))));
            }
        }
コード例 #11
0
 public IEnumerable <ProductQuantityPair> GetLocalizationIdPairs(BundlePart bundlePart, LocalizationPart locPart)
 {
     return(bundlePart.ProductQuantities
            .Select(TranslatedProductSelector(locPart)));
 }
コード例 #12
0
 public IEnumerable <IContent> GetProductsInTheWrongCulture(BundlePart bundlePart, LocalizationPart locPart)
 {
     return(bundlePart.ProductIds
            .Select(pid => _contentManager.Get(pid))
            .Where(WrongCulturePredicate(locPart)));
 }