/// <summary> /// The add imports. /// </summary> /// <param name="activity"> /// The activity. /// </param> /// <returns> /// </returns> internal static Activity AddImports(Activity activity) { var settings = new VisualBasicSettings(); settings.ImportReferences.Add( new VisualBasicImportReference { Assembly = "Microsoft.ApplicationServer.Http", Import = "Microsoft.ApplicationServer.Http" }); settings.ImportReferences.Add( new VisualBasicImportReference { Assembly = "Microsoft.ApplicationServer.Http", Import = "Microsoft.ApplicationServer.Http.Dispatcher" }); settings.ImportReferences.Add( new VisualBasicImportReference { Assembly = "System", Import = "System.Net" }); settings.ImportReferences.Add( new VisualBasicImportReference { Assembly = "Microsoft.Net.Http", Import = "System.Net.Http" }); VisualBasic.SetSettings(activity, settings); return(activity); }
internal static void SetVisualBasicSettings(object root, VisualBasicSettings settings) { if (NamespaceHelper.ShouldUsePropertiesForImplementation(root)) { VisualBasic.SetSettingsForImplementation(root, settings); } else { VisualBasic.SetSettings(root, settings); } }
/// <summary> /// Adds a setting to the activity provided which ensures visual basic-style declarations are interpreted correctly /// </summary> internal static void AddVbSetting(Activity activity) { var settings = new VisualBasicSettings { ImportReferences = { new VisualBasicImportReference { Assembly = typeof(Person).Assembly.GetName().Name, Import = typeof(Person).Namespace } } }; VisualBasic.SetSettings(activity, settings); }
public void SetNamespaces(object target) { var dev2ActivitiesAssembly = typeof(WorkflowHelper).Assembly; var dev2CommonAssembly = typeof(GlobalConstants).Assembly; var dev2DataAssembly = typeof(Dev2DataListDecisionHandler).Assembly; var namespaces = new Dictionary <string, Assembly> { { "Dev2.Common", dev2CommonAssembly }, { "Dev2.Data.Decisions.Operations", dev2DataAssembly }, { "Dev2.Data.SystemTemplates.Models", dev2DataAssembly }, { "Dev2.DataList.Contract", dev2DataAssembly }, { "Dev2.DataList.Contract.Binary_Objects", dev2DataAssembly }, { "Unlimited.Applications.BusinessDesignStudio.Activities", dev2ActivitiesAssembly } }; #region Set C# assembly references // http://stackoverflow.com/questions/16086612/wf-4-5-using-c-sharp-expressions-with-external-class-references // http://blogs.msdn.com/b/tilovell/archive/2012/05/25/wf4-5-using-csharpvalue-lt-t-gt-and-csharpreference-lt-t-gt-in-net-4-5-compiling-expressions-and-changes-in-visual-studio-generated-xaml.aspx TextExpression.SetReferencesForImplementation(target, namespaces.Values.Distinct().Select(a => new AssemblyReference { Assembly = a }).ToArray()); var impl = new AttachableMemberIdentifier(typeof(TextExpression), "NamespacesForImplementation"); AttachablePropertyServices.SetProperty(target, impl, namespaces.Keys.ToList()); #endregion #region Set VB assembly references var vbSettings = VisualBasic.GetSettings(target) ?? new VisualBasicSettings(); vbSettings.ImportReferences.Clear(); foreach (var ns in namespaces.Keys) { vbSettings.ImportReferences.Add(new VisualBasicImportReference { Assembly = namespaces[ns].GetName().Name, Import = ns }); } VisualBasic.SetSettings(target, vbSettings); #endregion }
static DynamicActivity GetDynamicActivity(ActivityBuilder activityDefinition) { DynamicActivity result = new DynamicActivity { Name = activityDefinition.Name }; foreach (DynamicActivityProperty property in activityDefinition.Properties) { result.Properties.Add(property); } foreach (Attribute attrib in activityDefinition.Attributes) { result.Attributes.Add(attrib); } foreach (Constraint constraint in activityDefinition.Constraints) { result.Constraints.Add(constraint); } result.Implementation = () => activityDefinition.Implementation; VisualBasicSettings vbsettings = VisualBasic.GetSettings(activityDefinition); if (vbsettings != null) { VisualBasic.SetSettings(result, vbsettings); } IList <string> namespacesForImplementation = TextExpression.GetNamespacesForImplementation(activityDefinition); if (namespacesForImplementation.Count > 0) { TextExpression.SetNamespacesForImplementation(result, namespacesForImplementation); } IList <AssemblyReference> referencesForImplementation = TextExpression.GetReferencesForImplementation(activityDefinition); if (referencesForImplementation.Count > 0) { TextExpression.SetReferencesForImplementation(result, referencesForImplementation); } return(result); }
private static DynamicActivity GetDynamicActivity(ActivityBuilder activityDefinition) { var result = new DynamicActivity { Name = activityDefinition.Name }; foreach (var property in activityDefinition.Properties) { result.Properties.Add(property); } foreach (var attrib in activityDefinition.Attributes) { result.Attributes.Add(attrib); } foreach (var constraint in activityDefinition.Constraints) { result.Constraints.Add(constraint); } result.Implementation = () => activityDefinition.Implementation; var vbsettings = VisualBasic.GetSettings(activityDefinition); if (vbsettings != null) { VisualBasic.SetSettings(result, vbsettings); } var namespacesForImplementation = TextExpression.GetNamespacesForImplementation(activityDefinition); if (namespacesForImplementation.Count > 0) { TextExpression.SetNamespacesForImplementation(result, namespacesForImplementation); } var referencesForImplementation = TextExpression.GetReferencesForImplementation(activityDefinition); if (referencesForImplementation.Count > 0) { TextExpression.SetReferencesForImplementation(result, referencesForImplementation); } return(result); }
/// <summary> /// Creates a DynamicActivityProperty for each argument and variable in the current context. /// </summary> /// <param name="context"></param> /// <returns></returns> private Activity CreateDynamicActivity(AsyncCodeActivityContext context) { DynamicActivity result = new DynamicActivity(); foreach (DynamicActivityProperty dap in context.DataContext.GetProperties() .Cast <PropertyDescriptor>() .Select(property => new DynamicActivityProperty { Name = property.Name, Type = typeof(InArgument <>).MakeGenericType(property.PropertyType) })) { dap.Value = Activator.CreateInstance(dap.Type); result.Properties.Add(dap); } VisualBasic.SetSettings(result, VisualBasic.GetSettings(this)); result.Implementation = () => Body.Handler; return(result); }
public static ActivityBuilder ToBuilder(DynamicActivity dynamicActivity) { var activityBuilder = new ActivityBuilder { Implementation = dynamicActivity.Implementation != null?dynamicActivity.Implementation() : null, Name = dynamicActivity.Name }; foreach (var item in dynamicActivity.Attributes) { activityBuilder.Attributes.Add(item); } foreach (var item in dynamicActivity.Constraints) { activityBuilder.Constraints.Add(item); } foreach (var item in dynamicActivity.Properties) { var property = new DynamicActivityProperty { Name = item.Name, Type = item.Type, Value = null }; foreach (var attribute in item.Attributes) { property.Attributes.Add(attribute); } activityBuilder.Properties.Add(property); } VisualBasic.SetSettings(activityBuilder, VisualBasic.GetSettings(dynamicActivity)); return(activityBuilder); }
internal static void ConvertActivityBuilderToDynamicActivity(ActivityBuilder activityBuilder, DynamicActivity bodyPlaceholder) { bodyPlaceholder.Name = activityBuilder.Name; bodyPlaceholder.Implementation = () => activityBuilder.Implementation; if (activityBuilder.Implementation != null) { VisualBasic.SetSettings(bodyPlaceholder, VisualBasic.GetSettings(activityBuilder)); } bodyPlaceholder.Attributes.Clear(); foreach (Attribute attribute in activityBuilder.Attributes) { bodyPlaceholder.Attributes.Add(attribute); } bodyPlaceholder.Properties.Clear(); foreach (DynamicActivityProperty property in activityBuilder.Properties) { bodyPlaceholder.Properties.Add(property); } }
private void AddDynamicAssembly(Assembly asm) { AssemblyContextControlItem acci = (AssemblyContextControlItem)(_WorkflowDesigner.Context.Items.GetValue(typeof(AssemblyContextControlItem))); var root = GetRootElement(); var fullname = asm.FullName; if (null == root) { return; } VisualBasicSettings vbs = VisualBasic.GetSettings(root) ?? new VisualBasicSettings(); var namespaces = (from type in asm.GetTypes() select type.Namespace).Distinct(); foreach (var name in namespaces) { var import = new VisualBasicImportReference() { Assembly = fullname, Import = name }; vbs.ImportReferences.Add(import); } VisualBasic.SetSettings(root, vbs); }
private string buildXaml(PD_Process process, PD_Subject subject) { Flowchart flow = new Flowchart(); Variable flowGlobalTransition = new Variable <String> { Name = "GlobalTransition" }; Variable flowGlobalVariables = new Variable <DynamicValue> { Name = "GlobalVariables" }; string globVariablesInit = ""; if (subject.GlobalParameters.Count > 0) { globVariablesInit = "{"; foreach (string p in subject.GlobalParameters) { var par = _pdesignerDB.PD_Parameters.Find(subject.PD_Process_Id, p); globVariablesInit = globVariablesInit + "\"" + p + "\":" + par.Config + ","; } globVariablesInit = globVariablesInit.Remove(globVariablesInit.Length - 1, 1); globVariablesInit = globVariablesInit + "}"; } Variable flowGlobalVariablesSchema = new Variable <string> { Name = "GlobalVariablesSchema", Default = globVariablesInit }; Dictionary <int, FlowStep> nodeList = new Dictionary <int, System.Activities.Statements.FlowStep>(); flow.Variables.Add(flowGlobalTransition); flow.Variables.Add(flowGlobalVariables); flow.Variables.Add(flowGlobalVariablesSchema); foreach (var state in subject.States) { FlowStep f; if (state.Type == PD_StateTypes.FunctionState) { var s = (PD_FunctionState)state; string timeout = ""; try { var timeouttransition = subject.Transitions.First(result => result.Source == s.Id && result.Type == PD_TransitionTypes.TimeoutTransition); timeout = ((PD_TimeoutTransition)timeouttransition).TimeSpan; } catch (Exception e) { } var transitions = subject.Transitions.Where(result => result.Source == s.Id && result.Type == PD_TransitionTypes.RegularTransition); List <string> titems = new List <string>(); transitions.ToList().ForEach(i => titems.Add(((PD_RegularTransition)i).Name)); f = new FlowStep() { Action = new FunctionStateT() { DisplayName = s.Name, OrderId = s.Id, name = s.Name, GlobalTransition = new OutArgument <string>(flowGlobalTransition), GlobalVariables = new InOutArgument <DynamicValue>(flowGlobalVariables), isEndState = s.EndState, readableParameters = collectionToString(s.ReadableParameters), editableParameters = collectionToString(s.EditableParameters), TimeOut = timeout, transitions = collectionToString(titems) } }; } else if (state.Type == PD_StateTypes.SendState) { var s = (PD_SendState)state; string timeout = ""; try { var timeouttransition = subject.Transitions.First(result => result.Source == s.Id && result.Type == PD_TransitionTypes.TimeoutTransition); timeout = ((PD_TimeoutTransition)timeouttransition).TimeSpan; } catch (Exception e) { } var message = process.Messages.First(result => result.Id == s.Message); string to = process.Subjects.First(result => result.Id == message.To).Name; f = new FlowStep() { Action = new SendStateT() { DisplayName = s.Name, OrderId = s.Id, name = s.Name, GlobalTransition = new OutArgument <string>(flowGlobalTransition), GlobalVariables = new InOutArgument <DynamicValue>(flowGlobalVariables), isEndState = s.EndState, readableParameters = collectionToString(s.ReadableParameters), editableParameters = collectionToString(s.EditableParameters), messageType = message.PD_MessageType.Name, parameters = collectionToString(message.PD_MessageType.Parameters), toSubject = to, TimeOut = timeout } }; } else //(state.Type == PD_StateTypes.ReceiveState) { var s = (PD_ReceiveState)state; string messages = ""; List <string> messagelist = new List <string>(); var receivetransitions = subject.Transitions.Where(result => result.Source == s.Id && result.Type == PD_TransitionTypes.ReceiveTransition); foreach (var i in receivetransitions) { messagelist.Add(receiveTranstionToString(process, (PD_ReceiveTransition)i)); } messages = collectionToString(messagelist); string timeout = ""; try { var timeouttransition = subject.Transitions.First(result => result.Source == s.Id && result.Type == PD_TransitionTypes.TimeoutTransition); timeout = ((PD_TimeoutTransition)timeouttransition).TimeSpan; } catch (Exception e) { } f = new FlowStep() { Action = new ReceiveStateT() { DisplayName = s.Name, OrderId = s.Id, name = s.Name, GlobalTransition = new OutArgument <string>(flowGlobalTransition), GlobalVariables = new InOutArgument <DynamicValue>(flowGlobalVariables), isEndState = s.EndState, TimeOut = timeout, messages = messages } }; } flow.Nodes.Add(f); nodeList.Add(state.Id, f); } var initGP = new FlowStep() { Action = new InitializeGlobalParameters() { DisplayName = "init GP", DynamicVal = new InOutArgument <DynamicValue>(flowGlobalVariables), GlobalParameterSchema = new InArgument <string>(flowGlobalVariablesSchema) } }; initGP.Next = nodeList[subject.States.First(result => result.StartState == true).Id]; flow.StartNode = initGP; // flow.StartNode = nodeList[subject.States.First(result => result.StartState == true).Id]; foreach (var state in subject.States) { List <PD_Transition> transitions = new List <PD_Transition>(); try { subject.Transitions.Where(result => result.Source == state.Id).ToList().ForEach(item => transitions.Add(item)); } catch (Exception e) { } if (transitions.Count > 0) { if (transitions.Count == 1) { var t = transitions[0]; nodeList[t.Source].Next = nodeList[t.Target]; } else { FlowSwitch <String> newSwitch = new FlowSwitch <String> { Expression = flowGlobalTransition }; flow.Nodes.Add(newSwitch); nodeList[state.Id].Next = newSwitch; try { var timeouttransition = transitions.First(result => result.Type == PD_TransitionTypes.TimeoutTransition); newSwitch.Cases.Add("TimeOut!", nodeList[timeouttransition.Target]); transitions.Remove(timeouttransition); } catch (Exception e) { } if (state.Type == PD_StateTypes.SendState) { newSwitch.Default = nodeList[transitions[0].Target]; } else if (state.Type == PD_StateTypes.ReceiveState) { foreach (var t in transitions) { newSwitch.Cases.Add(receiveTranstionToString(process, (PD_ReceiveTransition)t), nodeList[t.Target]); } } else { foreach (var t in transitions) { newSwitch.Cases.Add(((PD_RegularTransition)t).Name, nodeList[t.Target]); } } } } } ActivityBuilder builder = new ActivityBuilder(); builder.Name = "strICT.InFlowTest.WFProcesses." + process.Name + "." + subject.Name; builder.Implementation = flow; VisualBasic.SetSettings(builder, new VisualBasicSettings()); //StringBuilder sb = new StringBuilder(); StringWriterUtf8 stream = new StringWriterUtf8(); XamlWriter writer = ActivityXamlServices.CreateBuilderWriter(new XamlXmlWriter(stream, new XamlSchemaContext())); XamlServices.Save(writer, builder); string res = stream.GetStringBuilder().ToString(); res = res.Replace("<?xml version=\"1.0\" encoding=\"utf-8\"?>", ""); return(res); }