public ReactorFuelType(IEnumerable <ReactorFuelMode> reactorFuelModes) { Variants = reactorFuelModes.ToList(); ResourceGroups = new List <ResourceGroupMetaData>(); foreach (var group in Variants.SelectMany(m => m.ReactorFuels).GroupBy(m => m.FuelName)) { ResourceGroups.Add(new ResourceGroupMetaData() { name = group.Key, resourceVariantsMetaData = group.Select(m => new FuelResourceMetaData(m.Definition, m.Ratio)).Distinct().ToList() }); } var first = Variants.First(); Index = first.Index; ModeGUIName = first.ModeGUIName; TechLevel = first.TechLevel; TechRequirement = first.TechRequirement; SupportedReactorTypes = first.SupportedReactorTypes; Aneutronic = first.Aneutronic; RequiresLab = first.RequiresLab; RequiresUpgrade = first.RequiresUpgrade; ChargedPowerRatio = first.ChargedPowerRatio; MeVPerChargedProduct = first.MeVPerChargedProduct; NormalisedReactionRate = first.NormalisedReactionRate; NormalisedPowerRequirements = first.NormalisedPowerRequirements; NeutronsRatio = first.NeutronsRatio; TritiumBreedModifier = first.TritiumBreedModifier; FuelEfficencyMultiplier = first.FuelEfficencyMultiplier; }
/// <summary> /// Calculates the variant data such as selected options, their categories etc. /// </summary> private void CalculateVariantData() { // Current selected options(item2 in tuple) in selectors and theirs categories(item1 in tuple) mSelectedOptionsInCategories = new List <Tuple <int, int> >(); // All possible options and theirs categories in dictionary with option ID as a key and category ID as value mOptionsInCategories = new Dictionary <int, int>(); mRelatedSelectors = new List <ProductOptionSelector>(); // Categories used in variants IEnumerable <int> usedCategoriesInVariants = new List <int>(); // Do not evaluate variants when there are no selectors displayed if (OptionSelectors.Any() && (Variants.Count != 0)) { usedCategoriesInVariants = Variants.First().ProductAttributes.CategoryIDs; } // Get product options and categories from selectors foreach (var selector in OptionSelectors) { // Get option category of this selector var category = selector.OptionCategory; // Ignore non-attribute categories and categories not included in Variants if ((category.CategoryType == OptionCategoryTypeEnum.Attribute) && usedCategoriesInVariants.Contains(category.CategoryID)) { string option = selector.GetSelectedSKUOptions(); // Get selected option id for this selector and add new Tuple<category, option> to selected option collection int selectedOptionId = ValidationHelper.GetInteger(option, 0); mSelectedOptionsInCategories.Add(new Tuple <int, int>(category.CategoryID, selectedOptionId)); // Get all options for this category from selector to reduce SQL queries DataSet dsAllOptions = selector.ProductOptionsData; if (DataHelper.DataSourceIsEmpty(dsAllOptions)) { continue; } List <int> allOptionsId = (List <int>)DataHelper.GetIntegerValues(dsAllOptions.Tables[0], "SKUID"); // Add option ids (plus category ids) to dictionary allOptionsId.ForEach(opt => { if (!mOptionsInCategories.ContainsKey(opt)) { mOptionsInCategories.Add(opt, category.CategoryID); } }); mRelatedSelectors.Add(selector); } } }
public ReactorFuelType(IEnumerable <ReactorFuelMode> reactorFuelModes) { Variants = reactorFuelModes.ToList(); ResourceGroups = new List <ResourceGroupMetaData>(); foreach (var group in Variants.SelectMany(m => m.ReactorFuels).GroupBy(m => m.FuelName)) { ResourceGroups.Add(new ResourceGroupMetaData() { name = group.Key, resourceVariantsMetaData = group.Select(m => new FuelResourceMetaData(m.Definition, m.Ratio)).Distinct().ToList() }); } var first = Variants.First(); AlternativeFuelType1 = first.AlternativeFuelType1; AlternativeFuelType2 = first.AlternativeFuelType2; AlternativeFuelType3 = first.AlternativeFuelType3; AlternativeFuelType4 = first.AlternativeFuelType4; AlternativeFuelType5 = first.AlternativeFuelType5; AlternativeFuelType6 = first.AlternativeFuelType6; Index = first.Index; ModeGUIName = first.ModeGuiName; DisplayName = first.DisplayName; TechLevel = first.TechLevel; MinimumFusionGainFactor = first.MinimumQ; TechRequirement = first.TechRequirement; SupportedReactorTypes = first.SupportedReactorTypes; Aneutronic = first.Aneutronic; Hidden = first.Hidden; GammaRayEnergy = first.GammaRayEnergy; RequiresLab = first.RequiresLab; RequiresUpgrade = first.RequiresUpgrade; ChargedPowerRatio = first.ChargedPowerRatio; MeVPerChargedProduct = first.MeVPerChargedProduct; ReactionRatePowerMultiplier = first.ReactionRatePowerMultiplier; NormalizedPowerMultiplier = first.NormalizedPowerMultiplier; NormalizedPowerRequirements = first.NormalizedPowerRequirements; NeutronsRatio = first.NeutronsRatio; TritiumBreedModifier = first.TritiumBreedModifier; FuelEfficiencyMultiplier = first.FuelEfficiencyMultiplier; }
/// <summary> /// Loads product options. /// </summary> private void LoadProductOptions() { DataSet dsCategories = null; if (IsLiveSite) { // Get cache minutes int cacheMinutes = SettingsKeyInfoProvider.GetIntValue(SiteContext.CurrentSiteName + ".CMSCacheMinutes"); // Try to get data from cache using (var cs = new CachedSection <DataSet>(ref dsCategories, cacheMinutes, true, null, "skuoptioncategories", SKUID)) { if (cs.LoadData) { // Get all option categories for SKU dsCategories = OptionCategoryInfoProvider.GetProductOptionCategories(SKUID, false); // Save to the cache if (cs.Cached) { // Get dependencies var dependencies = new List <string> { "ecommerce.sku|byid|" + SKUID, "ecommerce.optioncategory|all" }; // Set dependencies cs.CacheDependency = CacheHelper.GetCacheDependency(dependencies); } cs.Data = dsCategories; } } } else { // Get all option categories for SKU dsCategories = OptionCategoryInfoProvider.GetProductOptionCategories(SKUID, false); } // Initialize product option selectors if (!DataHelper.DataSourceIsEmpty(dsCategories)) { mProductOptions = new Hashtable(); // Is only one option category available for variants? var variantCategories = Variants.Any() ? Variants.First().ProductAttributes.CategoryIDs.ToList() : null; mOneCategoryUsed = variantCategories != null && variantCategories.Count == 1; foreach (DataRow dr in dsCategories.Tables[0].Rows) { try { // Load control for selection product options ProductOptionSelector selector = (ProductOptionSelector)LoadUserControl("~/CMSModules/Ecommerce/Controls/ProductOptions/ProductOptionSelector.ascx"); // Add control to the collection var categoryID = ValidationHelper.GetInteger(dr["CategoryID"], 0); selector.ID = "opt" + categoryID; // Init selector selector.LocalShoppingCartObj = ShoppingCart; selector.IsLiveSite = IsLiveSite; selector.CssClassFade = CssClassFade; selector.CssClassNormal = CssClassNormal; selector.SKUID = SKUID; selector.OptionCategory = new OptionCategoryInfo(dr); // If one category is used, fix the one selector with options to use only options which are not in disabled variants if (mOneCategoryUsed && variantCategories.Contains(categoryID)) { var disabled = from variant in Variants where !variant.Variant.SKUEnabled from productAttributes in variant.ProductAttributes select productAttributes.SKUID; var disabledList = disabled.ToList(); selector.ProductOptionsInDisabledVariants = disabledList.Any() ? disabledList : null; } // Load all product options foreach (DictionaryEntry entry in selector.ProductOptions) { mProductOptions[entry.Key] = entry.Value; } var lc = selector.SelectionControl as ListControl; if (lc != null) { // Add Index change handler lc.AutoPostBack = true; } pnlSelectors.Controls.Add(selector); } catch { } } } }
/// <summary> /// Loads product options. /// </summary> private void LoadProductOptions() { // Get all option categories for SKU DataSet dsCategories = OptionCategoryInfoProvider.GetProductOptionCategories(SKUID, false); // Initialize product option selectors if (!DataHelper.DataSourceIsEmpty(dsCategories)) { mProductOptions = new Hashtable(); // Is only one option category available for variants? var variantCategories = Variants.Any() ? Variants.First().ProductAttributes.CategoryIDs.ToList() : null; mOneCategoryUsed = variantCategories != null && variantCategories.Count == 1; foreach (DataRow dr in dsCategories.Tables[0].Rows) { try { // Load control for selection product options ProductOptionSelector selector = (ProductOptionSelector)LoadUserControl("~/CMSModules/Ecommerce/Controls/ProductOptions/ProductOptionSelector.ascx"); // Add control to the collection var categoryID = ValidationHelper.GetInteger(dr["CategoryID"], 0); selector.ID = "opt" + categoryID; // Init selector selector.LocalShoppingCartObj = ShoppingCart; selector.IsLiveSite = false; selector.CssClassFade = "text-muted"; selector.CssClassNormal = "normal"; selector.SKUID = SKUID; selector.OptionCategory = new OptionCategoryInfo(dr); // If one category is used, fix the one selector with options to use only options which are not in disabled variants if (mOneCategoryUsed && variantCategories.Contains(categoryID)) { var disabled = from variant in Variants where !variant.Variant.SKUEnabled from productAttributes in variant.ProductAttributes select productAttributes.SKUID; var disabledList = disabled.ToList(); selector.ProductOptionsInDisabledVariants = disabledList.Any() ? disabledList : null; } // Load all product options foreach (DictionaryEntry entry in selector.ProductOptions) { mProductOptions[entry.Key] = entry.Value; } var lc = selector.SelectionControl as ListControl; if (lc != null) { // Add Index change handler lc.AutoPostBack = true; } pnlSelectors.Controls.Add(selector); } catch { } } } }