Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DerivedSymbol implementation #1194

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using Microsoft.TemplateEngine.Abstractions;
using Newtonsoft.Json.Linq;

namespace Microsoft.TemplateEngine.Orchestrator.RunnableProjects
{
public class DerivedSymbol : BaseValueSymbol
{
internal const string TypeName = "derived";

public string ValueTransform { get; set; }

public string ValueSource { get; set; }

public static ISymbolModel FromJObject(JObject jObject, IParameterSymbolLocalizationModel localization, string defaultOverride)
{
DerivedSymbol symbol = FromJObject<DerivedSymbol>(jObject, localization, defaultOverride);

symbol.ValueTransform = jObject.ToString(nameof(ValueTransform));
symbol.ValueSource = jObject.ToString(nameof(ValueSource));

return symbol;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using Microsoft.TemplateEngine.Abstractions;
using Microsoft.TemplateEngine.Core.Contracts;
Expand Down Expand Up @@ -42,11 +42,24 @@ public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVari

value = config.ToLower ? value.ToLowerInvariant() : value.ToUpperInvariant();

Parameter p = new Parameter
Parameter p;

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.
p = (Parameter)existingParam;
p.IsVariable = true;
}
else
{
IsVariable = true,
Name = config.VariableName
};
p = new Parameter
{
IsVariable = true,
Name = config.VariableName
};
}

vars[config.VariableName] = value;
setter(p, value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using Microsoft.TemplateEngine.Abstractions;
using Microsoft.TemplateEngine.Core.Contracts;
using Microsoft.TemplateEngine.Orchestrator.RunnableProjects.Macros.Config;
Expand Down Expand Up @@ -67,14 +67,27 @@ public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVari
}
}

Parameter pd = new Parameter
Parameter p;

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.
p = (Parameter)existingParam;
p.IsVariable = true;
}
else
{
IsVariable = true,
Name = config.VariableName
};
p = new Parameter
{
IsVariable = true,
Name = config.VariableName
};
}

vars[config.VariableName] = targetValue?.ToString();
setter(pd, targetValue?.ToString());
setter(p, targetValue?.ToString());
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using Microsoft.TemplateEngine.Abstractions;
using Microsoft.TemplateEngine.Core.Contracts;
using Microsoft.TemplateEngine.Orchestrator.RunnableProjects.Macros.Config;
Expand All @@ -21,12 +21,25 @@ public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVari
throw new InvalidCastException("Couldn't cast the rawConfig as ConstantMacroConfig");
}

Parameter p = new Parameter
Parameter p;

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.
p = (Parameter)existingParam;
p.IsVariable = true;
}
else
{
IsVariable = true,
Name = config.VariableName
};

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

vars[config.VariableName] = config.Value;
setter(p, config.Value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,24 @@ public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVari
IProcessorState state = new GlobalRunSpec.ProcessorState(environmentSettings, vars, data, Encoding.UTF8);
bool result = evaluator(state, ref len, ref pos, out bool faulted);

Parameter p = new Parameter
Parameter p;

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.
p = (Parameter)existingParam;
p.IsVariable = true;
}
else
{
IsVariable = true,
Name = config.VariableName
};
p = new Parameter
{
IsVariable = true,
Name = config.VariableName
};
}

vars[config.VariableName] = result.ToString();
setter(p, result.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,24 @@ public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVari

config.Socket?.Dispose();

Parameter p = new Parameter
Parameter p;

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.
p = (Parameter)existingParam;
p.IsVariable = true;
}
else
{
IsVariable = true,
Name = config.VariableName
};
p = new Parameter
{
IsVariable = true,
Name = config.VariableName
};
}

vars[config.VariableName] = config.Port.ToString();
setter(p, config.Port.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,24 @@ public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVari
setter(p, value);
}

Parameter pd = new Parameter
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
{
IsVariable = true,
Name = config.VariableName
};
pd = new Parameter
{
IsVariable = true,
Name = config.VariableName
};
}

vars[config.VariableName] = g.ToString("D");
setter(pd, g.ToString("D"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,25 @@ public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVari

DateTime time = config.Utc ? DateTime.UtcNow : DateTime.Now;
string value = time.ToString(config.Format);
Parameter p = new Parameter

Parameter p;

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.
p = (Parameter)existingParam;
p.IsVariable = true;
}
else
{
IsVariable = true,
Name = config.VariableName
};
p = new Parameter
{
IsVariable = true,
Name = config.VariableName
};
}

vars[config.VariableName] = value;
setter(p, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,24 @@ public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVari
{
value = form.Process(realConfig.Forms, value);

Parameter p = new Parameter
Parameter p;

if (parameters.TryGetParameterDefinition(config.VariableName, out ITemplateParameter existingParam))
{ // Derived parameters already have a definition, but need value form processing.
// 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.
p = (Parameter)existingParam;
p.IsVariable = true;
}
else
{
IsVariable = true,
Name = config.VariableName
};
p = new Parameter
{
IsVariable = true,
Name = config.VariableName
};
}

vars[config.VariableName] = value;
setter(p, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,24 @@ public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVari
Random rnd = new Random();
int value = rnd.Next(config.Low, config.High);

Parameter p = new Parameter
Parameter p;

if (parameters.TryGetParameterDefinition(config.VariableName, out ITemplateParameter existingParam))
{
IsVariable = true,
Name = config.VariableName
};
// 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.
p = (Parameter)existingParam;
p.IsVariable = true;
}
else
{
p = new Parameter
{
IsVariable = true,
Name = config.VariableName
};
}

vars[config.VariableName] = value.ToString();
setter(p, value.ToString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,24 @@ public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVari
}
}

Parameter p = new Parameter
Parameter p;

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.
p = (Parameter)existingParam;
p.IsVariable = true;
}
else
{
IsVariable = true,
Name = config.VariableName
};
p = new Parameter
{
IsVariable = true,
Name = config.VariableName
};
}

vars[config.VariableName] = value;
setter(p, value);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.TemplateEngine.Abstractions;
Expand Down Expand Up @@ -55,12 +55,24 @@ public void EvaluateConfig(IEngineEnvironmentSettings environmentSettings, IVari
}
}

Parameter p = new Parameter
Parameter p;

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.
p = (Parameter)existingParam;
p.IsVariable = true;
}
else
{
IsVariable = true,
Name = config.VariableName,
DataType = config.DataType
};
p = new Parameter
{
IsVariable = true,
Name = config.VariableName
};
}

vars[config.VariableName] = result.ToString();
setter(p, result.ToString());
Expand Down
Loading