Ejemplo n.º 1
0
        public WorkflowViewWrapper()
        {
            this.loader = new Loader();

            // Create a Workflow Design Surface
            this.surface = new DesignSurface();
            this.surface.BeginLoad(this.loader);

            // Get the Workflow Designer Host
            this.Host = this.surface.GetService(typeof(IDesignerHost)) as IDesignerHost;

            if (this.Host == null)
                return;

            // Create a Sequential Workflow by using the Workflow Designer Host
            SequentialWorkflow = (SequentialWorkflowActivity)Host.CreateComponent(typeof(SequentialWorkflowActivity));
            SequentialWorkflow.Name = "CustomOutlookWorkflow";

            // Create a Workflow View on the Workflow Design Surface
            this.workflowView = new WorkflowView(this.surface as IServiceProvider);

            // Add a message filter to the workflow view, to support panning
            MessageFilter filter = new MessageFilter(this.surface as IServiceProvider, this.workflowView);
            this.workflowView.AddDesignerMessageFilter(filter);

            // Activate the Workflow View
            this.Host.Activate();

            this.workflowView.Dock = DockStyle.Fill;
            this.Controls.Add(workflowView);
            this.Dock = DockStyle.Fill;
        }
Ejemplo n.º 2
0
		public void GetActivityByNameAndParent ()
		{
			SequentialWorkflowActivity sq = new SequentialWorkflowActivity ();
			IfElseActivity ifelse_activity = new IfElseActivity ();
			IfElseBranchActivity branch1 = new IfElseBranchActivity ();
			CodeActivity code_branch1 = new CodeActivity ();
			CodeActivity code_branch2 = new CodeActivity ();
			IfElseBranchActivity branch2 = new IfElseBranchActivity ();
			Activity activity;

			code_branch1.Name ="Code1";
			code_branch2.Name ="Code2";
			ifelse_activity.Name = "IfElse";
			sq.Name = "Root";
			branch1.Activities.Add (code_branch1);
			branch2.Activities.Add (code_branch2);
			ifelse_activity.Activities.Add (branch1);
			ifelse_activity.Activities.Add (branch2);
			sq.Activities.Add (ifelse_activity);

			// Getting Code1 activity from root
			activity = sq.GetActivityByName ("Code1", true);
			Assert.AreEqual (code_branch1, activity, "C1#1");

			activity = sq.GetActivityByName ("Code1", false);
			Assert.AreEqual (code_branch1, activity, "C1#2");

			// Getting Root activity from IfElse
			activity = ifelse_activity.GetActivityByName ("Root", true);
			Assert.AreEqual (null, activity, "C1#3");

			activity = ifelse_activity.GetActivityByName ("Root", false);
			Assert.AreEqual (sq, activity, "C1#4");

			// Getting Root activity from Code1
			activity = code_branch1.GetActivityByName ("Root", true);
			Assert.AreEqual (null, activity, "C1#5");

			activity = code_branch1.GetActivityByName ("Root", false);
			Assert.AreEqual (sq, activity, "C1#6");

			// Getting Ifelse activity from Code1
			activity = code_branch1.GetActivityByName ("IfElse", true);
			Assert.AreEqual (null, activity, "C1#7");

			activity = code_branch2.GetActivityByName ("IfElse", false);
			Assert.AreEqual (ifelse_activity, activity, "C1#8");

			// Parent checks
			Assert.AreEqual (ifelse_activity, branch1.Parent, "C1#9");
			Assert.AreEqual (ifelse_activity, branch2.Parent, "C1#10");
			Assert.AreEqual (null, sq.Parent, "C1#11");
		}
Ejemplo n.º 3
0
        // Loads precreated workflow. The function is similar to the above function except
        // instead of creating an empty workflow we create workflow with contents
        internal void LoadDefaultWorkflow()
        {
            Clear();

            this.designSurface = new WorkflowDesignSurface(this);
            WorkflowLoader loader = new WorkflowLoader();
            this.designSurface.BeginLoad(loader);
            
            this.designerHost = GetService(typeof(IDesignerHost)) as IDesignerHost;
            if (this.designerHost != null)
            {
                this.rootActivity = (SequentialWorkflowActivity)this.designerHost.CreateComponent(typeof(SequentialWorkflowActivity));
                this.rootActivity.Name = "Service1";

                CodeActivity codeActivity1 = new CodeActivity();
                this.rootActivity.Activities.Add(codeActivity1);
                this.designerHost.RootComponent.Site.Container.Add(codeActivity1);

                this.workflowView = new WorkflowView(this.designSurface as IServiceProvider);
                this.workflowView.AddDesignerMessageFilter(new CustomMessageFilter(this.designSurface as IServiceProvider, this.workflowView, loader));

                Controls.Add(this.workflowView);
                this.designerHost.Activate();

                ISelectionService selectionService = (ISelectionService)GetService(typeof(ISelectionService));
                if (selectionService != null)
                {
                    selectionService.SelectionChanged += new EventHandler(OnSelectionChanged);
                    IComponent[] selection = new IComponent[] { rootActivity };
                    selectionService.SetSelectedComponents(selection);
                }
            }
        }
