示例#1
0
        public void TestConstantDeferredConfig()
        {
            string variableName = "myConstant";
            string value        = "1048576";
            Dictionary <string, JToken> jsonParameters = new Dictionary <string, JToken>();

            jsonParameters.Add("value", value);
            GeneratedSymbolDeferredMacroConfig deferredConfig = new GeneratedSymbolDeferredMacroConfig("ConstantMacro", null, variableName, jsonParameters);

            IVariableCollection    variables  = new VariableCollection();
            IRunnableProjectConfig config     = A.Fake <IRunnableProjectConfig>();
            IParameterSet          parameters = new ParameterSet(config);
            ParameterSetter        setter     = MacroTestHelpers.TestParameterSetter(_engineEnvironmentSettings, parameters);

            ConstantMacro macro      = new ConstantMacro();
            IMacroConfig  realConfig = macro.CreateConfig(_engineEnvironmentSettings, deferredConfig);

            macro.EvaluateConfig(_engineEnvironmentSettings, variables, realConfig, parameters, setter);
            ITemplateParameter constParameter;

            Assert.True(parameters.TryGetParameterDefinition(variableName, out constParameter));
            string constParamValue = (parameters.ResolvedValues[constParameter]).ToString();

            Assert.Equal(constParamValue, value);
        }
示例#2
0
        private void btnSetValue_Click(object sender, EventArgs e)
        {
            if (lstParameters.SelectedIndices.Count != 1)
            {
                return;
            }
            ParameterExpression p = (ParameterExpression)lstParameters.SelectedItems[0].Tag;

            //Check if the parameter is a base type if not we need another form.

            if (p.Type.IsPrimitive)
            {
                ParameterSetter setter = new ParameterSetter(p);
                if (setter.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    lstParameters.SelectedItems[0].SubItems[1].Tag  = setter.SelectedValue;
                    lstParameters.SelectedItems[0].SubItems[1].Text = setter.SelectedValue.ToString();
                }
            }
            else
            {
                Object obj = lstParameters.SelectedItems[0].SubItems[1].Tag ?? Activator.CreateInstance(p.Type);
                ParameterSetterNotBaseType setter = new ParameterSetterNotBaseType(obj);
                if (setter.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    lstParameters.SelectedItems[0].SubItems[1].Tag  = setter.SelectedValue;
                    lstParameters.SelectedItems[0].SubItems[1].Text = setter.SelectedValue.ToString();
                }
            }
        }
示例#3
0
        public void EvaluateNowDeferredConfig()
        {
            string variableName = "nowString";
            string format       = "";
            bool   utc          = false;
            Dictionary <string, JToken> jsonParameters = new Dictionary <string, JToken>();

            jsonParameters.Add("format", format);
            jsonParameters.Add("utc", utc);
            GeneratedSymbolDeferredMacroConfig deferredConfig = new GeneratedSymbolDeferredMacroConfig("NowMacro", variableName, jsonParameters);


            IVariableCollection    variables  = new VariableCollection();
            IRunnableProjectConfig config     = new SimpleConfigModel();
            IParameterSet          parameters = new ParameterSet(config);
            ParameterSetter        setter     = MacroTestHelpers.TestParameterSetter(EngineEnvironmentSettings, parameters);

            NowMacro     macro      = new NowMacro();
            IMacroConfig realConfig = macro.CreateConfig(EngineEnvironmentSettings, deferredConfig);

            macro.EvaluateConfig(EngineEnvironmentSettings, variables, realConfig, parameters, setter);
            ITemplateParameter resultParam;

            Assert.True(parameters.TryGetParameterDefinition(variableName, out resultParam));
            string   macroNowString = (string)parameters.ResolvedValues[resultParam];
            DateTime macroNowTime   = Convert.ToDateTime(macroNowString);

            TimeSpan difference = macroNowTime.Subtract(DateTime.Now);

            // 10 seconds is quite a lot of wiggle room, but should be fine, and safe.
            Assert.True(difference.TotalSeconds < 10);
        }
示例#4
0
        public void EvaluateNowConfig()
        {
            string         variableName = "nowString";
            string         format       = "";
            bool           utc          = true;
            NowMacroConfig macroConfig  = new NowMacroConfig(variableName, format, utc);

            IVariableCollection    variables  = new VariableCollection();
            IRunnableProjectConfig config     = new SimpleConfigModel();
            IParameterSet          parameters = new ParameterSet(config);
            ParameterSetter        setter     = MacroTestHelpers.TestParameterSetter(EngineEnvironmentSettings, parameters);

            NowMacro macro = new NowMacro();

            macro.EvaluateConfig(EngineEnvironmentSettings, variables, macroConfig, parameters, setter);
            ITemplateParameter resultParam;

            Assert.True(parameters.TryGetParameterDefinition(variableName, out resultParam));
            string   macroNowString = (string)parameters.ResolvedValues[resultParam];
            DateTime macroNowTime   = Convert.ToDateTime(macroNowString);

            TimeSpan difference = macroNowTime.Subtract(DateTime.UtcNow);

            // 10 seconds is quite a lot of wiggle room, but should be fine, and safe.
            Assert.True(difference.TotalSeconds < 10);
        }
