Exemplo n.º 1
0
 public void TestInitialize()
 {
     _definitionProvider = new TestDefinitionProvider();
     _dataProvider       = new TestDataProvider();
     _generator          = new FragmentGenerators(_definitionProvider, _dataProvider);
     _macroVariables     = new TestMacroVariables();
 }
Exemplo n.º 2
0
        public void TestInitialize()
        {
            _definitionProvider = new TestDefinitionProvider();
            _dataProvider       = new TestDataProvider();
            _generator          = new FragmentGenerators(_definitionProvider, _dataProvider);
            _macroVariables     = new TestMacroVariables();
            var direction = new Direction(TestSynonyms.GetSynonyms());

            _renderer = new Basic10KRenderer(_macroVariables, _definitionProvider.Templates, direction);
        }
Exemplo n.º 3
0
        public static string ProcessMacros(IMacroVariables macroVariables, IClauseFragment fragment, string template)
        {
            if (string.IsNullOrEmpty(template) || fragment == null)
            {
                return("");
            }

            var result = template;
            var items  = Regex.Matches(template, @"\[([^]]*)\]");

            foreach (Match item in items)
            {
                var itemValue     = item.Value.ToUpper();
                var macroVariable = macroVariables.Get(itemValue);
                if (macroVariable != null)
                {
                    string macroValue = null;

                    if (!string.IsNullOrEmpty(macroVariable.Type))
                    {
                        if (macroVariable.Type == fragment.GetType().Name)
                        {
                            var fragmentData = fragment.Data;
                            var property     = fragmentData.GetType().GetProperty(macroVariable.Value);
                            if (property != null)
                            {
                                macroValue = property.GetValue(fragmentData)?.ToString();
                            }
                            else
                            {
                                property   = fragment.GetType().GetProperty(macroVariable.Value);
                                macroValue = property.GetValue(fragment)?.ToString();
                            }
                        }
                    }
                    else
                    {
                        macroValue = macroVariable.Value;
                    }

                    if (macroValue != null)
                    {
                        result = result.Replace(item.Value, macroValue);
                    }
                }
            }

            return(result);
        }
Exemplo n.º 4
0
        // EZSTOOD - write unit tests for this
        public TestMacroVariables()
        {
            MacroVariables = new MacroVariables();

            var macroList = new List <MacroVariable>()
            {
                new MacroVariable {
                    Name = "HOMES", Value = " homes"
                },
                new MacroVariable {
                    Name = "METRIC CODE", Value = "Code", Type = "MetricFragment"
                },
                new MacroVariable {
                    Name = "METRIC NAME", Value = "ShortName", Type = "MetricFragment"
                },
                new MacroVariable {
                    Name = "METRIC LONGNAME", Value = "LongName", Type = "MetricFragment"
                },
                new MacroVariable {
                    Name = "ACTUAL VALUE", Value = "CurrentValue", Type = "DataFragment"
                },
                new MacroVariable {
                    Name = "PREVIOUS VALUE", Value = "PreviousValue", Type = "DataFragment"
                },
                new MacroVariable {
                    Name = "PCT", Value = "PercentChange", Type = "DataFragment"
                },
                new MacroVariable {
                    Name = "DATA UNITS", Value = "Units", Type = "DataFragment"
                },
                new MacroVariable {
                    Name = "ACTUAL NAME", Value = "ShortName", Type = "VariableFragment"
                },
                new MacroVariable {
                    Name = "ACTUAL LONGNAME", Value = "LongName", Type = "VariableFragment"
                },
                new MacroVariable {
                    Name = "VAR UNITS", Value = "Units", Type = "VariableFragment"
                },
                new MacroVariable {
                    Name = "DIR", Value = ""
                }
            };

            MacroVariables.Add(macroList);
        }
Exemplo n.º 5
0
 public Basic10KRenderer(IMacroVariables macroVariable, Templates templates, IDirection direction)
 {
     _macroVariable = macroVariable;
     _direction     = direction;
     _templates     = templates ?? DefaultTemplates;
 }