private void AddDesigner() { //Create an instance of WorkflowDesigner class. this.workflowDesigner = new WorkflowDesigner(); //Place the designer canvas in the middle column of the grid. Grid.SetColumn(this.workflowDesigner.View, 1); Grid.SetRow(this.workflowDesigner.View, 1); this.expressionEditorService = new RoslynExpressionEditorService(); ExpressionTextBox.RegisterExpressionActivityEditor(new CSharpValue <string>().Language, typeof(RoslynExpressionEditor), CSharpExpressionHelper.CreateExpressionFromString); this.workflowDesigner.Context.Services.Publish <IExpressionEditorService>(this.expressionEditorService); //To avoid loading the default VB expression editor DesignerConfigurationService configurationService = this.workflowDesigner.Context.Services.GetService <DesignerConfigurationService>(); configurationService.TargetFrameworkName = new FrameworkName(".NETFramework", new System.Version(4, 5)); configurationService.LoadingFromUntrustedSourceEnabled = true; //Load a new Sequence as default. this.workflowDesigner.Load("StartingWorkflow.xml"); //Add the designer canvas to the grid. grid1.Children.Add(this.workflowDesigner.View); }
/// <summary> /// Creates a new Workflow Designer instance with C# Expression Editor /// </summary> /// <param name="sourceFile">Workflow FileName</param> public static void NewInstanceCSharp(string sourceFile = _defaultWorkflowCSharp) { _expressionEditorService = new RoslynExpressionEditorService(); ExpressionTextBox.RegisterExpressionActivityEditor(new CSharpValue <string>().Language, typeof(RoslynExpressionEditor), CSharpExpressionHelper.CreateExpressionFromString); _wfDesigner = new WorkflowDesigner(); _wfDesigner.Context.Services.GetService <DesignerConfigurationService>().TargetFrameworkName = new System.Runtime.Versioning.FrameworkName(".NETFramework", new Version(4, 5)); _wfDesigner.Context.Services.GetService <DesignerConfigurationService>().LoadingFromUntrustedSourceEnabled = true; _wfDesigner.Context.Services.Publish <IExpressionEditorService>(_expressionEditorService); //associates all of the basic activities with their designers new DesignerMetadata().Register(); //load Workflow Xaml _wfDesigner.Load(sourceFile); SelectHelper._wfDesigner = _wfDesigner; if (!SelectHelper.WorkflowDictionary.ContainsKey(sourceFile)) { SelectHelper.WorkflowDictionary.Add(sourceFile, _wfDesigner); } else { SelectHelper.WorkflowDictionary[sourceFile] = _wfDesigner; } if (!SelectHelper.RuntimeApplicationHelperDictionary.ContainsKey(sourceFile)) { SelectHelper.RuntimeApplicationHelperDictionary.Add(sourceFile, new RuntimeApplicationHelper()); } }
/// <summary> /// Creates a new Workflow Designer instance with C# Expression Editor /// </summary> /// <param name="sourceFile">Workflow FileName</param> public static WorkflowDesigner NewInstance(string sourceFile = _defaultActivity) { if (string.IsNullOrWhiteSpace(sourceFile)) { sourceFile = Path.Combine(AssemblyDirectory, _defaultActivity); } var expressionEditorService = new RoslynExpressionEditorService(); ExpressionTextBox.RegisterExpressionActivityEditor(new CSharpValue <string>().Language, typeof(RoslynExpressionEditor), CSharpExpressionHelper.CreateExpressionFromString); var wfDesigner = new WorkflowDesigner(); var dcs = wfDesigner.Context.Services.GetService <DesignerConfigurationService>(); dcs.TargetFrameworkName = new System.Runtime.Versioning.FrameworkName(".NETFramework", new Version(4, 6, 1)); dcs.LoadingFromUntrustedSourceEnabled = true; wfDesigner.Context.Services.Publish <IExpressionEditorService>(expressionEditorService); //associates all of the basic activities with their designers new DesignerMetadata().Register(); string temp = File.ReadAllText(Path.Combine(AssemblyDirectory, @"colors.xaml")); StringReader reader = new StringReader(temp); XmlReader xmlReader = XmlReader.Create(reader); ResourceDictionary fontAndColorDictionary = (ResourceDictionary)System.Windows.Markup.XamlReader.Load(xmlReader); //var keys = GetColorKeys(); //foreach (var key in keys) //{ // fontAndColorDictionary[key] = Brushes.Pink; //} Hashtable hashTable = new Hashtable(); foreach (var key in fontAndColorDictionary.Keys) { hashTable.Add(key, fontAndColorDictionary[key]); } wfDesigner.PropertyInspectorFontAndColorData = XamlServices.Save(hashTable); //load Workflow Xaml wfDesigner.Load(sourceFile); //var g = wfDesigner.View as Grid; //g.Background = Brushes.Pink; return(wfDesigner); }
// Called by the designer to register design-time metadata. public void Register() { AttributeTableBuilder builder = new AttributeTableBuilder(); // Register Designers. builder.AddCustomAttributes(typeof(Activity), new DesignerAttribute(typeof(ActivityDesigner))); builder.AddCustomAttributes(typeof(ActivityBuilder), new DesignerAttribute(typeof(ActivityTypeDesigner))); builder.AddCustomAttributes(typeof(ActivityBuilder <>), new DesignerAttribute(typeof(GenericActivityTypeDesigner))); // Register PropertyValueEditors builder.AddCustomAttributes(typeof(Argument), new EditorAttribute(typeof(ExpressionValueEditor), typeof(PropertyValueEditor))); builder.AddCustomAttributes(typeof(Type), PropertyValueEditor.CreateEditorAttribute(typeof(TypePropertyEditor))); builder.AddCustomAttributes(typeof(Activity <>), new EditorAttribute(typeof(ExpressionValueEditor), typeof(PropertyValueEditor))); // Disable reuse of propertyvalueeditors for Arguments builder.AddCustomAttributes(typeof(Argument), new EditorReuseAttribute(false)); builder.AddCustomAttributes(typeof(Activity <>), new EditorReuseAttribute(false)); //Removing all the properties except "Name" from property grid for the type SchemaType. foreach (MemberInfo mi in typeof(ActivityBuilder).GetMembers()) { if (mi.MemberType == MemberTypes.Property && !mi.Name.Equals("Name") && !mi.Name.Equals("ImplementationVersion")) { builder.AddCustomAttributes(typeof(ActivityBuilder), mi, new BrowsableAttribute(false)); } } // Removing all the properties property grid for the type SchemaType. foreach (MemberInfo mi in typeof(ActivityBuilder <>).GetMembers()) { builder.AddCustomAttributes(typeof(ActivityBuilder <>), mi, new BrowsableAttribute(false)); } builder.AddCustomAttributes(typeof(Argument), new SearchableStringConverterAttribute(typeof(ArgumentSearchableStringConverter))); builder.AddCustomAttributes(typeof(VisualBasicValue <>), new SearchableStringConverterAttribute(typeof(VisualBasicValueSearchableStringConverter))); builder.AddCustomAttributes(typeof(Type), new SearchableStringConverterAttribute(typeof(TypeSearchableStringConverter))); builder.AddCustomAttributes(typeof(ActivityAction <>), new SearchableStringConverterAttribute(typeof(ActivityActionSearchableStringConverter <>))); builder.AddCustomAttributes(typeof(XName), new SearchableStringConverterAttribute(typeof(XNameSearchableStringConverter))); builder.AddCustomAttributes(typeof(Encoding), new SearchableStringConverterAttribute(typeof(EncodingSearchableStringConverter))); builder.AddCustomAttributes(typeof(ErrorActivity), new SearchableStringConverterAttribute(typeof(EmptySearchableStringConverter))); builder.AddCustomAttributes(typeof(XName), new TypeConverterAttribute(typeof(XNameConverter))); builder.AddCustomAttributes(typeof(VBIdentifierName), new EditorAttribute(typeof(VBIdentifierNameEditor), typeof(PropertyValueEditor))); builder.AddCustomAttributes(typeof(VBIdentifierName), new EditorReuseAttribute(false)); ExpressionTextBox.RegisterExpressionActivityEditor(VisualBasicEditor.ExpressionLanguageName, typeof(VisualBasicEditor), VisualBasicEditor.CreateExpressionFromString); builder.AddCustomAttributes(typeof(VisualBasicValue <>), new ExpressionMorphHelperAttribute(typeof(VisualBasicExpressionMorphHelper))); builder.AddCustomAttributes(typeof(VisualBasicReference <>), new ExpressionMorphHelperAttribute(typeof(VisualBasicExpressionMorphHelper))); builder.AddCustomAttributes(typeof(VisualBasicValue <>), new FeatureAttribute(typeof(VisualBasicValueValidationFeature))); builder.AddCustomAttributes(typeof(VisualBasicReference <>), new FeatureAttribute(typeof(VisualBasicReferenceValidationFeature))); builder.AddCustomAttributes(typeof(Literal <>), new ExpressionMorphHelperAttribute(typeof(NonTextualExpressionMorphHelper))); builder.AddCustomAttributes(typeof(VariableValue <>), new ExpressionMorphHelperAttribute(typeof(NonTextualExpressionMorphHelper))); builder.AddCustomAttributes(typeof(VariableReference <>), new ExpressionMorphHelperAttribute(typeof(NonTextualExpressionMorphHelper))); builder.AddCustomAttributes(typeof(Activity), new ShowInOutlineViewAttribute()); builder.AddCustomAttributes(typeof(Collection <Activity>), new ShowInOutlineViewAttribute()); Type type = typeof(ActivityDelegate); builder.AddCustomAttributes(type, new ShowInOutlineViewAttribute() { PromotedProperty = "Handler" }); type = typeof(ActivityBuilder); builder.AddCustomAttributes(type, new ShowInOutlineViewAttribute()); builder.AddCustomAttributes(type, type.GetProperty("Implementation"), new ShowPropertyInOutlineViewAttribute() { CurrentPropertyVisible = false }); type = typeof(WorkflowService); builder.AddCustomAttributes(type, type.GetProperty("Body"), new ShowPropertyInOutlineViewAttribute() { CurrentPropertyVisible = false }); builder.AddCustomAttributes(typeof(WorkflowIdentity), new TypeConverterAttribute(typeof(ExpandableObjectConverter))); builder.AddCustomAttributes(typeof(Version), new EditorAttribute(typeof(VersionPropertyValueEditor), typeof(PropertyValueEditor))); // Apply the metadata MetadataStore.AddAttributeTable(builder.CreateTable()); }