示例#5
0
        private void btnSetValue_Click(object sender, EventArgs e)
        {
            if (lstParameters.SelectedIndices.Count != 1) return;
            ParameterExpression p = (ParameterExpression)lstParameters.SelectedItems[0].Tag;
            //Check if the parameter is a base type if not we need another form.

            if (p.Type.IsPrimitive)
            {
                ParameterSetter setter = new ParameterSetter(p);
                if (setter.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    lstParameters.SelectedItems[0].SubItems[1].Tag = setter.SelectedValue;
                    lstParameters.SelectedItems[0].SubItems[1].Text = setter.SelectedValue.ToString();
                }
            }
            else
            {
                Object obj = lstParameters.SelectedItems[0].SubItems[1].Tag ?? Activator.CreateInstance(p.Type);
                ParameterSetterNotBaseType setter = new ParameterSetterNotBaseType(obj);
                if (setter.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    lstParameters.SelectedItems[0].SubItems[1].Tag = setter.SelectedValue;
                    lstParameters.SelectedItems[0].SubItems[1].Text = setter.SelectedValue.ToString();
                }
            }
        }
示例#6
0
        public void TestRegexMatchMacroFalse()
        {
            const string          variableName   = "isMatch";
            const string          sourceVariable = "originalValue";
            RegexMatchMacroConfig macroConfig    = new RegexMatchMacroConfig(variableName, null, sourceVariable, @"(((?<=\.)|^)(?=\d)|[^\w\.])");

            IVariableCollection    variables  = new VariableCollection();
            IRunnableProjectConfig config     = A.Fake <IRunnableProjectConfig>();
            IParameterSet          parameters = new RunnableProjectGenerator.ParameterSet(config);
            ParameterSetter        setter     = MacroTestHelpers.TestParameterSetter(_engineEnvironmentSettings, parameters);

            const string sourceValue   = "A1234test";
            const bool   expectedValue = false;

            Parameter sourceParam = new Parameter
            {
                IsVariable = true,
                Name       = sourceVariable
            };

            variables[sourceVariable] = sourceValue;
            setter(sourceParam, sourceValue);

            RegexMatchMacro macro = new RegexMatchMacro();

            macro.EvaluateConfig(_engineEnvironmentSettings, variables, macroConfig, parameters, setter);

            Assert.True(parameters.TryGetParameterDefinition(variableName, out ITemplateParameter newParam));
            bool newValue = (bool)parameters.ResolvedValues[newParam];

            Assert.Equal(newValue, expectedValue);
        }
        public void TestSwitchConfig()
        {
            string variableName  = "mySwitchVar";
            string evaluator     = "C++";
            string dataType      = "string";
            string expectedValue = "this one";
            IList <KeyValuePair <string, string> > switches = new List <KeyValuePair <string, string> >();

            switches.Add(new KeyValuePair <string, string>("(3 > 10)", "three greater than ten - false"));
            switches.Add(new KeyValuePair <string, string>("(false)", "false value"));
            switches.Add(new KeyValuePair <string, string>("(10 > 0)", expectedValue));
            switches.Add(new KeyValuePair <string, string>("(5 > 4)", "not this one"));
            SwitchMacroConfig macroConfig = new SwitchMacroConfig(variableName, evaluator, dataType, switches);

            IVariableCollection    variables  = new VariableCollection();
            IRunnableProjectConfig config     = new SimpleConfigModel();
            IParameterSet          parameters = new ParameterSet(config);
            ParameterSetter        setter     = MacroTestHelpers.TestParameterSetter(_engineEnvironmentSettings, parameters);

            SwitchMacro macro = new SwitchMacro();

            macro.EvaluateConfig(_engineEnvironmentSettings, variables, macroConfig, parameters, setter);
            ITemplateParameter resultParam;

            Assert.True(parameters.TryGetParameterDefinition(variableName, out resultParam));
            string resultValue = (string)parameters.ResolvedValues[resultParam];

            Assert.Equal(resultValue, expectedValue);
        }
示例#8
0
        public void TestDeferredCaseChangeConfig()
        {
            string variableName = "myString";

            Dictionary <string, JToken> jsonParameters = new Dictionary <string, JToken>();
            string sourceVariable = "sourceString";

            jsonParameters.Add("source", sourceVariable);
            jsonParameters.Add("toLower", false);
            GeneratedSymbolDeferredMacroConfig deferredConfig = new GeneratedSymbolDeferredMacroConfig("CaseChangeMacro", variableName, jsonParameters);

            CaseChangeMacro        macro      = new CaseChangeMacro();
            IVariableCollection    variables  = new VariableCollection();
            IRunnableProjectConfig config     = new SimpleConfigModel();
            IParameterSet          parameters = new ParameterSet(config);
            ParameterSetter        setter     = MacroTestHelpers.TestParameterSetter(EngineEnvironmentSettings, parameters);

            string    sourceValue = "Original Value SomethingCamelCase";
            Parameter sourceParam = new Parameter
            {
                IsVariable = true,
                Name       = sourceVariable
            };

            variables[sourceVariable] = sourceValue;
            setter(sourceParam, sourceValue);

            macro.EvaluateDeferredConfig(EngineEnvironmentSettings, variables, deferredConfig, parameters, setter);
            ITemplateParameter convertedParam;

            Assert.True(parameters.TryGetParameterDefinition(variableName, out convertedParam));
            string convertedValue = (string)parameters.ResolvedValues[convertedParam];

            Assert.Equal(convertedValue, sourceValue.ToUpper());
        }
