Exemple #1
0
        static string parse(string template, IKeyValues values)
        {
            var matches = TemplateExpression.Matches(template);
            if (matches.Count == 0) return template;

            var lastIndex = 0;
            var builder = new StringBuilder();
            foreach (Match match in matches)
            {
                builder.Append(template.Substring(lastIndex, match.Index - lastIndex));

                var key = match.Groups[TemplateGroup].Value;
                if ((lastIndex == 0 || match.Index > lastIndex) && values.Has(key))
                {
                    builder.Append(values.Get(key));
                }
                else
                {
                    builder.Append("{{" + key + "}}"); // escape the missing key so that the while loop ContainsTemplate will terminate
                }

                lastIndex = match.Index + match.Length;
            }

            if (lastIndex < template.Length)
            {
                builder.Append(template.Substring(lastIndex, template.Length - lastIndex));
            }

            return builder.ToString();
        }
        public static string Parse(string template, IKeyValues values)
        {
            var matches = TemplateExpression.Matches(template);
            if (matches.Count == 0) return template;

            var lastIndex = 0;
            var builder = new StringBuilder();
            foreach (Match match in matches)
            {
                var key = match.Groups[TemplateGroup].Value;
                if ((lastIndex == 0 || match.Index > lastIndex) && values.ContainsKey(key))
                {
                    builder.Append(template.Substring(lastIndex, match.Index - lastIndex));
                    builder.Append(values.Get(key));
                }

                lastIndex = match.Index + match.Length;
            }

            if (lastIndex < template.Length)
            {
                builder.Append(template.Substring(lastIndex, template.Length - lastIndex));
            }

            return builder.ToString();
        }
        public static SettingsData For(IKeyValues values, string name = "Anonymous")
        {
            var source = new SettingsData(new Dictionary<string, object>(), name);
            values.ReadAll((key, value) => source[key] = value);

            return source;
        }
        static string parse(string template, IKeyValues values)
        {
            var matches = TemplateExpression.Matches(template);

            if (matches.Count == 0)
            {
                return(template);
            }

            var lastIndex = 0;
            var builder   = new StringBuilder();

            foreach (Match match in matches)
            {
                var key = match.Groups[TemplateGroup].Value;
                if ((lastIndex == 0 || match.Index > lastIndex) && values.ContainsKey(key))
                {
                    builder.Append(template.Substring(lastIndex, match.Index - lastIndex));
                    builder.Append(values.Get(key));
                }

                lastIndex = match.Index + match.Length;
            }

            if (lastIndex < template.Length)
            {
                builder.Append(template.Substring(lastIndex, template.Length - lastIndex));
            }

            return(builder.ToString());
        }
        public static SettingsData For(IKeyValues values, string name = "Anonymous")
        {
            var source = new SettingsData(new Dictionary <string, object>(), name);

            values.ReadAll((key, value) => source[key] = value);

            return(source);
        }
 public static string Parse(string template, IKeyValues values)
 {
     while (ContainsTemplates(template))
     {
         template = parse(template, values);
     }
     return(template);
 }
        public static string Parse(string template, IKeyValues values)
        {
            while (ContainsTemplates(template))
            {
                template = parse(template, values);
            }

            template = nowFlattenDoubleCurlies(template);
            return(template);
        }
        public static string Parse(string template, IKeyValues values)
        {
            while(ContainsTemplates(template))
            {
                template = parse(template, values);
            }

            template = nowFlattenDoubleCurlies(template);
            return template;
        }
        ///////////////////////////////////////////////////////////////////////////////////////////////////
        ////////////BUILD FROM IMMUTABLE OBJECT                 //////////////////////////////////////////////
        ///////////////////////////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Initializes a new instance of the <see cref="KeyValuesMutableImpl"/> class.
        /// </summary>
        /// <param name="immutable">
        /// The immutable. 
        /// </param>
        public KeyValuesMutableImpl(IKeyValues immutable)
            : base(SdmxStructureType.GetFromEnum(SdmxStructureEnumType.KeyValues))
        {
            this.values = new List<string>(immutable.Values);
            this.cascadeList = new List<string>();
            this.id = immutable.Id;
            
            foreach (string each in this.values)
            {
                if (immutable.IsCascadeValue(each))
                {
                    this.cascadeList.Add(each);
                }
            }

            if (immutable.TimeRange != null)
            {
                this.timeRange = new TimeRangeMutableCore(immutable.TimeRange);
            }
        }
Exemple #10
0
        static string parse(string template, IKeyValues values)
        {
            var matches = TemplateExpression.Matches(template);

            if (matches.Count == 0)
            {
                return(template);
            }

            var lastIndex = 0;
            var builder   = new StringBuilder();

            foreach (Match match in matches)
            {
                builder.Append(template.Substring(lastIndex, match.Index - lastIndex));

                var key = match.Groups[TemplateGroup].Value;
                if ((lastIndex == 0 || match.Index > lastIndex) && values.Has(key))
                {
                    builder.Append(values.Get(key));
                }
                else
                {
                    builder.Append("{{" + key + "}}"); // escape the missing key so that the while loop ContainsTemplate will terminate
                }

                lastIndex = match.Index + match.Length;
            }

            if (lastIndex < template.Length)
            {
                builder.Append(template.Substring(lastIndex, template.Length - lastIndex));
            }

            return(builder.ToString());
        }
 public SubstitutedRequestData(IRequestData inner, IKeyValues substitutions)
 {
     _inner = inner;
     _substitutions = substitutions;
 }
Exemple #12
0
 public static void ReadAll(this IKeyValues values, Action <string, string> callback)
 {
     values.GetKeys().ToList().Each(key => callback(key, values.Get(key)));
 }
 public static void AddValues(this IRequestData request, RequestDataSource source, IKeyValues values)
 {
     request.AddValues(source.ToString(), values);
 }
Exemple #14
0
 public static void AddValues(this IRequestData request, RequestDataSource source, IKeyValues values)
 {
     request.AddValues(source.ToString(), values);
 }
Exemple #15
0
 public void AddValues(string name, IKeyValues values)
 {
     _inner.AddValues(name, values);
 }
 public PrefixedKeyValues(string prefix, IKeyValues <T> inner)
 {
     _prefix = prefix;
     _inner  = inner;
 }
        public void AddValues(string name, IKeyValues values)
        {
            var source = new FlatValueSource(values, name);

            _sources.Add(source);
        }
Exemple #18
0
 public FlatValueSource(IKeyValues <T> values, string provenance = "Anonymous")
 {
     _provenance = provenance;
     _values     = values;
 }
 public void AddValues(string name, IKeyValues values)
 {
     _inner.AddValues(name, values);
 }
Exemple #20
0
 public SubstitutedRequestData(IRequestData inner, IKeyValues substitutions)
 {
     _inner         = inner;
     _substitutions = substitutions;
 }
Exemple #21
0
 public static string Parse(string template, IKeyValues values)
 {
     while(ContainsTemplates(template))
     {
         template = parse(template, values);
     }
     return template;
 }
 public void AddValues(string name, IKeyValues values)
 {
     var source = new FlatValueSource(values, name);
     _sources.Add(source);
 }
Exemple #23
0
        public bool ForValue(string key, Action <string, string> callback)
        {
            IKeyValues holder = findHolder(key);

            return(holder == null ? false : holder.ForValue(key, callback));
        }