|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Xml.Linq; |
| 4 | + |
| 5 | +namespace OptimaJet.Workflow.Core.Generator |
| 6 | +{ |
| 7 | + public class TTXmlWorkflowGenerator : IWorkflowGenerator<XElement> |
| 8 | + { |
| 9 | + protected IDictionary<string,Type> TemplateTypeMapping = new Dictionary<string, Type>(); |
| 10 | + |
| 11 | + public XElement Generate(string SchemeCode, Guid schemeId, IDictionary<string, object> parameters) |
| 12 | + { |
| 13 | + var processTemplateType = TemplateTypeMapping[SchemeCode.ToLower()]; |
| 14 | + var sessionProperty = processTemplateType.GetProperty("Session", typeof(IDictionary<string, object>)); |
| 15 | + var transformTextMethod = processTemplateType.GetMethod("TransformText"); |
| 16 | + var initializeMethod = processTemplateType.GetMethod("Initialize"); |
| 17 | + var obj = Activator.CreateInstance(processTemplateType, false); |
| 18 | + |
| 19 | + var session = (IDictionary<string, object>)sessionProperty.GetGetMethod(false).Invoke(obj,new object[]{}); |
| 20 | + |
| 21 | + if (session == null) |
| 22 | + { |
| 23 | + session = new Dictionary<string, object>(); |
| 24 | + sessionProperty.GetSetMethod(false).Invoke(obj, new object[] {session}); |
| 25 | + } |
| 26 | + |
| 27 | + session.Clear(); |
| 28 | + |
| 29 | + foreach (var parameter in parameters) |
| 30 | + session.Add(parameter.Key,parameter.Value); |
| 31 | + |
| 32 | + session.Add("SchemeId",schemeId); |
| 33 | + |
| 34 | + initializeMethod.Invoke(obj, new object[] {}); |
| 35 | + |
| 36 | + var output = (string) transformTextMethod.Invoke(obj, new object[] {}); |
| 37 | + |
| 38 | + return XElement.Parse(output); |
| 39 | + } |
| 40 | + |
| 41 | + public void AddMapping(string SchemeCode, object generatorSource) |
| 42 | + { |
| 43 | + var type = generatorSource as Type; |
| 44 | + if (type == null) |
| 45 | + throw new InvalidOperationException(); |
| 46 | + TemplateTypeMapping.Add(SchemeCode.ToLower(), type); |
| 47 | + } |
| 48 | + } |
| 49 | + |
| 50 | + |
| 51 | +} |
0 commit comments