Exemplo n.º 1
0
        /// <summary>
        /// Initializes the WF designer host.
        /// </summary>
        private void InitializeDesigner()
        {
            bool firstTime = (_designer == null);

            _designer = new WorkflowDesigner();

            DesignerConfigurationService dcs = _designer.Context.Services.GetService <DesignerConfigurationService>();

            // Set the runtime Framework version to 4.5
            dcs.TargetFrameworkName = new System.Runtime.Versioning.FrameworkName(".NETFramework", new Version(4, 5));

            // Turn on designer features
            dcs.AnnotationEnabled = true;
            dcs.AutoSurroundWithSequenceEnabled   = true;
            dcs.LoadingFromUntrustedSourceEnabled = true;
            dcs.RubberBandSelectionEnabled        = true;

            // Add the UI
            outlineView.Content          = _designer.OutlineView;
            inspectorPlaceholder.Content = _designer.PropertyInspectorView;
            designerPlaceholder.Content  = _designer.View;

            if (firstTime)
            {
                ToolboxControl toolbox = BuildToolbox();
                toolboxPlaceholder.Content = toolbox;

                (new DesignerMetadata()).Register();
            }

            _designer.Context.Services.Publish <IValidationErrorService>(new ValidationErrorService(ViewModel.Errors));
            _designer.Context.Services.Publish <IExpressionEditorService>(new EditorService());
        }
        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);
        }
Exemplo n.º 3
0
        private void AddDesigner(string fileName = null)
        {
            ////Wait till create Intellisense List
            //while (creating)
            //{
            //    System.Threading.Thread.Sleep(1);
            //}

            //Create an instance of WorkflowDesigner class.
            this.wd = new WorkflowDesigner();

            DesignerConfigurationService configurationService = wd.Context.Services.GetService <DesignerConfigurationService>();

            configurationService.TargetFrameworkName = new FrameworkName(".NETFramework", new System.Version(4, 5));

            configurationService.LoadingFromUntrustedSourceEnabled = true;

            #region Intellisense
            var expEditor = new EditorService()
            {
                IntellisenseData = _inttelisenseList,
                EditorKeyWord    = this.CreateKeywords()
            };

            wd.Context.Services.Publish <IExpressionEditorService>(expEditor);
            #endregion


            wd.Context.Items.Subscribe <Selection>(SelectionChanged);

            //Place the designer canvas in the middle column of the grid.
            Grid.SetColumn(this.wd.View, 1);


            if (fileName == null)
            {
                var activityBuilder = new ActivityBuilder();
                wd.Load(activityBuilder);
                //Load a new Sequence as default.
                activityBuilder.Implementation = new Sequence();
            }
            else
            {
                this.wd.Load(fileName);
            }

            //// view options
            //var designerView = wd.Context.Services.GetService<DesignerView>();

            //designerView.WorkflowShellBarItemVisibility =
            //    ShellBarItemVisibility.Imports |
            //    ShellBarItemVisibility.MiniMap |
            //    ShellBarItemVisibility.Variables |
            //     ShellBarItemVisibility.Arguments | // <-- Uncomment to show again
            //    ShellBarItemVisibility.Zoom;

            DesignerBorder.Child = wd.View;
            PropertyBorder.Child = wd.PropertyInspectorView;
        }
        private void CreateDesigner()
        {
            this.Designer = new WorkflowDesigner();
            //this._expressionEditorService = new RoslynExpressionEditorService();
            //ExpressionTextBox.RegisterExpressionActivityEditor(new CSharpValue<string>().Language, typeof(RoslynExpressionEditor), CSharpExpressionHelper.CreateExpressionFromString);
            //this.Designer.Context.Services.Publish<IExpressionEditorService>(this._expressionEditorService);
            this.Designer.Context.Services.Publish <IValidationErrorService>(new DesignerValidationService());
            DesignerConfigurationService configurationService = Designer.Context.Services.GetService <DesignerConfigurationService>();

            configurationService.TargetFrameworkName = new FrameworkName(".NETFramework", new Version(4, 5));
        }
Exemplo n.º 5
0
        private void Optin45()
        {
            DesignerConfigurationService configService = _workflowDesigner.Context.Services.GetRequiredService <DesignerConfigurationService>();

            configService.AnnotationEnabled  = true; /* maybe, see explanation of TargetFrameworkName*/
            configService.AutoConnectEnabled = true;
            configService.AutoSplitEnabled   = true;
            configService.AutoSurroundWithSequenceEnabled = true;
            configService.BackgroundValidationEnabled     = true;
            configService.MultipleItemsContextMenuEnabled = true;
            configService.MultipleItemsDragDropEnabled    = true;
            configService.NamespaceConversionEnabled      = true;
            configService.PanModeEnabled                    = true;
            configService.RubberBandSelectionEnabled        = true;
            configService.LoadingFromUntrustedSourceEnabled = false;
            configService.TargetFrameworkName               = new FrameworkName(".NETFramework,Version=v4.5");
        }
