public Task <RuleOptionsResult> GetOptionsAsync(RuleOptionsContext context) { var result = new RuleOptionsResult(); if (context.DataSource == KnownRuleOptionDataSourceNames.PaymentMethod) { // TODO: (mg) (core) Complete IPaymentMethodRuleOptionsProvider (IPaymentMethod required). //var options = await _providerManager.Value.GetAllProviders<IPaymentMethod>() // .Select(x => x.Metadata) // .SelectAsync(async x => new RuleValueSelectListOption // { // Value = x.SystemName, // Text = await GetLocalized(x, "FriendlyName") ?? x.FriendlyName.NullEmpty() ?? x.SystemName, // Hint = x.SystemName // }) // .ToListAsync(); //result.AddOptions(context, options.OrderBy(x => x.Text).ToList(); } else { return(null); } return(Task.FromResult(result)); }
public async Task <RuleOptionsResult> GetOptionsAsync(RuleOptionsContext context) { var result = new RuleOptionsResult(); if (context.DataSource == KnownRuleOptionDataSourceNames.VariantValue) { if (context.Reason == RuleOptionsRequestReason.SelectedDisplayNames) { var variants = await _db.ProductVariantAttributeValues.GetManyAsync(context.Value.ToIntArray()); result.AddOptions(context, variants.Select(x => new RuleValueSelectListOption { Value = x.Id.ToString(), Text = x.GetLocalized(y => y.Name, context.Language, true, false) })); } else if (context.Descriptor.Metadata.TryGetValue("ParentId", out var objParentId)) { var pIndex = -1; var existingValues = new HashSet <string>(StringComparer.InvariantCultureIgnoreCase); var options = new List <RuleValueSelectListOption>(); var query = _db.ProductVariantAttributeValues .AsNoTracking() .Where(x => x.ProductVariantAttribute.ProductAttributeId == (int)objParentId && x.ProductVariantAttribute.ProductAttribute.AllowFiltering && x.ValueTypeId == (int)ProductVariantAttributeValueType.Simple) .ApplyValueFilter(null, true); while (true) { var variants = await PagedList.Create(query, ++pIndex, 1000).LoadAsync(); foreach (var variant in variants) { var name = variant.GetLocalized(x => x.Name, context.Language, true, false); if (!existingValues.Contains(name)) { existingValues.Add(name); options.Add(new RuleValueSelectListOption { Value = variant.Id.ToString(), Text = name }); } } if (!variants.HasNextPage) { break; } } result.AddOptions(context, options); } } else { return(null); } return(result); }
public async Task <RuleOptionsResult> GetOptionsAsync(RuleOptionsContext context) { var result = new RuleOptionsResult(); if (context.DataSource == KnownRuleOptionDataSourceNames.Product) { if (context.Reason == RuleOptionsRequestReason.SelectedDisplayNames) { var products = await _db.Products.GetManyAsync(context.Value.ToIntArray()); result.AddOptions(context, products.Select(x => new RuleValueSelectListOption { Value = x.Id.ToString(), Text = x.GetLocalized(y => y.Name, context.Language, true, false), Hint = x.Sku })); } else { var options = await SearchProducts(result, context.SearchTerm, context.PageIndex *context.PageSize, context.PageSize); result.AddOptions(context, options); result.IsPaged = true; } } else { return(null); } return(result); }
private async Task <string> GetLocalized(RuleOptionsContext context, ProviderMetadata metadata, string propertyName) { var resourceName = metadata.ResourceKeyPattern.FormatInvariant(metadata.SystemName, propertyName); var resource = await _localizationService.GetResourceAsync(resourceName, context.Language.Id, false, string.Empty, true); return(resource.NullEmpty()); }
public async Task <RuleOptionsResult> GetOptionsAsync(RuleOptionsContext context) { var result = new RuleOptionsResult(); if (context.DataSource == KnownRuleOptionDataSourceNames.ShippingRateComputationMethod) { var options = await _providerManager.GetAllProviders <IShippingRateComputationMethod>() .Select(x => x.Metadata) .SelectAsync(async x => new RuleValueSelectListOption { Value = x.SystemName, Text = await GetLocalized(context, x, "FriendlyName") ?? x.FriendlyName.NullEmpty() ?? x.SystemName, Hint = x.SystemName }) .ToListAsync(); result.AddOptions(context, options.OrderBy(x => x.Text)); } else { return(null); } return(result); }
public async Task <RuleOptionsResult> GetOptionsAsync(RuleOptionsContext context) { var result = new RuleOptionsResult(); switch (context.DataSource) { case KnownRuleOptionDataSourceNames.Country: var countries = await _db.Countries .AsNoTracking() .ApplyStandardFilter(true) .ToListAsync(); result.AddOptions(context, countries.Select(x => new RuleValueSelectListOption { Value = context.OptionById ? x.Id.ToString() : x.TwoLetterIsoCode, Text = x.GetLocalized(y => y.Name, context.Language, true, false) })); break; case KnownRuleOptionDataSourceNames.Currency: var currencies = await _db.Currencies .AsNoTracking() .ApplyStandardFilter(true) .ToListAsync(); result.AddOptions(context, currencies.Select(x => new RuleValueSelectListOption { Value = context.OptionById ? x.Id.ToString() : x.CurrencyCode, Text = x.GetLocalized(y => y.Name, context.Language, true, false) })); break; case KnownRuleOptionDataSourceNames.DeliveryTime: var deliveryTimes = await _db.DeliveryTimes .AsNoTracking() .OrderBy(x => x.DisplayOrder) .ToListAsync(); result.AddOptions(context, deliveryTimes.Select(x => new RuleValueSelectListOption { Value = x.Id.ToString(), Text = x.GetLocalized(y => y.Name, context.Language, true, false) })); break; default: return(null); } return(result); }
public async Task <RuleOptionsResult> GetOptionsAsync(RuleOptionsContext context) { var result = new RuleOptionsResult(); if (context.DataSource == KnownRuleOptionDataSourceNames.Category) { if (context.Reason == RuleOptionsRequestReason.SelectedDisplayNames) { var categories = await _db.Categories.GetManyAsync(context.Value.ToIntArray()); var options = await categories .SelectAsync(async x => new RuleValueSelectListOption { Value = x.Id.ToString(), Text = (await _categoryService.GetCategoryPathAsync(x, context.Language.Id)).NullEmpty() ?? x.Name }) .ToListAsync(); result.AddOptions(context, options); } else { var categories = await _categoryService.GetCategoryTreeAsync(0, true); var options = await categories .Flatten(false) .SelectAsync(async x => new RuleValueSelectListOption { Value = x.Id.ToString(), Text = (await _categoryService.GetCategoryPathAsync(x, context.Language.Id)).NullEmpty() ?? x.Name }) .ToListAsync(); result.AddOptions(context, options); } } else { return(null); } return(result); }
public async Task <RuleOptionsResult> GetOptionsAsync(RuleOptionsContext context) { var result = new RuleOptionsResult(); if (context.DataSource == KnownRuleOptionDataSourceNames.AttributeOption) { if (context.Reason == RuleOptionsRequestReason.SelectedDisplayNames) { var attributes = await _db.SpecificationAttributeOptions.GetManyAsync(context.Value.ToIntArray()); result.AddOptions(context, attributes.Select(x => new RuleValueSelectListOption { Value = x.Id.ToString(), Text = x.GetLocalized(y => y.Name, context.Language, true, false) })); } else if (context.Descriptor.Metadata.TryGetValue("ParentId", out var objParentId)) { var attributes = await _db.SpecificationAttributeOptions .AsNoTracking() .Where(x => x.SpecificationAttributeId == (int)objParentId) .OrderBy(x => x.DisplayOrder) .ToPagedList(context.PageIndex, context.PageSize) .LoadAsync(); result.IsPaged = true; result.HasMoreData = attributes.HasNextPage; result.AddOptions(context, attributes.AsQueryable().Select(x => new RuleValueSelectListOption { Value = x.Id.ToString(), Text = x.GetLocalized(y => y.Name, context.Language, true, false, false) })); } } else { return(null); } return(result); }
public async Task <RuleOptionsResult> GetOptionsAsync(RuleOptionsContext context) { var result = new RuleOptionsResult(); if (context.DataSource == KnownRuleOptionDataSourceNames.CartRule || context.DataSource == KnownRuleOptionDataSourceNames.TargetGroup) { if (context.Reason == RuleOptionsRequestReason.SelectedDisplayNames) { var ruleSets = await _db.RuleSets.GetManyAsync(context.Value.ToIntArray()); result.AddOptions(context, ruleSets.Select(x => new RuleValueSelectListOption { Value = x.Id.ToString(), Text = x.Name })); } else { var ruleSets = await _db.RuleSets .AsNoTracking() .ApplyStandardFilter(context.Descriptor.Scope, false, true) .ToPagedList(context.PageIndex, context.PageSize) .LoadAsync(); result.IsPaged = true; result.HasMoreData = ruleSets.HasNextPage; result.AddOptions(context, ruleSets.Select(x => new RuleValueSelectListOption { Value = x.Id.ToString(), Text = x.Name })); } } else { return(null); } return(result); }
public async Task <RuleOptionsResult> GetOptionsAsync(RuleOptionsContext context) { var result = new RuleOptionsResult(); if (context.DataSource == KnownRuleOptionDataSourceNames.ProductTag) { var productTags = await _db.ProductTags.AsNoTracking().ToListAsync(); result.AddOptions(context, productTags .Select(x => new RuleValueSelectListOption { Value = x.Id.ToString(), Text = x.GetLocalized(y => y.Name, context.Language, true, false) }) .OrderBy(x => x.Text)); } else { return(null); } return(result); }
public async Task <RuleOptionsResult> GetOptionsAsync(RuleOptionsContext context) { var result = new RuleOptionsResult(); if (context.DataSource == KnownRuleOptionDataSourceNames.Language) { var languages = await _db.Languages .AsNoTracking() .ApplyStandardFilter(true) .ToListAsync(); result.AddOptions(context, languages.Select(x => new RuleValueSelectListOption { Value = x.Id.ToString(), Text = GetCultureDisplayName(x) ?? x.Name })); } else { return(null); } return(result); }
public async Task <RuleOptionsResult> GetOptionsAsync(RuleOptionsContext context) { var result = new RuleOptionsResult(); if (context.DataSource == KnownRuleOptionDataSourceNames.ShippingMethod) { var shippingMethods = await _db.ShippingMethods .AsNoTracking() .OrderBy(x => x.DisplayOrder) .ToListAsync(); result.AddOptions(context, shippingMethods.Select(x => new RuleValueSelectListOption { Value = context.OptionById ? x.Id.ToString() : x.Name, Text = context.OptionById ? x.GetLocalized(y => y.Name, context.Language, true, false) : x.Name })); } else { return(null); } return(result); }
public async Task <RuleOptionsResult> GetOptionsAsync(RuleOptionsContext context) { var result = new RuleOptionsResult(); if (context.DataSource == KnownRuleOptionDataSourceNames.CustomerRole) { var customerRoles = await _db.CustomerRoles .AsNoTracking() .OrderBy(x => x.Name) .ToListAsync(); result.AddOptions(context, customerRoles.Select(x => new RuleValueSelectListOption { Value = x.Id.ToString(), Text = x.Name })); } else { return(null); } return(result); }
public async Task <RuleOptionsResult> GetOptionsAsync(RuleOptionsContext context) { var result = new RuleOptionsResult(); if (context.DataSource == KnownRuleOptionDataSourceNames.Manufacturer) { var manufacturers = await _db.Manufacturers .AsNoTracking() .ApplyStandardFilter(true) .ToListAsync(); result.AddOptions(context, manufacturers.Select(x => new RuleValueSelectListOption { Value = x.Id.ToString(), Text = x.GetLocalized(y => y.Name, context.Language, true, false) })); } else { return(null); } return(result); }
public RuleOptionsContext ruleOptions() { RuleOptionsContext _localctx = new RuleOptionsContext(Context, State); EnterRule(_localctx, 12, RULE_ruleOptions); try { EnterOuterAlt(_localctx, 1); { State = 86; byteOption(); } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { ExitRule(); } return _localctx; }
public override void EnterParseRule([NotNull] BinShredParser.ParseRuleContext context) { string regionName = context.label().GetText(); parseActions[regionName] = new List <ParseAction>(); processingActions.Push(regionName); if (String.IsNullOrEmpty(startAction)) { startAction = regionName; } foreach (RuleBodyContext body in context.ruleBody()) { // This is a rule that describes additional actions to be taken from something // already parsed // "(additional properties identified by propertyName from lookupTableName)" if (body.ADDITIONAL() != null) { string propertyName = body.propertyName().GetText(); string lookupTableName = body.lookupTableName().GetText(); ProcessAdditionalProperties(propertyName, lookupTableName, regionName); continue; } // Get the rule's label and descriptive comment (/** */) string ruleLabel = body.label().GetText(); string ruleComment = null; ITerminalNode docComment = body.DOC_COMMENT(); if (docComment != null) { ruleComment = docComment.GetText(); ruleComment = ruleComment.Substring(3, ruleComment.Length - 5).Trim(); } // Get the rule's options RuleOptionsContext options = body.ruleOptions(); if (options != null) { // This is a rule with actual options (i.e.: "(4 bytes as int32)") ByteOptionContext byteOptions = options.byteOption(); int bytes = 0; String byteLabel = String.Empty; if (byteOptions.sizeReference().INT() != null) { bytes = Int32.Parse(byteOptions.sizeReference().INT().GetText()); } else { byteLabel = byteOptions.sizeReference().label().GetText(); } // This is a rule that extracts bytes in some format ProcessByteExtraction(regionName, ruleLabel, ruleComment, byteOptions, bytes, byteLabel); } else { // This is a rule with a reference to another rule if (body.ITEMS() != null) { // This is a rule which creates several records of a given record type // (i.e.: (12 items) or (byteCount items) int items = 0; string itemLabel = String.Empty; if (body.sizeReference().INT() != null) { items = Int32.Parse(body.sizeReference().INT().GetText()); } else { itemLabel = body.sizeReference().label().GetText(); } ProcessCountedRule(regionName, ruleLabel, ruleComment, items, itemLabel); } else { this.parseActions[regionName].Add( new ParseAction((content, contentPosition) => { OrderedDictionary currentResult = new OrderedDictionary(StringComparer.OrdinalIgnoreCase); results.Peek().Add(ruleLabel, currentResult); RunRule(ruleComment, ruleLabel, currentResult); return(0); } )); } } } }