public void RemoveExcludedRows(CsvFile products) { if (MatchingRowIds == null || MatchingRowIds.Count == 0) { return; } foreach (CsvRow row in products.Rows.Where(r => r.ExcludeMe)) { IFilterValue value = row.GetColumn(Sku); if (value == null) { value = row.GetColumn(Sku.ToLower()); } if (value == null) { } else { if (MatchingRowIds.Contains(value.Value) == true) { MatchingRowIds.Remove(value.Value); } } } }
public void CollectionTags(CsvRow row, StringBuilder tags) { IFilterValue collectionColumn = row.GetColumn("categories"); IFilterValue tagsColumns = row.GetColumn("tags"); String categories = collectionColumn.Value.Replace("\"", ""); foreach (String category in categories.Split('>')) { if (category == ">" || tags.ToString().IndexOf(category, StringComparison.Ordinal) != -1) { continue; } if (tags.Length > 0) { tags.Append(","); } tags.Append(category); } string reformatedCollection = tags.ToString().Replace(",", " > ").Trim(); string titleCasedCollection = _myTi.ToTitleCase(reformatedCollection); row.SetColumn("collection", titleCasedCollection); }
public bool Equals(IFilterValue other) { if (!(other is FontSizeValue)) { return(false); } return((other as FontSizeValue).Value == this.Value); }
public bool Equals(IFilterValue other) { if (other is ColorValue) { return((other as ColorValue).ColorValueList.SequenceEqual(this.ColorValueList)); } return(false); }
public bool?HasBeenFiltered(IFilterRow row) { if (ShouldFilter == false) { return(null); } IFilterValue handle = row.GetColumn("Handle"); return(MatchingRowIds.Contains(handle?.Value)); }
public IFilterValue GetColumn(String headerName) { IFilterValue fv = ColumnValues.Where(cv => cv.Header.IndexOf(headerName) != -1).FirstOrDefault(); if (fv == null && ColumnValues.Where(cv => cv.Header == headerName).Count() == 1) { InvalidRow = true; } return(fv); }
public void RemoveExcludedRows(CsvFile products) { foreach (CsvRow row in products.Rows.Where(r => r.ExcludeMe)) { IFilterValue value = row.GetColumn(Sku); if (MatchingRowIds.Contains(value.Value) == true) { MatchingRowIds.Remove(value.Value); } } }
public void Init(IFilterValue <TProperty?> value) { _filterValue = null; if (value == null) { return; } _initFilterValue = value; }
public bool SetColumn(String columnName, String columnValue) { bool result = false; IFilterValue fv = DoMatchHeader(columnName); //CsvColumn column = ColumnValues.Where(cv => cv.Header.IndexOf(columnName)!=-1).FirstOrDefault(); if (fv != null) { fv.UpdateValue(columnValue); result = true; } return(result); }
public void UpdateCollection(String newCollection) { IFilterValue column = GetColumn(CollectionName); if (column == null) { InvalidRow = true; } else { column.UpdateValue(newCollection); } }
private IFilterValue <TProperty?> GetFilterValue() { if (_filterValue != null) { return(_filterValue); } var value = (_initFilterValue ?? _defaultFilterValue) ?? _defaultLazyFilterValue?.Value; _filterValue = value; return(value); }
public bool ApplyFilter(IFilterRow row) { bool result = false; IFilterValue weightString = row.GetColumn(Weight); IFilterValue lengthString = row.GetColumn(Length); IFilterValue widthString = row.GetColumn(Width); IFilterValue heightString = row.GetColumn(Height); IFilterValue handle = row.GetColumn("Handle"); bool we = decimal.TryParse(weightString?.Value, out decimal weight); bool le = decimal.TryParse(lengthString?.Value, out decimal length); bool wi = decimal.TryParse(widthString?.Value, out decimal width); bool he = decimal.TryParse(heightString?.Value, out decimal height); if (le && wi && he) { decimal cubicVolumeLength = Math.Round(length); decimal cubicVolumeWidth = Math.Round(width); decimal cubicVolumeHeight = Math.Round(height); decimal dimWeight = cubicVolumeLength * cubicVolumeWidth * cubicVolumeHeight / DimWeightDivisor; if (dimWeight > weight) { weight = dimWeight; } } if (we) { result = (weight < 1); if (result) { row.Handle = handle; row.UnderOnePound = true; MatchingRowIds.Add(handle.Value); } else { row.Handle = handle; row.OverOnePound = true; Console.WriteLine($"Product with Handle={handle?.Value} and weight={weight} exceeds threshold=0.23"); } } return(result); }
private IFilterValue <TProperty> GetFilterValue() { if (_filterValue != null) { return(_filterValue); } var value = (_initFilterValue ?? _defaultFilterValue) ?? _defaultLazyFilterValue?.Value; value = value ?? (new FilterValue <TProperty> { ConditionKey = _conditions.Keys.FirstOrDefault() }); _filterValue = value; return(value); }
public void ProcessProductAttributeTags(CsvRow row, StringBuilder tags) { if (row.Under023CubicVolume) { tags.Append(",Under023CubicVolume"); } else { tags.Append(",Over023CubicVolume"); } if (row.UnderOnePound) { tags.Append(",UnderOnePound"); } else { tags.Append(",OverOnePound"); } if (row.FreeShipping) { tags.Append(",FreeShipping"); } else { tags.Append(",PaidShipping"); } IFilterValue leadTimeValue = row.GetColumn("lead-time"); if (int.TryParse(leadTimeValue?.Value.ToString(), out int leadTime)) { tags.Append(",LeadTime" + leadTime.ToString()); } IFilterValue storageValue = row.GetColumn("storage"); if (storageValue != null && String.IsNullOrWhiteSpace(storageValue.Value) == false && tags.ToString().IndexOf(storageValue.Value) == -1) { String val = storageValue?.Value.Replace(" ", "").Replace("\"", ""); tags.Append($",{val}"); } }
public override string ToString() { StringBuilder row = new StringBuilder(); int colIdx = 0; foreach (CsvColumn value in ColumnValues) { if (value.Header == Tags) { IFilterValue collection = GetColumn(CollectionName); IList <String> updatedCategories = CsvRow.UpdateCategories(collection.Value); String updatedCollection = CsvRow.GetUpdatedCollection(updatedCategories); collection.UpdateValue(updatedCollection); StringBuilder tags = new StringBuilder(); foreach (String tag in GetTags()) { if (tags.Length == 0) { tags.Append(tag); } else { tags.Append(',').Append(tag); } } value.UpdateValue($"\"{tags.ToString()}\""); } if (colIdx == 0) { row.Append(value.Value); } else { row.Append(',').Append(value.Value); } colIdx++; } return(row.ToString()); }
public bool?HasBeenFiltered(IFilterRow row) { if (row == null) { return(false); } IFilterValue upc = row.GetColumn(VariantBarcode); if (upc == null) { return(false); } row.RecommendedAmazonUk = RecommendedAmazonUkRowIds.Contains(upc.Value); row.RecommendedAmazonUs = RecommendedAmazonUsRowIds.Contains(upc.Value); row.RecommendedeBayUs = RecommendedeBayUsRowIds.Contains(upc.Value); row.Recommended = RecommendedRowIds.Contains(upc.Value); return(row.Recommended); }
public bool ApplyFilter(IFilterRow row) { bool result = false; IFilterValue recommendedAmazonUs = row.GetColumn(RecommendedAmazonUs); IFilterValue recommendedAmazonUk = row.GetColumn(RecommendedAmazonUk); IFilterValue recommendedeBayUs = row.GetColumn(RecommendedeBayUs); IFilterValue recommended = row.GetColumn(Recommended); IFilterValue upc = row.GetColumn(OriginalSearchTerm); if (upc == null || recommended == null) { return(result); } double upcNumber = double.Parse(upc.Value, CultureInfo.InvariantCulture); if (String.IsNullOrEmpty(recommended.Value) == false) { if (recommended.Value.Trim().ToLower() == "yes") { RecommendedRowIds.Add(upc.Value); if (recommendedAmazonUk.Value.Trim().ToLower() == "yes") { RecommendedAmazonUkRowIds.Add(upc.Value); } if (recommendedAmazonUs.Value.Trim().ToLower() == "yes") { RecommendedAmazonUsRowIds.Add(upc.Value); } if (recommendedeBayUs.Value.Trim().ToLower() == "yes") { RecommendedeBayUsRowIds.Add(upc.Value); } result = true; } } return(result); }
public bool ApplyFilter(IFilterRow row) { bool result = false; IFilterValue inventoryString = row.GetColumn(Inventory); IFilterValue handle = row.Handle ?? row.GetColumn("Handle"); if (handle == null || inventoryString == null) { return(result); } int inventory = -1; bool i = int.TryParse(inventoryString.Value, out inventory); if (i && String.IsNullOrEmpty(handle.Value) == false) { if (MinimumInventoryThreshold > 0 && MaximumInventoryThreshold > MinimumInventoryThreshold) { result = inventory >= MinimumInventoryThreshold && inventory <= MaximumInventoryThreshold; } else if (MinimumInventoryThreshold == MaximumInventoryThreshold) { result = inventory > MinimumInventoryThreshold; } if (result) { row.Handle = handle; MatchingRowIds.Add(handle.Value); } else { row.Handle = handle; Console.WriteLine($"Product with Handle={handle} and no inventory."); } } return(result); }
public void RemoveExcludedRows(CsvFile products) { foreach (CsvRow row in products.Rows.Where(r => r.ExcludeMe)) { IFilterValue value = row.GetColumn(Upc); if (RecommendedRowIds.Contains(value.Value) == true) { RecommendedRowIds.Remove(value.Value); } if (RecommendedAmazonUsRowIds.Contains(value.Value) == true) { RecommendedAmazonUsRowIds.Remove(value.Value); } if (RecommendedAmazonUkRowIds.Contains(value.Value) == true) { RecommendedAmazonUkRowIds.Remove(value.Value); } if (RecommendedeBayUsRowIds.Contains(value.Value) == true) { RecommendedeBayUsRowIds.Remove(value.Value); } } }
private KeyValuePair <string, IReferenceTypeCondition <TProperty> > GetCondition(IFilterValue filterValue) { return(_conditions.FirstOrDefault(x => x.Key == filterValue.ConditionKey)); }
public void SetDefaultValue(IFilterValue <TProperty?> filterValue) { _filterValue = null; _defaultFilterValue = filterValue; }
public void SetDefaultValue(Func <IFilterValue <TProperty?> > filterValue) { _filterValue = null; _defaultLazyFilterValue = new Lazy <IFilterValue <TProperty?> >(filterValue); }
void IFilter.Init(IFilterValue value) { Init(value as IFilterValue <TProperty?>); }
public bool Equals(IFilterValue other) { return(this.BoolValue == (other as BooleanValue).BoolValue); }
public bool Equals(IFilterValue otherObj) { var other = otherObj as SoundValue; return(this.SoundID == other.SoundID && this.Volume == other.Volume); }
public bool Equals(IFilterValue other) { return(this.ValueList.SequenceEqual((other as ListValue).ValueList)); }
public bool Equals(IFilterValue otherVal) { var other = otherVal as OperatorValue; return(this.Value == other.Value && this.Operator == other.Operator); }
public bool ApplyFilter(IFilterRow row) { bool result = false; if (row != null) { String volumeAsString = row.GetColumn("cubic_volume (in.)").Value; String weightAsString = row.GetColumn(Weight).Value; String priceAsString = row.GetColumn(Price).Value; String msrpAsString = row.GetColumn(Msrp).Value; String mapAsString = row.GetColumn(Map).Value; String sku = row.GetColumn(Sku).Value; WeightCubicVolumeInformation wi = null; decimal.TryParse(msrpAsString, out decimal msrp); decimal.TryParse(weightAsString, out decimal weight); decimal.TryParse(volumeAsString, out decimal volume); decimal.TryParse(mapAsString, out decimal map); if (String.IsNullOrWhiteSpace(weightAsString) == false && String.IsNullOrWhiteSpace(volumeAsString) == false) { if (decimal.TryParse(weightAsString, out decimal weightAsLBS) && decimal.TryParse(volumeAsString, out decimal volumeAsCubicFeet)) { decimal gramConversionFactor = (decimal)453.59237; weight = gramConversionFactor * weightAsLBS; wi = new WeightCubicVolumeInformation(weight, weightAsLBS, volumeAsCubicFeet); } } decimal.TryParse(priceAsString, out decimal price); decimal costPerItem = price; price = (price * (decimal)ProfitMargin); if (price > (decimal)3.0) { price = (Math.Floor(price) + (decimal)0.47); } if (price < costPerItem) { price = (costPerItem * (decimal)ProfitMargin); } if (String.IsNullOrWhiteSpace(mapAsString) == false) { if (price < map) { price = Math.Floor(map) + (decimal)0.49; } } if (msrp > 0) { if (price > msrp) { price = msrp; } } else { msrp = price + (price * (decimal)0.20); } IFilterValue storage = row.GetColumn("storage"); if (storage != null && string.IsNullOrWhiteSpace(storage.Value) == false && (storage.Value == Refrigerated || storage.Value == Frozen)) { price += (decimal)ShippingSurcharge; } decimal volumeShippingCost = 0; decimal weightShippingCost = 0; if (wi != null && ShouldAddShipping) { (volumeShippingCost, weightShippingCost) = ShippingCost.Get(wi); if (volumeShippingCost < weightShippingCost) { price += weightShippingCost; } else { price += volumeShippingCost; } } PriceInformation pi = new PriceInformation(msrp.ToString("C2"), msrp.ToString("C2"), costPerItem.ToString("C2"), price.ToString("C2")); MatchingRowIds.Add(row.GetColumn(Sku).Value, pi); result = true; } return(result); }
public IValueTypeFilterConfiguration <TModel, TProperty> SetDefaultFilterValue(IFilterValue <TProperty?> filterValue) { _filter.SetDefaultValue(filterValue); return(this); }
public bool Equals(IFilterValue other) { return(other is VoidValue); }