-
Notifications
You must be signed in to change notification settings - Fork 218
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
24 changed files
with
676 additions
and
418 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
// This file is part of Core WF which is licensed under the MIT license. | ||
// See LICENSE file in the project root for full license information. | ||
|
||
namespace System.Activities | ||
{ | ||
internal class EnvironmentExtensions | ||
{ | ||
private readonly Dictionary<Type, object> _extensions = new(); | ||
|
||
/// <summary> | ||
/// Gets the specified extension. | ||
/// If the extension does not exist, | ||
/// it will invoke the <paramref name="createExtensionFactory"/> parameter | ||
/// </summary> | ||
/// <typeparam name="T">The type of the extension</typeparam> | ||
/// <param name="createExtensionFactory">The factory to create the extension</param> | ||
/// <exception cref="ArgumentNullException"></exception> | ||
public TInterface GetOrAdd<TInterface>(Func<TInterface> createExtensionFactory) | ||
where TInterface : class | ||
{ | ||
var type = typeof(TInterface); | ||
if (_extensions.TryGetValue(type, out object extension)) | ||
{ | ||
return extension as TInterface; | ||
} | ||
|
||
return CreateAndAdd(createExtensionFactory, type); | ||
} | ||
|
||
/// <summary> | ||
/// Retrieves the extension registered for the given type | ||
/// or null otherwise | ||
/// </summary> | ||
/// <typeparam name="T">The type of the extension.</typeparam> | ||
public T Get<T>() where T : class | ||
{ | ||
if (_extensions.TryGetValue(typeof(T), out object extension)) | ||
return extension as T; | ||
return null; | ||
} | ||
|
||
/// <summary> | ||
/// Adds the specified extension to the list. | ||
/// The extension is treated as a singleton, | ||
/// so if a second extension with the same type is added, it will | ||
/// throw an <see cref="InvalidOperationException"/> | ||
/// </summary> | ||
/// <typeparam name="TInterface">The type of the extension</typeparam> | ||
/// <param name="extension">The extension</param> | ||
/// <exception cref="InvalidOperationException"></exception> | ||
public void Add<TInterface, TImplementation>(TImplementation extension) | ||
where TInterface : class | ||
where TImplementation : class, TInterface | ||
{ | ||
if (_extensions.ContainsKey(typeof(TInterface))) | ||
throw new InvalidOperationException($"Service '{typeof(TInterface).FullName}' already exists"); | ||
|
||
_extensions[typeof(TInterface)] = extension; | ||
} | ||
|
||
|
||
#region private methods | ||
private T CreateAndAdd<T>(Func<T> createExtensionFactory, Type type) where T : class | ||
{ | ||
var extension = createExtensionFactory(); | ||
if (extension is null) | ||
throw new ArgumentNullException(nameof(extension)); | ||
|
||
_extensions[type] = extension; | ||
return extension; | ||
} | ||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/UiPath.Workflow.Runtime/Validation/ExpressionToValidate.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
| ||
namespace System.Activities.Validation; | ||
|
||
internal sealed class ExpressionToValidate | ||
{ | ||
public Activity Activity { get; init; } | ||
|
||
public string ExpressionText { get; init; } | ||
|
||
public LocationReferenceEnvironment Environment { get; init; } | ||
|
||
public Type ResultType { get; init; } | ||
|
||
public bool IsLocation { get; init; } | ||
} |
9 changes: 9 additions & 0 deletions
9
src/UiPath.Workflow.Runtime/Validation/IValidatorExtension.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
namespace System.Activities.Validation | ||
{ | ||
internal interface IValidatorExtension | ||
{ | ||
IList<ValidationError> Validate(Activity activity, LocationReferenceEnvironment environment); | ||
|
||
void QueueExpressionForValidation<T>(ExpressionToValidate expressionToValidate, string language); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
using System.Collections.Immutable; | ||
|
||
namespace System.Activities.Validation | ||
{ | ||
internal sealed class ValidationScope | ||
{ | ||
private readonly Dictionary<string, ExpressionToValidate> _expressionsToValidate = new(); | ||
private string _language; | ||
|
||
internal void AddExpression<T>(ExpressionToValidate expressionToValidate, string language) | ||
{ | ||
_language ??= language; | ||
if (_language != language) | ||
{ | ||
expressionToValidate.Activity.AddTempValidationError(new ValidationError(SR.DynamicActivityMultipleExpressionLanguages(language), expressionToValidate.Activity)); | ||
return; | ||
} | ||
_expressionsToValidate.Add(expressionToValidate.Activity.Id, expressionToValidate); | ||
} | ||
|
||
internal string Language => _language; | ||
|
||
internal ExpressionToValidate GetExpression(string activityId) => _expressionsToValidate[activityId]; | ||
|
||
internal ImmutableArray<ExpressionToValidate> GetAllExpressions() => _expressionsToValidate.Values.ToImmutableArray(); | ||
|
||
internal void Reset() => _expressionsToValidate.Clear(); | ||
} | ||
} |
Oops, something went wrong.