feature: update expression browser and add plugin expression extensions
This commit is contained in:
@@ -531,6 +531,8 @@
|
||||
<Compile Include="Plugins\Features\DetailsProvider\DetailsProviderService.cs" />
|
||||
<Compile Include="Plugins\Features\DetailsProvider\UserContactFeature.cs" />
|
||||
<Compile Include="Plugins\Features\DocumentHandlerProvider\DocumentHandlerProviderFeature.cs" />
|
||||
<Compile Include="Plugins\Features\ExpressionExtensionProvider\ExpressionExtensionProviderFeature.cs" />
|
||||
<Compile Include="Plugins\Features\ExpressionExtensionProvider\ExpressionExtensionRegistration.cs" />
|
||||
<Compile Include="Plugins\Features\InsuranceProvider\InsuranceProviderFeature.cs" />
|
||||
<Compile Include="Plugins\Features\InsuranceProvider\InsuranceProviderSubmitJobException.cs" />
|
||||
<Compile Include="Plugins\Features\RepairProvider\RepairProvider2Feature.cs" />
|
||||
|
||||
@@ -5,9 +5,9 @@ namespace Disco.Services.Expressions
|
||||
{
|
||||
public class EvaluateExpressionPart : IExpressionPart
|
||||
{
|
||||
private Spring.Expressions.IExpression _Expression;
|
||||
private RecognitionException _ExpressionParseException;
|
||||
private EvaluateExpressionParseException _EvaluateParseException;
|
||||
private Spring.Expressions.IExpression expression;
|
||||
private RecognitionException expressionParseException;
|
||||
private EvaluateExpressionParseException evaluateParseException;
|
||||
|
||||
public string RawSource { get; set; }
|
||||
public string Source { get; set; }
|
||||
@@ -18,18 +18,18 @@ namespace Disco.Services.Expressions
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_ExpressionParseException == null)
|
||||
if (expressionParseException == null)
|
||||
return null;
|
||||
else
|
||||
if (_EvaluateParseException == null)
|
||||
_EvaluateParseException = EvaluateExpressionParseException.FromRecognitionException(_ExpressionParseException, Source);
|
||||
return _EvaluateParseException;
|
||||
if (evaluateParseException == null)
|
||||
evaluateParseException = EvaluateExpressionParseException.FromRecognitionException(expressionParseException, Source);
|
||||
return evaluateParseException;
|
||||
}
|
||||
}
|
||||
|
||||
public bool ParseError
|
||||
{
|
||||
get { return (_ExpressionParseException != null); }
|
||||
get { return (expressionParseException != null); }
|
||||
}
|
||||
public string ParseErrorMessage
|
||||
{
|
||||
@@ -61,21 +61,21 @@ namespace Disco.Services.Expressions
|
||||
}
|
||||
try
|
||||
{
|
||||
_Expression = Spring.Expressions.Expression.Parse(this.Source);
|
||||
expression = Spring.Expressions.Expression.Parse(this.Source);
|
||||
|
||||
}
|
||||
catch (RecognitionException ex)
|
||||
{
|
||||
_ExpressionParseException = ex;
|
||||
expressionParseException = ex;
|
||||
}
|
||||
}
|
||||
object IExpressionPart.Evaluate(object ExpressionContext, IDictionary Variables)
|
||||
{
|
||||
if (_ExpressionParseException == null)
|
||||
if (expressionParseException == null)
|
||||
{
|
||||
return _Expression.GetValue(ExpressionContext, Variables);
|
||||
return expression.GetValue(ExpressionContext, Variables);
|
||||
}
|
||||
throw _ExpressionParseException;
|
||||
throw expressionParseException;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -73,11 +73,6 @@ namespace Disco.Services.Expressions
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static IExpression Parse(string source)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public Tuple<string, bool, object> Evaluate(object ExpressionContext, IDictionary Variables)
|
||||
{
|
||||
if (Count == 0)
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace Disco.Services.Expressions
|
||||
public string Name { get; set; }
|
||||
public List<ExpressionTypeMemberDescriptor> Members { get; set; }
|
||||
|
||||
public static ExpressionTypeDescriptor Build(Type t, bool StaticDeclaredMembersOnly = true)
|
||||
public static ExpressionTypeDescriptor Build(Type t, bool staticMembersOnly = true)
|
||||
{
|
||||
ExpressionTypeDescriptor i = new ExpressionTypeDescriptor
|
||||
{
|
||||
@@ -21,7 +21,7 @@ namespace Disco.Services.Expressions
|
||||
i.Members = new List<ExpressionTypeMemberDescriptor>();
|
||||
|
||||
MemberInfo[] members;
|
||||
if (StaticDeclaredMembersOnly)
|
||||
if (staticMembersOnly)
|
||||
members = t.GetMembers(BindingFlags.Public | BindingFlags.Static | BindingFlags.DeclaredOnly);
|
||||
else
|
||||
members = t.GetMembers(BindingFlags.Public | BindingFlags.Instance);
|
||||
@@ -46,10 +46,7 @@ namespace Disco.Services.Expressions
|
||||
}
|
||||
}
|
||||
}
|
||||
i.Members = (
|
||||
from mi in i.Members
|
||||
orderby mi.Name
|
||||
select mi).ToList();
|
||||
i.Members = i.Members.OrderBy(m => m.Name).ToList();
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
+40
@@ -0,0 +1,40 @@
|
||||
using Spring.Core.TypeResolution;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace Disco.Services.Plugins.Features.ExpressionExtensionProvider
|
||||
{
|
||||
[PluginFeatureCategory(DisplayName = "Expression Extension")]
|
||||
public abstract class ExpressionExtensionProviderFeature : PluginFeature
|
||||
{
|
||||
private static readonly Dictionary<string, ExpressionExtensionRegistration> registrations = new Dictionary<string, ExpressionExtensionRegistration>(StringComparer.OrdinalIgnoreCase);
|
||||
private static readonly Dictionary<string, Assembly> pluginAssemblies = new Dictionary<string, Assembly>(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
public void RegisterExpressionExtension(string alias, Type extensionType)
|
||||
{
|
||||
if (!extensionType.IsClass || !extensionType.IsAbstract || !extensionType.IsSealed)
|
||||
throw new ArgumentException("Expression Extension Types must be a static class", nameof(extensionType));
|
||||
|
||||
lock (registrations)
|
||||
{
|
||||
registrations.Add(alias, new ExpressionExtensionRegistration(Manifest, alias, extensionType));
|
||||
var assemblyName = extensionType.Assembly.FullName.Substring(0, extensionType.Assembly.FullName.IndexOf(','));
|
||||
pluginAssemblies[assemblyName] = extensionType.Assembly;
|
||||
TypeRegistry.RegisterType(alias, extensionType);
|
||||
}
|
||||
}
|
||||
|
||||
public static List<ExpressionExtensionRegistration> GetExpressionExtensionRegistrations()
|
||||
{
|
||||
lock (registrations)
|
||||
{
|
||||
return registrations.Values.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryGetExtensionAssembly(string assemblyName, out Assembly assembly)
|
||||
=> pluginAssemblies.TryGetValue(assemblyName, out assembly);
|
||||
}
|
||||
}
|
||||
+18
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
|
||||
namespace Disco.Services.Plugins.Features.ExpressionExtensionProvider
|
||||
{
|
||||
public class ExpressionExtensionRegistration
|
||||
{
|
||||
public PluginFeatureManifest FeatureManifest { get; }
|
||||
public string Alias { get; }
|
||||
public Type ExtensionType { get; }
|
||||
|
||||
public ExpressionExtensionRegistration(PluginFeatureManifest featureManifest, string alias, Type extensionType)
|
||||
{
|
||||
FeatureManifest = featureManifest;
|
||||
Alias = alias;
|
||||
ExtensionType = extensionType;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user