public double?GetFillRate(TaxonomyInfo taxonomy, Attribute attribute, Filter filter) { var fillRateObject = FillRates.FirstOrDefault(fr => fr.Taxonomy.Equals(taxonomy)); if (fillRateObject == null) { fillRateObject = new FillRate(taxonomy, null, null, FillRate.DataState.Active, DateTime.Now); FillRates.Add(fillRateObject); if (UseBackgroundWorker) { EnqueWork(fillRateObject, attribute, filter); return(double.MinValue); } } double?fillRateValue = fillRateObject.TryGetFillRate(attribute, filter); if (fillRateValue == null) { if (UseBackgroundWorker) { EnqueWork(fillRateObject, attribute, filter); return(double.MinValue); } fillRateValue = fillRateObject.FetchFillRate(attribute, filter); } if (double.IsNaN((double)fillRateValue)) { return(null); } //return string.Format("{0:0.00}", fillRateValue); return(Math.Round((double)fillRateValue, 2)); }
private void EnqueWork(FillRate fillRate, Attribute attribute, Filter filter) { lock (CalculateFillRateQueue) { CalculateFillRateQueue.Enqueue(new FillRateWorkUnit(fillRate, attribute, filter)); if (CalculateFillRateQueue.Count == 1) { Monitor.PulseAll(CalculateFillRateQueue); } } }
public FillRateWorkUnit(FillRate fillRate, Attribute attribute, Filter filter) { FillRateUnit = fillRate; AttributeUnit = attribute; FilterUnit = filter; }