Exemplo n.º 6
0
        // private static RoslynExpressionEditorService _expressionEditorService;
        // private static EditorService _expressionEditorServiceVB;
        public WFDesigner(ClosableTab tab, Workflow workflow, Type[] extratypes)
        {
            this.tab = tab;
            InitializeComponent();
            ;
            WfToolboxBorder.Child = InitializeActivitiesToolbox();
            Workflow = workflow;
            Workflow.OnIdleOrComplete += onIdleOrComplete;
            wfDesigner = new WorkflowDesigner();

            // Register the runtime metadata for the designer.
            new DesignerMetadata().Register();



            DesignerConfigurationService configService = wfDesigner.Context.Services.GetRequiredService <DesignerConfigurationService>();

            configService.TargetFrameworkName             = new System.Runtime.Versioning.FrameworkName(".NETFramework", new Version(4, 5));
            configService.AnnotationEnabled               = true;
            configService.AutoConnectEnabled              = true;
            configService.AutoSplitEnabled                = true;
            configService.AutoSurroundWithSequenceEnabled = true;
            configService.BackgroundValidationEnabled     = true;
            configService.MultipleItemsContextMenuEnabled = true;
            configService.MultipleItemsDragDropEnabled    = true;
            configService.NamespaceConversionEnabled      = true;
            configService.PanModeEnabled                    = true;
            configService.RubberBandSelectionEnabled        = true;
            configService.LoadingFromUntrustedSourceEnabled = false;

            //if (_expressionEditorServiceVB == null) _expressionEditorServiceVB = new EditorService();
            //wfDesigner.Context.Services.Publish<IExpressionEditorService>(_expressionEditorServiceVB);

            wfDesigner.Context.Services.Publish <IExpressionEditorService>(new EditorService());

            if (!string.IsNullOrEmpty(workflow.Xaml))
            {
                wfDesigner.Text = workflow.Xaml;
                wfDesigner.Load();
                //wfDesigner.Load(workflow.Filename);
            }
            else
            {
                Activity wf = new System.Activities.Statements.Sequence {
                };
                var ab      = new ActivityBuilder();
                ab.Name           = workflow.name;
                ab.Implementation = wf;
                AddVBNamespaceSettings(ab, typeof(Action),
                                       typeof(Microsoft.VisualBasic.Collection),
                                       typeof(System.Xml.XmlNode),
                                       typeof(OpenRPA.Workflow),
                                       typeof(OpenRPA.UIElement),
                                       typeof(System.Data.DataSet),
                                       typeof(System.Linq.Enumerable)
                                       );
                AddVBNamespaceSettings(ab, extratypes);

                //if (workflow.language == entity.workflowLanguage.CSharp)
                //{
                //    System.Activities.Presentation.Expressions.ExpressionActivityEditor.SetExpressionActivityEditor(ab, "C#");
                //}
                wfDesigner.Load(ab);
            }
            HasChanged = false;
            wfDesigner.ModelChanged += (sender, e) =>
            {
                HasChanged = true;
                onChanged?.Invoke(this);
            };

            WfDesignerBorder.Child = wfDesigner.View;
            WfPropertyBorder.Child = wfDesigner.PropertyInspectorView;

            OutputMessages = MainWindow.tracing.OutputMessages;
            TraceMessages  = MainWindow.tracing.TraceMessages;


            var modelItem = wfDesigner.Context.Services.GetService <ModelService>().Root;

            workflow.name = modelItem.GetValue <string>("Name");
            tab.Title     = workflow.name;

            wfDesigner.Context.Items.Subscribe <Selection>(new SubscribeContextCallback <Selection>(SelectionChanged));

            WeakEventManager <System.ComponentModel.INotifyPropertyChanged, System.ComponentModel.PropertyChangedEventArgs> .
            AddHandler(MainWindow.tracing, "PropertyChanged", traceOnPropertyChanged);
        }
