public string[] Decode(GoodDataConnection connection, IEnumerable<string> filterUris) { var expressions = filterUris.Select(x => TryGetExpression(connection.MandatoryUserFilter, x)).ToArray(); var lookups = BuildReplacementDictionary(connection, expressions); for (int index = 0; index < expressions.Length; index++) { expressions[index] = Replace(lookups, expressions[index]); } return expressions; }
private static Dictionary<string, string> BuildReplacementDictionary(GoodDataConnection connection, IEnumerable<string> expressions) { var combinedExpresison = string.Join(" ", expressions.Where(x => !string.IsNullOrWhiteSpace(x))); var attributes = AttributeRegex .Matches(combinedExpresison) .Cast<object>() .Select(x => x.ToString()) .Distinct() .Select(x => TryGetAttribute(connection.Attribute, x)) .ToArray(); var usedElements = ElementRegex.Matches(combinedExpresison).Cast<object>().Select(x => x.ToString()).Distinct().ToArray(); var uriToReplacement = usedElements.ToDictionary(elem => elem); foreach (var attribute in attributes) { if (null != attribute) { uriToReplacement[string.Format("[{0}]", attribute.Attribute.Meta.Uri)] = string.Format("[{0}]", attribute.Attribute.Meta.Title); try { var elements = connection.Attribute.GetElements(attribute.Attribute.Content.DisplayForms[0].Links.Elements).AssertSuccess().AttributeElements.Elements; if (null != elements) { foreach (var elemInfo in elements) { if (uriToReplacement.ContainsKey(elemInfo.Uri)) { uriToReplacement[elemInfo.Uri] = elemInfo.Title; } } } } catch (Exception e) { Logger.Warn(e); } } } return uriToReplacement; }
public string Decode(GoodDataConnection connection, string filterUri) { return Decode(connection, new[] {filterUri})[0]; }