forked from open-rpa/openrpa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWFHelper.cs
62 lines (57 loc) · 2.69 KB
/
WFHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using System;
using System.Activities.Expressions;
using System.Activities.Presentation.Model;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace OpenRPA.Interfaces
{
public static class WFHelper
{
public static System.Activities.ActivityWithResult TryCreateLiteral(Type type, string expressionText)
{
var ActivityDesignerAsm = typeof(System.Activities.Presentation.ActivityDesigner).Assembly;
var types = ActivityDesignerAsm.GetTypes();
var ExpressionHelper = types.Where(x => x.Name == "ExpressionHelper").FirstOrDefault();
var ParserContext = types.Where(x => x.Name == "ParserContext").FirstOrDefault();
object context = Activator.CreateInstance(ParserContext);
var TryCreateLiteralMethod = ExpressionHelper.GetMethods(BindingFlags.Static | BindingFlags.NonPublic).Where(x => x.Name == "TryCreateLiteral").FirstOrDefault();
var o = TryCreateLiteralMethod.Invoke(ExpressionHelper, new object[] { type, expressionText, context });
return o as System.Activities.ActivityWithResult;
}
public static void AddVBNamespaceSettings(System.Activities.ActivityBuilder rootObject, params Type[] types)
{
var vbsettings = Microsoft.VisualBasic.Activities.VisualBasic.GetSettings(rootObject);
if (vbsettings == null)
{
vbsettings = new Microsoft.VisualBasic.Activities.VisualBasicSettings();
}
foreach (Type t in types)
{
vbsettings.ImportReferences.Add(
new Microsoft.VisualBasic.Activities.VisualBasicImportReference
{
Assembly = t.Assembly.GetName().Name,
Import = t.Namespace
});
}
Microsoft.VisualBasic.Activities.VisualBasic.SetSettings(rootObject, vbsettings);
}
public static void AddNamespaceSettings(object rootObject, params Type[] types)
{
Microsoft.VisualBasic.Activities.VisualBasicSettings vbsettings = Microsoft.VisualBasic.Activities.VisualBasic.GetSettings(rootObject);
foreach (Type t in types)
{
vbsettings.ImportReferences.Add(
new Microsoft.VisualBasic.Activities.VisualBasicImportReference
{
Assembly = t.Assembly.GetName().Name,
Import = t.Namespace
});
}
Microsoft.VisualBasic.Activities.VisualBasic.SetSettings(rootObject, vbsettings);
}
}
}