示例#9
0
        private static bool ParseArgument(string[] args, ref int argIndex, ParameterSetter setter)
        {
            var name  = args[argIndex];
            var value = argIndex + 1 < args.Length ? args[argIndex + 1] : null;

            string?message = null;

            if (value != null && setter(value, out message))
            {
                argIndex++;
                return(true);
            }

            if (value == null || value.StartsWith("-") || ProcessingParameters.IsValueLikeToMkvFilePath(value))
            {
                Console.WriteLine("Invalid command-line arguments:");
                Console.WriteLine($"Option {name} must be followed by its value");
                return(false);
            }

            argIndex++;
            Console.WriteLine($"Invalid value \"{value}\" of command-line option {name}:");
            Console.WriteLine(message);
            return(false);
        }
示例#10
0
        public void TestCaseChangeToUpperConfig()
        {
            string variableName   = "myString";
            string sourceVariable = "sourceString";
            bool   toLower        = false;

            CaseChangeMacroConfig macroConfig = new CaseChangeMacroConfig(variableName, null, sourceVariable, toLower);

            IVariableCollection    variables  = new VariableCollection();
            IRunnableProjectConfig config     = A.Fake <IRunnableProjectConfig>();
            IParameterSet          parameters = new ParameterSet(config);
            ParameterSetter        setter     = MacroTestHelpers.TestParameterSetter(_engineEnvironmentSettings, parameters);

            string    sourceValue = "Original Value SomethingCamelCase";
            Parameter sourceParam = new Parameter
            {
                IsVariable = true,
                Name       = sourceVariable
            };

            variables[sourceVariable] = sourceValue;
            setter(sourceParam, sourceValue);

            CaseChangeMacro macro = new CaseChangeMacro();

            macro.EvaluateConfig(_engineEnvironmentSettings, variables, macroConfig, parameters, setter);

            ITemplateParameter convertedParam;

            Assert.True(parameters.TryGetParameterDefinition(variableName, out convertedParam));
            string convertedValue = (string)parameters.ResolvedValues[convertedParam];

            Assert.Equal(convertedValue, sourceValue.ToUpper());
        }
示例#11
0
        public void TestDefaultFormatIsCaseSensetive()
        {
            string       paramNameLower   = "TestGuidLower";
            IMacroConfig macroConfigLower = new GuidMacroConfig(paramNameLower, "string", string.Empty, "n");
            string       paramNameUpper   = "TestGuidUPPER";
            IMacroConfig macroConfigUpper = new GuidMacroConfig(paramNameUpper, "string", string.Empty, "N");

            IVariableCollection    variables  = new VariableCollection();
            IRunnableProjectConfig config     = A.Fake <IRunnableProjectConfig>();
            IParameterSet          parameters = new ParameterSet(config);
            ParameterSetter        setter     = MacroTestHelpers.TestParameterSetter(_engineEnvironmentSettings, parameters);

            GuidMacro guidMacro = new GuidMacro();

            guidMacro.EvaluateConfig(_engineEnvironmentSettings, variables, macroConfigLower, parameters, setter);
            guidMacro.EvaluateConfig(_engineEnvironmentSettings, variables, macroConfigUpper, parameters, setter);

            Assert.True(parameters.TryGetParameterDefinition(paramNameLower, out var setParamLower));
            Assert.All(((string)parameters.ResolvedValues[setParamLower]).ToCharArray(), (c) =>
            {
                Assert.True(char.IsLower(c) || char.IsDigit(c));
            });

            Assert.True(parameters.TryGetParameterDefinition(paramNameUpper, out var setParamUpper));
            Assert.All(((string)parameters.ResolvedValues[setParamUpper]).ToCharArray(), (c) =>
            {
                Assert.True(char.IsUpper(c) || char.IsDigit(c));
            });
        }
        public void TestRandomConfig(int low, int?high)
        {
            string            variableName = "myRnd";
            RandomMacroConfig macroConfig  = new RandomMacroConfig(variableName, low, high);

            IVariableCollection    variables  = new VariableCollection();
            IRunnableProjectConfig config     = new SimpleConfigModel();
            IParameterSet          parameters = new ParameterSet(config);
            ParameterSetter        setter     = MacroTestHelpers.TestParameterSetter(EngineEnvironmentSettings, parameters);

            RandomMacro macro = new RandomMacro();

            macro.EvaluateConfig(EngineEnvironmentSettings, variables, macroConfig, parameters, setter);

            ITemplateParameter valueParam;

            Assert.True(parameters.TryGetParameterDefinition(variableName, out valueParam));
            long randomValue = (long)parameters.ResolvedValues[valueParam];

            Assert.True(randomValue >= low);

            if (high.HasValue)
            {
                Assert.True(randomValue <= high);
            }
        }
        public void TestRandomDeferredConfig(int low, int?high)
        {
            string variableName = "myRnd";
            Dictionary <string, JToken> jsonParameters = new Dictionary <string, JToken>();

            jsonParameters.Add("low", low);
            if (high.HasValue)
            {
                jsonParameters.Add("high", high);
            }

            GeneratedSymbolDeferredMacroConfig deferredConfig = new GeneratedSymbolDeferredMacroConfig("RandomMacro", variableName, jsonParameters);
            IVariableCollection    variables  = new VariableCollection();
            IRunnableProjectConfig config     = new SimpleConfigModel();
            IParameterSet          parameters = new ParameterSet(config);
            ParameterSetter        setter     = MacroTestHelpers.TestParameterSetter(EngineEnvironmentSettings, parameters);

            RandomMacro macro = new RandomMacro();

            macro.EvaluateDeferredConfig(EngineEnvironmentSettings, variables, deferredConfig, parameters, setter);
            ITemplateParameter valueParam;

            Assert.True(parameters.TryGetParameterDefinition(variableName, out valueParam));
            long randomValue = (long)parameters.ResolvedValues[valueParam];

            Assert.True(randomValue >= low);

            if (high.HasValue)
            {
                Assert.True(randomValue <= high);
            }
        }