Exemplo n.º 7
0
        protected override XamlType GetXamlType(string xamlNamespace, string name, params XamlType[] typeArguments)
        {
            if (!string.IsNullOrEmpty(this.localAssemblyNsPostfix) &&
                IsClrNamespaceWithNoAssembly(xamlNamespace))
            {
                xamlNamespace = AddLocalAssembly(xamlNamespace);
            }

            var xamlType = base.GetXamlType(xamlNamespace, name, typeArguments);

            if (xamlType == null && environmentAssembliesLoaded == false && editingContext != null)
            {
                // Failed to find the type, this might because the namespace is a custom namespace
                //  and the dependent assembly hasn't been loaded yet. Load all dependent assemblies
                //  and try to load the same xaml type again.
                AssemblyContextControlItem assemblyItem = this.editingContext.Items.GetValue <AssemblyContextControlItem>();
                var environmentAssemblies = assemblyItem.GetEnvironmentAssemblies(null);
                if (assemblyItem.LocalAssemblyName != null)
                {
                    AssemblyContextControlItem.GetAssembly(assemblyItem.LocalAssemblyName, null);
                }

                environmentAssembliesLoaded = true;
                xamlType = base.GetXamlType(xamlNamespace, name, typeArguments);
            }

            if (xamlType == null || xamlType.UnderlyingType == null || this.editingContext == null)
            {
                return(xamlType);
            }

            MultiTargetingSupportService multiTargetingService = editingContext.Services.GetService <IMultiTargetingSupportService>() as MultiTargetingSupportService;
            DesignerConfigurationService config = editingContext.Services.GetService <DesignerConfigurationService>();

            if (multiTargetingService == null || config == null)
            {
                return(xamlType);
            }

            // do not filter out new types and new properties if targeting to current framework and it's a full SKU
            if (config.TargetFrameworkName.Version == CurrentFramework.Version && config.TargetFrameworkName.IsFullProfile())
            {
                return(xamlType);
            }

            // Filter out new types and new properties
            if (this.resolverCache == null)
            {
                this.resolverCache = new ResolverCache();
            }

            if (supportedTypes.Contains(xamlType.UnderlyingType))
            {
                return(xamlType);
            }

            // only check if conversion is needed when target framework is less than 4.5
            if (config.TargetFrameworkName.Version < CurrentFramework.Version)
            {
                if (conversionRequiredTypes.Contains(xamlType.UnderlyingType))
                {
                    this.ContainsConversionRequiredType = true;
                    return(xamlType);
                }
            }

            ResolverResult resolverResult = this.resolverCache.Lookup(xamlType.UnderlyingType);

            if (resolverResult == null)
            {
                resolverResult = MultiTargetingTypeResolver.Resolve(multiTargetingService, xamlType.UnderlyingType);
                this.resolverCache.Update(xamlType.UnderlyingType, resolverResult);
            }

            return(MultiTargetingTypeResolver.GetXamlType(resolverResult, xamlType));
        }
Exemplo n.º 8
0
        private void LoadDesignerAndWorkflow(string fileName = null)
        {
            isLoadingXaml = true;
            Encrypt       = false;
            mustSave      = false;

            if (wd != null)
            {
                MainLayout.Children.Remove(this.wd.View);
                MainLayout.Children.Remove(this.wd.PropertyInspectorView);
                this.wd.ModelChanged -= wd_ModelChanged;
                this.wd = null;
            }
            //Create an instance of WorkflowDesigner class.
            this.wd = new WorkflowDesigner();

            DesignerConfigurationService configService = this.wd.Context.Services.GetService <DesignerConfigurationService>();

            configService.TargetFrameworkName = new FrameworkName(".NETFramework", new Version(4, 5));
            configService.LoadingFromUntrustedSourceEnabled = true;

            this.wd.ModelChanged += new EventHandler(wd_ModelChanged);

            //Place the designer canvas in the middle column of the grid.
            Grid.SetRow(this.wd.View, 1);
            Grid.SetColumn(this.wd.View, 2);

            AddPropertyInspector();

            if (string.IsNullOrEmpty(fileName))
            {
                this.wd.Load(new Sequence());
                wd.Flush();
                lastSavedXaml = wd.Text;
                mustSave      = true;
            }
            else
            {
                password = null;
                string errorMessage = null;
                if (XamlFileProviderFactory.IsXamlFileEncrypted(fileName))
                {
                    if (!GetPassword())
                    {
                        errorMessage = string.Format("The file '{0}' is protected and requires the correct password to open.", xamlFile);
                    }
                    else
                    {
                        Encrypt = true;
                    }
                }

                if (string.IsNullOrEmpty(errorMessage))
                {
                    try
                    {
                        IXamlFileProvider provider = XamlFileProviderFactory.GetXamlFileProvider(fileName, password);
                        provider.LoadXamlFile(fileName, password);
                        this.wd.Load(provider.XamlDocument);
                        wd.Flush();
                        lastSavedXaml = wd.Text;
                    }
                    catch (Exception ex)
                    {
                        errorMessage = ex.Message;
                        if (errorMessage == "The encrypted string was not in a valid format.")
                        {
                            errorMessage = "The password you specified was incorrect.";
                        }
                        errorMessage = string.Format("The following error occurred while trying to open '{0}' : \n\n{1}", xamlFile, errorMessage);
                    }
                }
                if (!string.IsNullOrEmpty(errorMessage))
                {
                    xamlFile = string.Empty;
                    ShowErrorMessage(errorMessage, "Failed to load file");
                    this.wd.Load(new Sequence());
                    password = null;
                    mustSave = true;
                    Encrypt  = false;
                }
            }

            busyGettingPassword = true;
            Protect.GetBindingExpression(System.Windows.Controls.Primitives.ToggleButton.IsCheckedProperty).UpdateTarget();
            busyGettingPassword = false;

            //Add the designer canvas to the grid.
            MainLayout.Children.Add(this.wd.View);

            StatusBarText.Text = "";
            ToggleDocumentHasChangesVisual(mustSave);

            isLoadingXaml = false;
        }