Merge pull request #73 from Amethi/master

Adding the new IndexByValue function
This commit is contained in:
Nilesh Ghodekar 2019-04-15 14:40:49 +01:00 коммит произвёл GitHub
Родитель c0282dcd2c 9c401b97fc
Коммит 22304489ad
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
2 изменённых файлов: 82 добавлений и 0 удалений

Просмотреть файл

@ -1288,6 +1288,11 @@ namespace MicrosoftServices.IdentityManagement.WorkflowActivityLibrary.Common
/// </summary> /// </summary>
public const int ExpressionFunctionMod = 11686; public const int ExpressionFunctionMod = 11686;
/// <summary>
/// The event identifier for ExpressionFunction IndexByValue events
/// </summary>
public const int ExpressionFunctionIndexByValue = 11687;
/// <summary> /// <summary>
/// The event identifier for LookupEvaluator Constructor events /// The event identifier for LookupEvaluator Constructor events
/// </summary> /// </summary>
@ -3178,6 +3183,16 @@ namespace MicrosoftServices.IdentityManagement.WorkflowActivityLibrary.Common
/// </summary> /// </summary>
public const int ExpressionFunctionModInvalidSecondFunctionParameterTypeError = 41686; 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> /// <summary>
/// The event identifier for LookupEvaluator Constructor events /// The event identifier for LookupEvaluator Constructor events
/// </summary> /// </summary>

Просмотреть файл

@ -222,6 +222,9 @@ namespace MicrosoftServices.IdentityManagement.WorkflowActivityLibrary.Common
case "IIF": case "IIF":
return this.IIF(); return this.IIF();
case "INDEXBYVALUE":
return this.IndexByValue();
case "INSERTVALUES": case "INSERTVALUES":
return this.InsertValues(); return this.InsertValues();
@ -2691,6 +2694,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> /// <summary>
/// This function is used to create a new InsertedValues collection which contains all values from the specified list. /// 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. /// This InsertedValues collection will be used by the activity so that it can generate update request parameters accordingly.