示例#14
0
        public IEnumerable <IOperationProvider> Process(IComponentManager componentManager, JObject rawConfiguration, IDirectory templateRoot, IVariableCollection variables, IParameterSet parameters)
        {
            EnsureMacros(componentManager);

            ParameterSetter setter = (p, value) =>
            {
                ((RunnableProjectGenerator.ParameterSet)parameters).AddParameter(p);
                parameters.ResolvedValues[p] = value;
            };

            foreach (JProperty property in rawConfiguration.Properties())
            {
                string  variableName = property.Name;
                JObject def          = (JObject)property.Value;
                string  macroType    = def["type"].ToString();

                IMacro macroObject;
                if (_macros.TryGetValue(macroType, out macroObject))
                {
                    macroObject.Evaluate(variableName, variables, def, parameters, setter);
                }
            }

            return(Empty <IOperationProvider> .List.Value);
        }
示例#15
0
        public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVariableCollection vars,
                                   IMacroConfig rawConfig, IParameterSet parameters, ParameterSetter setter)
        {
            JoinMacroConfig config = rawConfig as JoinMacroConfig;

            if (config == null)
            {
                throw new InvalidCastException("Couldn't cast the rawConfig as ConcatenationMacroConfig");
            }

            List <string> values = new List <string>();

            foreach (KeyValuePair <string, string> symbol in config.Symbols)
            {
                switch (symbol.Key)
                {
                case "ref":
                    string value;
                    if (!vars.TryGetValue(symbol.Value, out object working))
                    {
                        if (parameters.TryGetRuntimeValue(environmentSettings, symbol.Value,
                                                          out object resolvedValue, true))
                        {
                            value = resolvedValue.ToString();
                        }
                        else
                        {
                            value = string.Empty;
                        }
                    }
示例#16
0
 private void Execute_UpdateRoleView(object obj)
 {
     var p = (staff)obj;
     var index = _staffList.IndexOf(p);
     var popUpRole = new PopUpRole();
     ParameterSetter.SetParameter(p.Account_id);
     popUpRole.ShowDialog();
 }
示例#17
0
        public Page Create(Type type, object parameter)
        {
            Page page = null;

            if (Resolver.IsEnabled)
            {
                page = (Page)Resolver.Resolve(type);

                var view = page as ViewBase;

                if (view != null)
                {
                    view.CreatedByTinyMvvm = true;

                    view.CreateViewModel();
                }

                if (view?.BindingContext is ViewModelBase)
                {
                    TinyMvvmSetup(view, parameter);
                }
                else
                {
                    if (ParameterSetter.CanSet(type))
                    {
                        ParameterSetter.Set(page, parameter);
                    }
                }
            }
            else
            {
                var defaultCreator = new DefaultViewCreator();
                page = defaultCreator.Create(type);

                var view = page as ViewBase;

                if (view != null)
                {
                    view.CreatedByTinyMvvm = true;

                    view.CreateViewModel();
                }

                if (view?.BindingContext is ViewModelBase)
                {
                    TinyMvvmSetup(view, parameter);
                }
                else
                {
                    if (ParameterSetter.CanSet(type))
                    {
                        ParameterSetter.Set(page, parameter);
                    }
                }
            }

            return(page);
        }
        internal static ParameterSetter TestParameterSetter(IEngineEnvironmentSettings environmentSettings, IParameterSet parameters)
        {
            ParameterSetter setter = (p, value) =>
            {
                ((RunnableProjectGenerator.ParameterSet)parameters).AddParameter(p);
                parameters.ResolvedValues[p] = RunnableProjectGenerator.InternalConvertParameterValueToType(environmentSettings, p, value, out bool valueResolutionError);
            };

            return(setter);
        }
示例#19
0
        // Warning: if there are unknown macro "types", they are quietly ignored here.
        // This applies to both the regular and deferred macros.
        internal IEnumerable <IOperationProvider> ProcessMacros(IEngineEnvironmentSettings environmentSettings, IReadOnlyList <IMacroConfig> macroConfigs, IVariableCollection variables, IParameterSet parameters)
        {
            EnsureMacros(environmentSettings.Components);
            EnsureDeferredMacros(environmentSettings.Components);

            ParameterSetter setter = (p, value) =>
            {
                ((RunnableProjectGenerator.ParameterSet)parameters).AddParameter(p);
                parameters.ResolvedValues[p] = RunnableProjectGenerator.InternalConvertParameterValueToType(environmentSettings, p, value, out bool valueResolutionError);
                // TODO: consider checking the valueResolutionError and act on it, if needed.
                // Should be safe to ignore, params should be verified by the time this occurs.
            };

            IList <IMacroConfig> allMacroConfigs = new List <IMacroConfig>(macroConfigs);
            IList <GeneratedSymbolDeferredMacroConfig> deferredConfigList = new List <GeneratedSymbolDeferredMacroConfig>();

            // run the macros that are already setup, stash the deferred ones for afterwards
            foreach (IMacroConfig config in allMacroConfigs)
            {
                if (config is GeneratedSymbolDeferredMacroConfig deferredConfig)
                {
                    deferredConfigList.Add(deferredConfig);
                    continue;
                }

                if (_macroObjects.TryGetValue(config.Type, out IMacro macroObject))
                {
                    macroObject.EvaluateConfig(environmentSettings, variables, config, parameters, setter);
                }
            }

            List <Tuple <IMacro, IMacroConfig> > deferredConfigs = new List <Tuple <IMacro, IMacroConfig> >();

            // Set up all deferred macro configurations - this must be done separately from running them
            //  as certain generation types may require (like generating port numbers) that a shared resource
            //  be held in a particular state to influence the production of other values
            foreach (GeneratedSymbolDeferredMacroConfig deferredConfig in deferredConfigList)
            {
                IDeferredMacro deferredMacroObject;
                if (_deferredMacroObjects.TryGetValue(deferredConfig.Type, out deferredMacroObject))
                {
                    deferredConfigs.Add(Tuple.Create((IMacro)deferredMacroObject, deferredMacroObject.CreateConfig(environmentSettings, deferredConfig)));
                }
            }

            foreach (Tuple <IMacro, IMacroConfig> config in deferredConfigs)
            {
                config.Item1.EvaluateConfig(environmentSettings, variables, config.Item2, parameters, setter);
            }

            return(Array.Empty <IOperationProvider>());
        }
        public void TestSwitchDeferredConfig()
        {
            string variableName  = "mySwitchVar";
            string evaluator     = "C++";
            string dataType      = "string";
            string expectedValue = "this one";
            string switchCases   = @"[
                {
                    'condition': '(3 > 10)',
                    'value': 'three greater than ten'
                },
                {
                    'condition': '(false)',
                    'value': 'false value'
                },
                {
                    'condition': '(10 > 0)',
                    'value': '" + expectedValue + @"'
                },
                {
                    'condition': '(5 > 4)',
                    'value': 'not this one'
                }
            ]";

            Dictionary <string, JToken> jsonParameters = new Dictionary <string, JToken>();

            jsonParameters.Add("evaluator", evaluator);
            jsonParameters.Add("datatype", dataType);
            jsonParameters.Add("cases", JArray.Parse(switchCases));

            GeneratedSymbolDeferredMacroConfig deferredConfig = new GeneratedSymbolDeferredMacroConfig("SwitchMacro", null, variableName, jsonParameters);

            IVariableCollection    variables  = new VariableCollection();
            IRunnableProjectConfig config     = new SimpleConfigModel();
            IParameterSet          parameters = new ParameterSet(config);
            ParameterSetter        setter     = MacroTestHelpers.TestParameterSetter(_engineEnvironmentSettings, parameters);

            SwitchMacro  macro      = new SwitchMacro();
            IMacroConfig realConfig = macro.CreateConfig(_engineEnvironmentSettings, deferredConfig);

            macro.EvaluateConfig(_engineEnvironmentSettings, variables, realConfig, parameters, setter);
            ITemplateParameter resultParam;

            Assert.True(parameters.TryGetParameterDefinition(variableName, out resultParam));
            string resultValue = (string)parameters.ResolvedValues[resultParam];

            Assert.Equal(resultValue, expectedValue);
        }
示例#21
0
 private static bool AskParameter(string prompt, ParameterSetter setter)
 {
     for (var attempt = 0; attempt < MAX_ASK_ATTEMPTS; attempt++)
     {
         Console.Write(prompt + ": ");
         var str = Console.ReadLine();
         if (setter(str, out var message))
         {
             return(true);
         }
         Console.WriteLine(message);
         Console.Beep();
     }
     return(false);
 }
示例#22
0
        public void TestGuidConfig()
        {
            string       paramName   = "TestGuid";
            IMacroConfig macroConfig = new GuidMacroConfig(paramName, "string", string.Empty, null);

            IVariableCollection    variables  = new VariableCollection();
            IRunnableProjectConfig config     = new SimpleConfigModel();
            IParameterSet          parameters = new ParameterSet(config);
            ParameterSetter        setter     = MacroTestHelpers.TestParameterSetter(EngineEnvironmentSettings, parameters);

            GuidMacro guidMacro = new GuidMacro();

            guidMacro.EvaluateConfig(EngineEnvironmentSettings, variables, macroConfig, parameters, setter);
            ValidateGuidMacroCreatedParametersWithResolvedValues(paramName, parameters);
        }
示例#23
0
        public Page Create(Type type, object parameter)
        {
            if (ParameterSetter.CanSet(type))
            {
                var page = Create(type);

                ParameterSetter.Set(page, parameter);

                return(page);
            }
            else
            {
                return((Page)Activator.CreateInstance(type, parameter));
            }
        }
示例#24
0
        public void TestDeferredGuidConfig()
        {
            Dictionary <string, JToken> jsonParameters = new Dictionary <string, JToken>();

            jsonParameters.Add("format", null);
            string variableName = "myGuid1";
            GeneratedSymbolDeferredMacroConfig deferredConfig = new GeneratedSymbolDeferredMacroConfig("GuidMacro", variableName, jsonParameters);

            GuidMacro              guidMacro  = new GuidMacro();
            IVariableCollection    variables  = new VariableCollection();
            IRunnableProjectConfig config     = new SimpleConfigModel();
            IParameterSet          parameters = new ParameterSet(config);
            ParameterSetter        setter     = MacroTestHelpers.TestParameterSetter(EngineEnvironmentSettings, parameters);

            guidMacro.EvaluateDeferredConfig(EngineEnvironmentSettings, variables, deferredConfig, parameters, setter);
            ValidateGuidMacroCreatedParametersWithResolvedValues(variableName, parameters);
        }
        public void TestRegexDeferredConfig()
        {
            string variableName   = "myRegex";
            string sourceVariable = "originalValue";
            Dictionary <string, JToken> jsonParameters = new Dictionary <string, JToken>();

            jsonParameters.Add("source", sourceVariable);

            string jsonSteps = @"[
                { 
                    'regex': 'A',
                    'replacement': 'Z'
                }
            ]";

            jsonParameters.Add("steps", JArray.Parse(jsonSteps));

            GeneratedSymbolDeferredMacroConfig deferredConfig = new GeneratedSymbolDeferredMacroConfig("RegexMacro", variableName, jsonParameters);

            IVariableCollection    variables  = new VariableCollection();
            IRunnableProjectConfig config     = new SimpleConfigModel();
            IParameterSet          parameters = new ParameterSet(config);
            ParameterSetter        setter     = MacroTestHelpers.TestParameterSetter(EngineEnvironmentSettings, parameters);

            string    sourceValue   = "ABCAABBCC";
            string    expectedValue = "ZBCZZBBCC";
            Parameter sourceParam   = new Parameter
            {
                IsVariable = true,
                Name       = sourceVariable
            };

            variables[sourceVariable] = sourceValue;
            setter(sourceParam, sourceValue);

            RegexMacro   macro      = new RegexMacro();
            IMacroConfig realConfig = macro.CreateConfig(EngineEnvironmentSettings, deferredConfig);

            macro.EvaluateConfig(EngineEnvironmentSettings, variables, realConfig, parameters, setter);
            ITemplateParameter newParam;

            Assert.True(parameters.TryGetParameterDefinition(variableName, out newParam));
            string newValue = (string)parameters.ResolvedValues[newParam];

            Assert.Equal(newValue, expectedValue);
        }
示例#26
0
        public void TestDeferredJoinConfig(string separator)
        {
            string variableName         = "joinedParameter";
            string referenceSymbolName  = "referenceSymbol";
            string referenceSymbolValue = "referenceValue";
            string constantValue        = "constantValue";

            Dictionary <string, JToken> jsonParameters = new Dictionary <string, JToken>();
            string symbols =
                $"[ {{\"type\":\"const\" , \"value\":\"{constantValue}\"  }}, {{\"type\":\"ref\" , \"value\":\"{referenceSymbolName}\"  }} ]";

            jsonParameters.Add("symbols", JArray.Parse(symbols));
            if (!string.IsNullOrEmpty(separator))
            {
                jsonParameters.Add("separator", separator);
            }

            GeneratedSymbolDeferredMacroConfig deferredConfig = new GeneratedSymbolDeferredMacroConfig("JoinMacro", null, variableName, jsonParameters);

            IVariableCollection    variables  = new VariableCollection();
            IRunnableProjectConfig config     = new SimpleConfigModel();
            IParameterSet          parameters = new RunnableProjectGenerator.ParameterSet(config);
            ParameterSetter        setter     = MacroTestHelpers.TestParameterSetter(EngineEnvironmentSettings, parameters);

            Parameter referenceParam = new Parameter
            {
                IsVariable = true,
                Name       = referenceSymbolName
            };

            variables[referenceSymbolName] = referenceSymbolValue;
            setter(referenceParam, referenceSymbolValue);

            JoinMacro    macro      = new JoinMacro();
            IMacroConfig realConfig = macro.CreateConfig(EngineEnvironmentSettings, deferredConfig);

            macro.EvaluateConfig(EngineEnvironmentSettings, variables, realConfig, parameters, setter);

            Assert.True(parameters.TryGetParameterDefinition(variableName, out ITemplateParameter convertedParam));

            string convertedValue = (string)parameters.ResolvedValues[convertedParam];
            string expectedValue  = string.Join(separator, constantValue, referenceSymbolValue);

            Assert.Equal(convertedValue, expectedValue);
        }
示例#27
0
        public void TestJoinConstantAndReferenceSymbolConfig(string separator, bool removeEmptyValues)
        {
            string variableName             = "joinedParameter";
            string referenceSymbolName      = "referenceSymbol";
            string referenceSymbolValue     = "referenceValue";
            string referenceEmptySymbolName = "referenceEmptySymbol";
            string constantValue            = "constantValue";

            List <KeyValuePair <string, string> > definitions = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("const", constantValue),
                new KeyValuePair <string, string>("ref", referenceEmptySymbolName),
                new KeyValuePair <string, string>("ref", referenceSymbolName)
            };

            JoinMacroConfig macroConfig = new JoinMacroConfig(variableName, null, definitions, separator, removeEmptyValues);

            IVariableCollection    variables  = new VariableCollection();
            IRunnableProjectConfig config     = A.Fake <IRunnableProjectConfig>();
            IParameterSet          parameters = new RunnableProjectGenerator.ParameterSet(config);
            ParameterSetter        setter     = MacroTestHelpers.TestParameterSetter(_engineEnvironmentSettings, parameters);

            Parameter referenceParam = new Parameter
            {
                IsVariable = true,
                Name       = referenceSymbolName
            };

            variables[referenceSymbolName] = referenceSymbolValue;
            setter(referenceParam, referenceSymbolValue);

            JoinMacro macro = new JoinMacro();

            macro.EvaluateConfig(_engineEnvironmentSettings, variables, macroConfig, parameters, setter);

            Assert.True(parameters.TryGetParameterDefinition(variableName, out ITemplateParameter convertedParam));

            string convertedValue = (string)parameters.ResolvedValues[convertedParam];
            string expectedValue  =
                removeEmptyValues ?
                string.Join(separator, constantValue, referenceSymbolValue) :
                string.Join(separator, constantValue, null, referenceSymbolValue);

            Assert.Equal(convertedValue, expectedValue);
        }
        // Warning: if there are unknown macro "types", they are quietly ignored here.
        // This applies to both the regular and deferred macros.
        public IEnumerable <IOperationProvider> ProcessMacros(IEngineEnvironmentSettings environmentSettings, IComponentManager componentManager, IReadOnlyList <IMacroConfig> macroConfigs, IVariableCollection variables, IParameterSet parameters)
        {
            EnsureMacros(componentManager);
            EnsureDeferredMacros(componentManager);

            ParameterSetter setter = (p, value) =>
            {
                ((RunnableProjectGenerator.ParameterSet)parameters).AddParameter(p);
                parameters.ResolvedValues[p] = RunnableProjectGenerator.InternalConvertParameterValueToType(environmentSettings, p, value, out bool valueResolutionError);
                // TODO: consider checking the valueResolutionError and act on it, if needed.
                // Should be safe to ignore, params should be verified by the time this occurs.
            };

            IList <IMacroConfig> allMacroConfigs = new List <IMacroConfig>(macroConfigs);
            IList <GeneratedSymbolDeferredMacroConfig> deferredConfigList = new List <GeneratedSymbolDeferredMacroConfig>();

            // run the macros that are already setup, stash the deferred ones for afterwards
            foreach (IMacroConfig config in allMacroConfigs)
            {
                if (config is GeneratedSymbolDeferredMacroConfig deferredConfig)
                {
                    deferredConfigList.Add(deferredConfig);
                    continue;
                }

                if (_macroObjects.TryGetValue(config.Type, out IMacro macroObject))
                {
                    macroObject.EvaluateConfig(environmentSettings, variables, config, parameters, setter);
                }
            }

            // run the deferred macros
            foreach (GeneratedSymbolDeferredMacroConfig deferredConfig in deferredConfigList)
            {
                IDeferredMacro deferredMacroObject;
                if (_deferredMacroObjects.TryGetValue(deferredConfig.Type, out deferredMacroObject))
                {
                    deferredMacroObject.EvaluateDeferredConfig(environmentSettings, variables, deferredConfig, parameters, setter);
                }
            }

            return(Empty <IOperationProvider> .List.Value);
        }
        /// <summary>
        /// Executes batch of non queries with common command and different
        /// parameters.
        /// </summary>
        /// <typeparam name="T">
        /// The type of the data object.
        /// </typeparam>
        /// <param name="operation">
        /// An <see cref="Spring.Data.Generic.IAdoOperations"/> object to
        /// perform database operation.
        /// </param>
        /// <param name="cmdType">
        /// The type of command.
        /// </param>
        /// <param name="cmdText">
        /// The text of command.
        /// </param>
        /// <param name="data">
        /// A collection of data object to be updated in batch.
        /// </param>
        /// <param name="dataToParameters">
        /// Delegate that converts data object to parameters.
        /// </param>
        /// <returns>
        /// The total updated count if 0 or positive. When -1 is returned,
        /// it indicates that the update count cannot be obtained due the
        /// the limitation of the batch implementation.
        /// </returns>
        public static int ExecuteNonQuery <T>(
            this IAdoOperations operation,
            CommandType cmdType,
            string cmdText,
            ICollection <T> data,
            Converter <T, IDbParameters> dataToParameters)
        {
            // Argument checking
            if (data == null || data.Count == 0)
            {
                return(0);
            }
            if (cmdText == null)
            {
                throw new ArgumentNullException("cmdText");
            }
            if (dataToParameters == null)
            {
                throw new ArgumentNullException("dataToParameters");
            }

            if (data.Count > 1)
            {
                // Let's try batch
                IBatchExecutorFactory factory = operation as IBatchExecutorFactory;
                if (factory != null)
                {
                    return(factory.GetExecutor().ExecuteNonQuery(
                               operation, cmdType, cmdText, data, dataToParameters));
                }
            }

            ParameterSetter setter = new ParameterSetter();
            int             result = 0;

            foreach (T row in data)
            {
                setter.Parameters = dataToParameters(row);
                result           += operation.ExecuteNonQuery(cmdType, cmdText, setter);
            }
            return(result);
        }
        // Warning: if there are unknown macro "types", they are quietly ignored here.
        // This applies to both the regular and deferred macros.
        public IEnumerable <IOperationProvider> ProcessMacros(IComponentManager componentManager, IReadOnlyList <IMacroConfig> macroConfigs, IVariableCollection variables, IParameterSet parameters)
        {
            EnsureMacros(componentManager);
            EnsureDeferredMacros(componentManager);

            ParameterSetter setter = (p, value) =>
            {
                ((RunnableProjectGenerator.ParameterSet)parameters).AddParameter(p);
                parameters.ResolvedValues[p] = RunnableProjectGenerator.InternalConvertParameterValueToType(p, value);
            };

            IList <IMacroConfig> allMacroConfigs = new List <IMacroConfig>(macroConfigs);
            IList <GeneratedSymbolDeferredMacroConfig> deferredConfigList = new List <GeneratedSymbolDeferredMacroConfig>();

            // run the macros that are already setup, stash the deferred ones for afterwards
            foreach (IMacroConfig config in allMacroConfigs)
            {
                if (config is GeneratedSymbolDeferredMacroConfig)
                {
                    deferredConfigList.Add(config as GeneratedSymbolDeferredMacroConfig);
                    continue;
                }

                IMacro macroObject;
                if (_macroObjects.TryGetValue(config.Type, out macroObject))
                {
                    macroObject.EvaluateConfig(variables, config, parameters, setter);
                }
            }

            // run the deferred macros
            foreach (GeneratedSymbolDeferredMacroConfig deferredConfig in deferredConfigList)
            {
                IDeferredMacro deferredMacroObject;
                if (_deferredMacroObjects.TryGetValue(deferredConfig.Type, out deferredMacroObject))
                {
                    deferredMacroObject.EvaluateDeferredConfig(variables, deferredConfig, parameters, setter);
                }
            }

            return(Empty <IOperationProvider> .List.Value);
        }
示例#31
0
        public void TestEvaluateConfig(string predicate, bool expectedResult)
        {
            string variableName             = "myPredicate";
            string evaluator                = "C++";
            EvaluateMacroConfig macroConfig = new EvaluateMacroConfig(variableName, predicate, evaluator);

            IVariableCollection    variables  = new VariableCollection();
            IRunnableProjectConfig config     = new SimpleConfigModel();
            IParameterSet          parameters = new ParameterSet(config);
            ParameterSetter        setter     = MacroTestHelpers.TestParameterSetter(EngineEnvironmentSettings, parameters);

            EvaluateMacro macro = new EvaluateMacro();

            macro.EvaluateConfig(EngineEnvironmentSettings, variables, macroConfig, parameters, setter);
            ITemplateParameter resultParam;

            Assert.True(parameters.TryGetParameterDefinition(variableName, out resultParam));
            bool resultValue = (bool)parameters.ResolvedValues[resultParam];

            Assert.Equal(resultValue, expectedResult);
        }