Ejemplo n.º 4
0
        public void ShowDefaultWorkflow()
        {
            SequentialWorkflowActivity workflow = new SequentialWorkflowActivity();
            workflow.Name = "Workflow1";

            using (StringWriter stringWriter = new StringWriter())
            {
                using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter))
                {
                    WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
                    serializer.Serialize(xmlWriter, workflow);
                    this.Xaml = stringWriter.ToString();
                }
            }
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {

            Validator validator = (Validator)Activator.CreateInstance(typeof(Validator));
            WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
            DesignerSerializationManager serializationManager = new DesignerSerializationManager();

            using (WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                AutoResetEvent waitHandle = new AutoResetEvent(false);
                workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e)
                {
                    Console.WriteLine("Workflow completed.");
                    waitHandle.Set();
                };
                workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                {
                    Console.WriteLine(e.Exception.Message);
                    waitHandle.Set();
                };

                //
                // Create queue workflow programmatically
                //
                Console.WriteLine("Creating workflow.");
                SequentialWorkflowActivity workflow = new SequentialWorkflowActivity();
                workflow.Name = "Programmatically created workflow";
                workflow.Description = "Programmatically created workflow for XAML activation";

                // Add Queue activity
                QueueActivity queueActivity = new QueueActivity();
                queueActivity.Name = "QueueActivity1";

                // Enqueue data
                queueActivity.NameQueue.Enqueue("Queue item 1");
                queueActivity.NameQueue.Enqueue("Queue item 2");
                queueActivity.NameQueue.Enqueue("Queue item 3");
                workflow.Activities.Add(queueActivity);

                // Add Stack activity
                StackActivity stackActivity = new StackActivity();
                stackActivity.Name = "StackActivity1";

                // Push data
                stackActivity.NameStack.Push("Stack item 1");
                stackActivity.NameStack.Push("Stack item 2");
                stackActivity.NameStack.Push("Stack item 3");
                workflow.Activities.Add(stackActivity);

                //
                // Serialize workflow to XAML file
                //
                Console.WriteLine("Serializing workflow to file.");
                using (XmlWriter writer = XmlWriter.Create(workflowFilename))
                {
                    using (serializationManager.CreateSession())
                    {
                        serializer.Serialize(serializationManager, writer, workflow);
                        if (serializationManager.Errors.Count > 0)
                        {
                            Console.WriteLine(String.Format("There were {0} errors during serialization", serializationManager.Errors.Count));
                            return;
                        }
                    }
                }

                //
                // Create workflow instance from file
                //
                Console.WriteLine("Deserializing workflow from file.");
                WorkflowInstance workflowInstance;
                using (XmlReader reader = XmlReader.Create(workflowFilename))
                {
                    try
                    {
                        workflowInstance = workflowRuntime.CreateWorkflow(reader);
                    }
                    catch (WorkflowValidationFailedException e)
                    {
                        Console.WriteLine("Validation errors found.  Exiting.");
                        foreach (ValidationError validationError in e.Errors)
                        {
                            Console.WriteLine(validationError.ErrorText);
                        }
                        return;
                    }
                }

                //
                // Execute workflow
                //
                Console.WriteLine("Starting workflow.");
                workflowInstance.Start();
                waitHandle.WaitOne();
                workflowRuntime.StopRuntime();
            }
        }
Ejemplo n.º 6
0
        static void Main(string[] args)
        {
            const string workflowFilename = "workflow.xoml";

            //
            // Create and configure workflow runtime
            //
            using(WorkflowRuntime workflowRuntime = new WorkflowRuntime())
            {
                AutoResetEvent waitHandle = new AutoResetEvent(false);
                workflowRuntime.WorkflowCompleted += delegate(object sender, WorkflowCompletedEventArgs e) 
                {
                    Console.WriteLine("Workflow completed.");
                    waitHandle.Set();
                };
                workflowRuntime.WorkflowTerminated += delegate(object sender, WorkflowTerminatedEventArgs e)
                {
                    Console.WriteLine(e.Exception.Message);
                    waitHandle.Set();
                };

                //
                // Create workflow programmatically
                //
                Console.WriteLine("Creating workflow.");
                SequentialWorkflowActivity workflow = new SequentialWorkflowActivity();
                workflow.Name = "Programmatically created workflow";
                workflow.Description = "Programmatically created workflow for XAML activation";
                ConsoleActivity activity = new ConsoleActivity();
                activity.Name = "ConsoleActivity1";
                activity.StringToWrite = "Sample String";
                workflow.Activities.Add(activity);
                
                //
                // Serialize workflow to XAML file
                //
                Console.WriteLine("Serializing workflow to file.");
                WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
                using (XmlWriter writer = XmlWriter.Create(workflowFilename))
                {
                    DesignerSerializationManager serializationManager = new DesignerSerializationManager();
                    using (serializationManager.CreateSession())
                    {
                        serializer.Serialize(serializationManager, writer, workflow);
                        if (serializationManager.Errors.Count > 0)
                        {
                            Console.WriteLine(String.Format("There were {0} errors during serialization", serializationManager.Errors.Count));
                            return;
                        }
                    }
                }

                //
                // Deserialize workflow from file
                //
                WorkflowInstance deserializedWorkflow = null;
                Console.WriteLine("Deserializing workflow from file.");
                try
                {

                    using (XmlReader reader = XmlReader.Create(workflowFilename))
                    {
                        deserializedWorkflow = workflowRuntime.CreateWorkflow(reader);
                    }
                }
                catch (WorkflowValidationFailedException exp)
                {
                    ValidationErrorCollection list = exp.Errors;
                    foreach (ValidationError err in list)
                    {
                        Console.WriteLine(err.ErrorText);
                    }
                    return;
                }


                //
                // Start workflow
                //
                Console.WriteLine("Starting workflow.");
                deserializedWorkflow.Start();
           
                waitHandle.WaitOne();

                workflowRuntime.StopRuntime();
            }
        }