public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVariableCollection vars, IMacroConfig rawConfig, IParameterSet parameters, ParameterSetter setter)
        {
            GuidMacroConfig config = rawConfig as GuidMacroConfig;

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

            string guidFormats;

            if (!string.IsNullOrEmpty(config.Format))
            {
                guidFormats = config.Format;
            }
            else
            {
                guidFormats = GuidMacroConfig.DefaultFormats;
            }

            Guid g = Guid.NewGuid();

            for (int i = 0; i < guidFormats.Length; ++i)
            {
                string    value = char.IsUpper(guidFormats[i]) ? g.ToString(guidFormats[i].ToString()).ToUpperInvariant() : g.ToString(guidFormats[i].ToString()).ToLowerInvariant();
                Parameter p     = new Parameter
                {
                    IsVariable = true,
                    Name       = config.VariableName + "-" + guidFormats[i],
                    DataType   = config.DataType
                };

                vars[p.Name] = value;
                setter(p, value);
            }

            Parameter pd;

            if (parameters.TryGetParameterDefinition(config.VariableName, out ITemplateParameter existingParam))
            {
                // If there is an existing parameter with this name, it must be reused so it can be referenced by name
                // for other processing, for example: if the parameter had value forms defined for creating variants.
                // When the param already exists, use its definition, but set IsVariable = true for consistency.
                pd            = (Parameter)existingParam;
                pd.IsVariable = true;
            }
            else
            {
                pd = new Parameter
                {
                    IsVariable = true,
                    Name       = config.VariableName
                };
            }

            string value = char.IsUpper(config.DefaultFormat) ? g.ToString(config.DefaultFormat.ToString()).ToUpperInvariant() : g.ToString(config.DefaultFormat.ToString()).ToLowerInvariant();

            vars[config.VariableName] = value;
            setter(pd, value);
        }
Esempio n. 2
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));
            });
        }
Esempio n. 3
0
        public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVariableCollection vars, IMacroConfig rawConfig, IParameterSet parameters, ParameterSetter setter)
        {
            GuidMacroConfig config = rawConfig as GuidMacroConfig;

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

            if (!string.IsNullOrEmpty(config.Format))
            {
                Guid      g     = Guid.NewGuid();
                string    value = char.IsUpper(config.Format[0]) ? g.ToString(config.Format[0].ToString()).ToUpperInvariant() : g.ToString(config.Format[0].ToString()).ToLowerInvariant();
                Parameter p     = new Parameter
                {
                    IsVariable = true,
                    Name       = config.VariableName
                };

                vars[config.VariableName] = value;
                setter(p, value);
            }
            else
            {
                Guid   g           = Guid.NewGuid();
                string guidFormats = GuidMacroConfig.DefaultFormats;
                for (int i = 0; i < guidFormats.Length; ++i)
                {
                    string    value = char.IsUpper(guidFormats[i]) ? g.ToString(guidFormats[i].ToString()).ToUpperInvariant() : g.ToString(guidFormats[i].ToString()).ToLowerInvariant();
                    Parameter p     = new Parameter
                    {
                        IsVariable = true,
                        Name       = config.VariableName + "-" + guidFormats[i]
                    };

                    vars[config.VariableName] = value;
                    setter(p, value);
                }

                Parameter pd = new Parameter
                {
                    IsVariable = true,
                    Name       = config.VariableName
                };

                vars[config.VariableName] = g.ToString("D");
                setter(pd, g.ToString("D"));
            }
        }
Esempio n. 4
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);
        }
Esempio n. 5
0
        public IMacroConfig CreateConfig(IEngineEnvironmentSettings environmentSettings, IMacroConfig rawConfig)
        {
            GeneratedSymbolDeferredMacroConfig deferredConfig = rawConfig as GeneratedSymbolDeferredMacroConfig;

            if (deferredConfig == null)
            {
                throw new InvalidCastException("Couldn't cast the rawConfig as a GeneratedSymbolDeferredMacroConfig");
            }

            deferredConfig.Parameters.TryGetValue("format", out JToken formatToken);
            string format = formatToken?.ToString();

            IMacroConfig realConfig = new GuidMacroConfig(deferredConfig.VariableName, format);

            return(realConfig);
        }
Esempio n. 6
0
        public void EvaluateDeferredConfig(IEngineEnvironmentSettings environmentSettings, IVariableCollection vars, IMacroConfig rawConfig, IParameterSet parameters, ParameterSetter setter)
        {
            GeneratedSymbolDeferredMacroConfig deferredConfig = rawConfig as GeneratedSymbolDeferredMacroConfig;

            if (deferredConfig == null)
            {
                throw new InvalidCastException("Couldn't cast the rawConfig as a GeneratedSymbolDeferredMacroConfig");
            }

            if (!deferredConfig.Parameters.TryGetValue("format", out JToken formatToken))
            {
                throw new ArgumentNullException("format");
            }
            string format = formatToken?.ToString();

            IMacroConfig realConfig = new GuidMacroConfig(deferredConfig.VariableName, format);

            EvaluateConfig(environmentSettings, vars, realConfig, parameters, setter);
        }