Skip to content

Instantly share code, notes, and snippets.

@stdray
Created June 17, 2014 16:50
Show Gist options
  • Save stdray/fe74d3c56df4117a1a36 to your computer and use it in GitHub Desktop.
Save stdray/fe74d3c56df4117a1a36 to your computer and use it in GitHub Desktop.
internal static object FindRealSource(Model model, ValueSourceKey key, IList<IDimension> dimensionsPriority, params DataMapping[] mappings)
{
var orderedIds = key.Items.Select(x => new { index = dimensionsPriority.IndexOf(x.Dimension), Item = x })
.OrderBy(y => y.index).ToArray();
var toPermutate = orderedIds.Where(x => x.index >= 0).Select(x => x.Item);
var excludedIds = orderedIds.Where(x => x.index < 0).Select(x => x.Item);
var parentChains = toPermutate.Select(x => GetChainToParent(x).ToArray()).ToList();
var order = PermutationsMany<DimensionItem>(parentChains);
foreach (var item in order)
{
var parentKey = new ValueSourceKey(item.Union(excludedIds).ToArray());
object res;
if (CalculatedValuesCache.IsOn && CalculatedValuesCache.TryGetValue(parentKey, out res))
{
return res;
}
if (model.TryGetRealValueContainer(parentKey, out res))
{
CalculatedValuesCache.AddIFCachingNow(parentKey, res);
return res;
}
foreach (var mapping in mappings)
{
ValueSourceKey sourceKey = null;
if (mapping.TryGetMapping(parentKey, out sourceKey))
{
var value = mapping.Source.GetValue(sourceKey);
CalculatedValuesCache.AddIFCachingNow(parentKey, value);
return value;
}
}
}
return null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment