зеркало из https://github.com/microsoft/MIMWAL.git
Added support for the IndexByValue function.
This commit is contained in:
Родитель
40ab6065f6
Коммит
7d68106b94
|
@ -1258,6 +1258,11 @@ namespace MicrosoftServices.IdentityManagement.WorkflowActivityLibrary.Common
|
|||
/// </summary>
|
||||
public const int ExpressionFunctionMod = 11686;
|
||||
|
||||
/// <summary>
|
||||
/// The event identifier for ExpressionFunction IndexByValue events
|
||||
/// </summary>
|
||||
public const int ExpressionFunctionIndexByValue = 11687;
|
||||
|
||||
/// <summary>
|
||||
/// The event identifier for LookupEvaluator Constructor events
|
||||
/// </summary>
|
||||
|
@ -3133,6 +3138,16 @@ namespace MicrosoftServices.IdentityManagement.WorkflowActivityLibrary.Common
|
|||
/// </summary>
|
||||
public const int ExpressionFunctionModInvalidSecondFunctionParameterTypeError = 41686;
|
||||
|
||||
/// <summary>
|
||||
/// The event identifier for ExpressionFunction ValueByIndex events
|
||||
/// </summary>
|
||||
public const int ExpressionFunctionIndexByValueInvalidFunctionParameterCountError = 41687;
|
||||
|
||||
/// <summary>
|
||||
/// The event identifier for ExpressionFunction IndexByValue events
|
||||
/// </summary>
|
||||
public const int ExpressionFunctionIndexByValueNullFunctionParameterError = 41645;
|
||||
|
||||
/// <summary>
|
||||
/// The event identifier for LookupEvaluator Constructor events
|
||||
/// </summary>
|
||||
|
|
|
@ -222,6 +222,9 @@ namespace MicrosoftServices.IdentityManagement.WorkflowActivityLibrary.Common
|
|||
case "IIF":
|
||||
return this.IIF();
|
||||
|
||||
case "INDEXBYVALUE":
|
||||
return this.IndexByValue();
|
||||
|
||||
case "INSERTVALUES":
|
||||
return this.InsertValues();
|
||||
|
||||
|
@ -2676,6 +2679,70 @@ namespace MicrosoftServices.IdentityManagement.WorkflowActivityLibrary.Common
|
|||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function is used to retrieve the index for a specific value within the input list.
|
||||
/// Function Syntax: IndexByValue(values:[list or object], value:object)
|
||||
/// </summary>
|
||||
/// <returns>The index of the specified value in the input list. If the value is not found in the list, null is returned.</returns>
|
||||
private object IndexByValue()
|
||||
{
|
||||
Logger.Instance.WriteMethodEntry(EventIdentifier.ExpressionFunctionIndexByValue, "Evaluation Mode: '{0}'.", this.mode);
|
||||
|
||||
try
|
||||
{
|
||||
if (this.parameters.Count != 2)
|
||||
{
|
||||
throw Logger.Instance.ReportError(EventIdentifier.ExpressionFunctionIndexByValueInvalidFunctionParameterCountError, new InvalidFunctionFormatException(Messages.ExpressionFunction_InvalidFunctionParameterCountError, this.function, 2, this.parameters.Count));
|
||||
}
|
||||
|
||||
// default value if no results are found
|
||||
int result = -1;
|
||||
|
||||
if (this.mode != EvaluationMode.Parse)
|
||||
{
|
||||
if (this.parameters[0] != null && this.parameters[1] != null)
|
||||
{
|
||||
Type paramType = this.parameters[0].GetType();
|
||||
if (paramType.IsGenericType && paramType.GetGenericTypeDefinition() == typeof(List<>))
|
||||
{
|
||||
Logger.Instance.WriteVerbose(EventIdentifier.ExpressionFunctionIndexByValue, "IndexByValue('{0}', '{1}') First parameter is a list. Enumerating list items.", this.parameters[0], this.parameters[1]);
|
||||
|
||||
int index = 0;
|
||||
foreach (object item in (IEnumerable)this.parameters[0])
|
||||
{
|
||||
if (item is string && this.parameters[1] is string)
|
||||
{
|
||||
if (item.ToString().Equals(this.parameters[1].ToString(), StringComparison.InvariantCultureIgnoreCase))
|
||||
{
|
||||
Logger.Instance.WriteVerbose(EventIdentifier.ExpressionFunctionIndexByValue, "IndexByValue('{0}', '{1}') Matched string item '{2}' to second param '{3}'. Result: {4}.", this.parameters[0], this.parameters[1], item.ToString(), this.parameters[1].ToString(), index);
|
||||
result = index;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (item.Equals(this.parameters[1]))
|
||||
{
|
||||
Logger.Instance.WriteVerbose(EventIdentifier.ExpressionFunctionIndexByValue, "IndexByValue('{0}', '{1}') Matched object item '{2}' to second param '{3}'. Result: {4}.", this.parameters[0], this.parameters[1], item.ToString(), this.parameters[1].ToString(), index);
|
||||
result = index;
|
||||
break;
|
||||
}
|
||||
|
||||
index += 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Logger.Instance.WriteVerbose(EventIdentifier.ExpressionFunctionIndexByValue, "IndexByValue('{0}', '{1}') returned '{2}'.", this.parameters[0], this.parameters[1], result);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Logger.Instance.WriteMethodExit(EventIdentifier.ExpressionFunctionIndexByValue, "Evaluation Mode: '{0}'.", this.mode);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This function is used to create a new InsertedValues collection which contains all values from the specified list.
|
||||
/// This InsertedValues collection will be used by the activity so that it can generate update request parameters accordingly.
|
||||
|
|
Загрузка…
Ссылка в новой задаче