Skip to content

Commit

Permalink
feat: support setVariable pipelineReturnValues (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
arjendev authored Sep 8, 2023
1 parent a86ad79 commit c5d304e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ internal static SetVariableActivity DeserializeSetVariableActivity(JsonElement e
Optional<IList<PipelineActivityUserProperty>> userProperties = default;
Optional<string> variableName = default;
Optional<DataFactoryElement<string>> value = default;
Optional<Dictionary<string, DataFactoryElement<string>>> pipelineReturnValues = default;
Optional<bool> setSystemVariable = default;
IDictionary<string, DataFactoryElement<string>> additionalProperties = default;
Dictionary<string, DataFactoryElement<string>> additionalPropertiesDictionary = new Dictionary<string, DataFactoryElement<string>>();
Expand Down Expand Up @@ -201,6 +202,16 @@ internal static SetVariableActivity DeserializeSetVariableActivity(JsonElement e
{
continue;
}

if (property0.Value.ValueKind == JsonValueKind.Array)
{
pipelineReturnValues = new Dictionary<string, DataFactoryElement<string>>();
foreach (var item in property0.Value.EnumerateArray())
pipelineReturnValues.Value.Add(item.GetProperty("key"u8).GetString(), JsonSerializer.Deserialize<DataFactoryElement<string>>(item.GetProperty("value"u8).GetRawText()));

continue;
}

value = JsonSerializer.Deserialize<DataFactoryElement<string>>(property0.Value.GetRawText());
continue;
}
Expand All @@ -219,7 +230,7 @@ internal static SetVariableActivity DeserializeSetVariableActivity(JsonElement e
additionalPropertiesDictionary.Add(property.Name, JsonSerializer.Deserialize<DataFactoryElement<string>>(property.Value.GetRawText()));
}
additionalProperties = additionalPropertiesDictionary;
return new SetVariableActivity(name, type, description.Value, Optional.ToNullable(state), Optional.ToNullable(onInactiveMarkAs), Optional.ToList(dependsOn), Optional.ToList(userProperties), additionalProperties, policy.Value, variableName.Value, value.Value, Optional.ToNullable(setSystemVariable));
return new SetVariableActivity(name, type, description.Value, Optional.ToNullable(state), Optional.ToNullable(onInactiveMarkAs), Optional.ToList(dependsOn), Optional.ToList(userProperties), additionalProperties, policy.Value, variableName.Value, value.Value, pipelineReturnValues.Value, Optional.ToNullable(setSystemVariable));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,12 @@ public SetVariableActivity(string name) : base(name)
/// <param name="variableName"> Name of the variable whose value needs to be set. </param>
/// <param name="value"> Value to be set. Could be a static value or Expression. </param>
/// <param name="setSystemVariable"> If set to true, it sets the pipeline run return value. </param>
internal SetVariableActivity(string name, string activityType, string description, PipelineActivityState? state, ActivityOnInactiveMarkAs? onInactiveMarkAs, IList<PipelineActivityDependency> dependsOn, IList<PipelineActivityUserProperty> userProperties, IDictionary<string, DataFactoryElement<string>> additionalProperties, SecureInputOutputPolicy policy, string variableName, DataFactoryElement<string> value, bool? setSystemVariable) : base(name, activityType, description, state, onInactiveMarkAs, dependsOn, userProperties, additionalProperties)
internal SetVariableActivity(string name, string activityType, string description, PipelineActivityState? state, ActivityOnInactiveMarkAs? onInactiveMarkAs, IList<PipelineActivityDependency> dependsOn, IList<PipelineActivityUserProperty> userProperties, IDictionary<string, DataFactoryElement<string>> additionalProperties, SecureInputOutputPolicy policy, string variableName, DataFactoryElement<string> value, Dictionary<string, DataFactoryElement<string>> pipelineReturnValues, bool? setSystemVariable) : base(name, activityType, description, state, onInactiveMarkAs, dependsOn, userProperties, additionalProperties)
{
Policy = policy;
VariableName = variableName;
Value = value;
PipelineReturnValues = pipelineReturnValues;
SetSystemVariable = setSystemVariable;
ActivityType = activityType ?? "SetVariable";
}
Expand All @@ -51,6 +52,8 @@ internal SetVariableActivity(string name, string activityType, string descriptio
public string VariableName { get; set; }
/// <summary> Value to be set. Could be a static value or Expression. </summary>
public DataFactoryElement<string> Value { get; set; }
/// <summary> Value to be set. Could be a static value or Expression. </summary>
public Dictionary<string, DataFactoryElement<string>> PipelineReturnValues { get; set; }
/// <summary> If set to true, it sets the pipeline run return value. </summary>
public bool? SetSystemVariable { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ public override PipelineActivity Evaluate(PipelineRunState state)
{
base.Evaluate(state);

// If SetVariable is used for setting return values, local variables are ignored
if (VariableName == "pipelineReturnValue")
return this;

var existingVariable = state.Variables.SingleOrDefault(variable => variable.Name == VariableName) ??
throw new VariableBeingEvaluatedDoesNotExistException(VariableName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,21 @@ private static bool TryGetNonLiteral<T>(JsonElement json, out DataFactoryElement
// Expression should only have two properties: type and value
return false;
}
var expressionValue = json.GetProperty("value").GetString();

string expressionValue = null;
if (json.TryGetProperty("value", out var value))
{
expressionValue = value.GetString();
}
else if (json.TryGetProperty("content", out var content))
{
expressionValue = content.GetString();
}
else
{
throw new JsonException("Expression object does not have a value or content property.");
}

element = new DataFactoryElement<T?>(expressionValue, DataFactoryElementKind.Expression);
}
else
Expand Down

0 comments on commit c5d304e

Please sign in to comment.