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; }
// 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); } } }
private void OnListBoxDoubleClick(object sener, EventArgs e) { IToolboxUser docDes = null; SelfHostToolboxItem selectedItem = listBox.SelectedItem as SelfHostToolboxItem; if (selectedItem == null) { return; } this.currentSelection = selectedItem.ComponentType; IDesignerHost host = (IDesignerHost)provider.GetService(typeof(IDesignerHost)); //des.ActiveDesigner; if (host != null && this.currentSelection != null) { IDesigner designer = host.GetDesigner(host.RootComponent); if (designer is IToolboxUser) { docDes = (IToolboxUser)designer; } if (docDes != null) { ToolboxItem c = ToolboxService.GetToolboxItem(this.currentSelection); Debug.Assert(c != null, "Class " + this.currentSelection.FullName + " does not exist"); if (c != null && docDes.GetToolSupported(c)) { try { docDes.ToolPicked(c); } catch (Exception ex) { IUIService uis = (IUIService)provider.GetService(typeof(IUIService)); if (uis != null) { uis.ShowError(ex); } else { MessageBox.Show("Error: " + ex.ToString()); } } } } else { object o = Activator.CreateInstance(this.currentSelection); SequentialWorkflowActivity service = host.RootComponent as SequentialWorkflowActivity; service.Activities.Add(o as Activity); host.RootComponent.Site.Container.Add(o as IComponent); } } }
/// <summary> /// Handles the Click event of the btnDelete control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void btnDelete_Click(object sender, ImageClickEventArgs e) { SequentialWorkflowActivity root = this.CurrentContainer.CurrentRootActivity; Activity ac = root.GetActivityByName(CurrentActivity.Name); if (ac.Parent != null) { ac.Parent.Activities.Remove(ac); } CurrentContainer.CurrentRootActivity = root; this.CurrentContainer.PerformControls(); }
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"); }
protected void Page_Load(object sender, EventArgs e) { Response.Redirect("~/Modules/Pages/WorkflowList.aspx"); WorkflowDefinitionEntity en = BusinessManager.InitializeEntity <WorkflowDefinitionEntity>(WorkflowDefinitionEntity.ClassName); SequentialWorkflowActivity item = McWorkflowSerializer.GetObject <SequentialWorkflowActivity>(en.Xaml); CreateAssignmentAndWaitResultActivity act1 = new CreateAssignmentAndWaitResultActivity(); act1.Name = "Guid1"; //act1.Subject =" Subject Here " ; //a //item.Activities.Add(act1); }
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(); } } }
public void CreateNewWorkflow() { SequentialWorkflowActivity rootActivity = new SequentialWorkflowActivity("root"); rootActivity.SetValue(WorkflowMarkupSerializer.XClassProperty, WorkflowTypeFactory.GetWorkflowClassFullName(Workflow)); StringBuilder sb = new StringBuilder(); XmlWriter xmlWriter = XmlWriter.Create(sb); WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer(); serializer.Serialize(xmlWriter, rootActivity); xmlWriter.Close(); Workflow.WorkflowXoml = sb.ToString(); //Check out the created workflow CheckOutInObject(Workflow, true); }
public static DataTable GetChildActivityList(WorkflowDescription wfDescription, object activity) { DataTable dt = new DataTable(); dt.Locale = CultureInfo.InvariantCulture; dt.Columns.Add("Id", typeof(string)); dt.Columns.Add("Number", typeof(int)); dt.Columns.Add("Subject", typeof(string)); dt.Columns.Add("User", typeof(int)); dt.Columns.Add("DueDate", typeof(DateTime)); dt.Columns.Add("State", typeof(ActivityStatus)); dt.Columns.Add("IsBlock", typeof(bool)); dt.Columns.Add("ReadOnlyLibraryAccess", typeof(bool)); if (activity is SequentialWorkflowActivity) { SequentialWorkflowActivity block = (SequentialWorkflowActivity)activity; foreach (Activity child in block.Activities) { ProcessChildActivity(wfDescription, child, dt); } } else if (activity is StateMachineWorkflowActivity) { StateMachineWorkflowActivity block = (StateMachineWorkflowActivity)activity; foreach (Activity child in block.Activities) { ProcessChildActivity(wfDescription, child, dt); } } else if (activity is BlockActivity) { BlockActivity block = (BlockActivity)activity; foreach (Activity child in block.Activities) { ProcessChildActivity(wfDescription, child, dt); } } return(dt); }
/// <summary> /// Binds the value. /// </summary> private void BindValue() { EntityObject eo = BusinessManager.Load(WorkflowDefinitionEntity.ClassName, PrimaryKeyId.Parse(WorkflowId)); SequentialWorkflowActivity root = McWorkflowSerializer.GetObject <SequentialWorkflowActivity>(((WorkflowDefinitionEntity)eo).Xaml); Activity ac = root.GetActivityByName(ActivityName); if (ac is CreateAssignmentAndWaitResultActivity) { AssignmentPrototypePropertyEntityCollection props = ((CreateAssignmentAndWaitResultActivity)ac).PrototypeUserProperties; if (props.Contains("Assignment.Properties.Subject")) { tbSubject.Text = props.GetValue("Assignment.Properties.Subject").ToString(); } else { props.SetValue("Assignment.Properties.Subject", string.Empty); } } }
/// <summary> /// Handles the Click event of the btnOk control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void btnOk_Click(object sender, EventArgs e) { EntityObject eo = BusinessManager.Load(WorkflowDefinitionEntity.ClassName, PrimaryKeyId.Parse(WorkflowId)); SequentialWorkflowActivity root = McWorkflowSerializer.GetObject <SequentialWorkflowActivity>(((WorkflowDefinitionEntity)eo).Xaml); Activity ac = root.GetActivityByName(ActivityName); if (ac is CreateAssignmentAndWaitResultActivity) { AssignmentPrototypePropertyEntityCollection props = ((CreateAssignmentAndWaitResultActivity)ac).PrototypeUserProperties; props.SetValue("Assignment.Properties.Subject", tbSubject.Text); } string xaml = McWorkflowSerializer.GetString <SequentialWorkflowActivity>(root); ((WorkflowDefinitionEntity)eo).Xaml = xaml; BusinessManager.Update(eo); Page.ClientScript.RegisterClientScriptBlock(this.GetType(), Guid.NewGuid().ToString(), "window.opener.__doPostBack('', ''); window.close();", true); //BusinessManager.Update(((CreateAssignmentAndWaitResultActivity)ac); }
public void CreateNewWorkflow(Module module) { workflow = new Cdc.MetaManager.DataAccess.Domain.Workflow(); workflow.RequestMap = new PropertyMap(); workflow.Name = tbName.Text; workflow.Module = module; workflow.Description = tbDescription.Text; SequentialWorkflowActivity rootActivity = new SequentialWorkflowActivity("root"); rootActivity.SetValue(WorkflowMarkupSerializer.XClassProperty, WorkflowTypeFactory.GetWorkflowClassFullName(workflow)); StringBuilder sb = new StringBuilder(); XmlWriter xmlWriter = XmlWriter.Create(sb); WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer(); serializer.Serialize(xmlWriter, rootActivity); xmlWriter.Close(); workflow.WorkflowXoml = sb.ToString(); }
/// <summary> /// Handles the Click event of the btnCreate control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> void btnCreate_Click(object sender, EventArgs e) { //throw new NotImplementedException(); SequentialWorkflowActivity root = this.CurrentContainer.CurrentRootActivity; Activity ac = root.GetActivityByName(CurrentActivity.Name); CreateAssignmentAndWaitResultActivity newAct = new CreateAssignmentAndWaitResultActivity(); newAct.Name = String.Format("test dvs {0}", Guid.NewGuid().ToString("N")); //newAct.Subject = " Subject Here "; if (ac.Parent != null || ac is System.Workflow.ComponentModel.CompositeActivity) { ((System.Workflow.ComponentModel.CompositeActivity)ac).Activities.Add(newAct); } else { root.Activities.Add(newAct); } CurrentContainer.CurrentRootActivity = root; this.CurrentContainer.PerformControls(); }
/// <summary> /// When overridden in an abstract class, creates the control hierarchy that is used to render the composite data-bound control based on the values from the specified data source. /// </summary> /// <param name="dataSource">An <see cref="T:System.Collections.IEnumerable"/> that contains the values to bind to the control.</param> /// <param name="dataBinding">true to indicate that the <see cref="M:System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls(System.Collections.IEnumerable,System.Boolean)"/> is called during data binding; otherwise, false.</param> /// <returns> /// The number of items created by the <see cref="M:System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls(System.Collections.IEnumerable,System.Boolean)"/>. /// </returns> protected override int CreateChildControls(System.Collections.IEnumerable dataSource, bool dataBinding) { if (this.CurrentRootActivity == null) { EntityObject[] arr = BusinessManager.List(WorkflowDefinitionEntity.ClassName, new Mediachase.Ibn.Data.FilterElement[] { new Mediachase.Ibn.Data.FilterElement("WorkflowDefinitionId", FilterElementType.Equal, this.WorkflowId) }); if (arr.Length == 1) { WorkflowDefinitionEntity wf = (WorkflowDefinitionEntity)arr[0]; this.CurrentRootActivity = McWorkflowSerializer.GetObject <SequentialWorkflowActivity>(wf.Xaml); } else { throw new ArgumentNullException(String.Format("Cant find workflow with id: {0}", this.WorkflowId)); } } btnSave = new Button(); btnSave.Text = "Save workflow"; btnSave.Click += new EventHandler(btnSave_Click); divContainer = new Panel(); divContainer.CssClass = "wfMainContainer"; divContainer.ID = this.ID + "_wfMainContainerId"; _counter = 0; if (this.CurrentRootActivity != null) { ProcessNodeCollection(this.CurrentRootActivity, divContainer); } divContainer.Controls.Add(btnSave); this.Controls.Add(divContainer); return(1); }
/// <summary> /// Performs the move. /// </summary> /// <param name="direction">The direction.</param> private void PerformMove(int direction) { SequentialWorkflowActivity root = this.CurrentContainer.CurrentRootActivity; Activity ac = root.GetActivityByName(CurrentActivity.Name); System.Workflow.ComponentModel.CompositeActivity parent = ac.Parent; if (parent != null && parent.Activities.Count > 1) { int index = parent.Activities.IndexOf(ac); if (direction == 0) { //move up if (index > 0) { parent.Activities.Remove(ac); index--; parent.Activities.Insert(index, ac); } } else { //movedown if (index != parent.Activities.Count - 1) { parent.Activities.Remove(ac); index++; parent.Activities.Insert(index, ac); } } } CurrentContainer.CurrentRootActivity = root; this.CurrentContainer.PerformControls(); }
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(); } }
private static void ProcessActivity(WorkflowDescription wfDescription, Activity activity, DataTable dt, int level) { DataRow row = dt.NewRow(); row["Id"] = activity.QualifiedName; row["Number"] = dt.Rows.Count + 1; if (activity is SequentialWorkflowActivity) { row["Subject"] = wfDescription.Name; row["IsBlock"] = true; } else if (activity is StateMachineWorkflowActivity) { row["Subject"] = wfDescription.Name; row["IsBlock"] = true; } else if (activity is BlockActivity) { if (((BlockActivity)activity).Type == BlockActivityType.All) { row["Subject"] = "{IbnFramework.BusinessProcess:BlockActivityTypeAll}"; } else { row["Subject"] = "{IbnFramework.BusinessProcess:BlockActivityTypeAny}"; } row["IsBlock"] = true; } else if (activity is CreateAssignmentAndWaitResultActivity) { PropertyValueCollection properties = ((CreateAssignmentAndWaitResultActivity)activity).AssignmentProperties; row["Subject"] = properties[AssignmentEntity.FieldSubject].ToString(); row["User"] = (int)properties[AssignmentEntity.FieldUserId]; if (properties[AssignmentEntity.FieldPlanFinishDate] != null) { row["DueDate"] = (DateTime)properties[AssignmentEntity.FieldPlanFinishDate]; } row["IsBlock"] = false; } if (row["Subject"] == DBNull.Value) { row["Subject"] = "{IbnFramework.BusinessProcess:NoSubject}"; } row["State"] = GetActivityStatus(wfDescription, activity); row["Level"] = level; dt.Rows.Add(row); level++; if (activity is SequentialWorkflowActivity) { SequentialWorkflowActivity block = (SequentialWorkflowActivity)activity; foreach (Activity child in block.Activities) { ProcessActivity(wfDescription, child, dt, level); } } else if (activity is StateMachineWorkflowActivity) { StateMachineWorkflowActivity block = (StateMachineWorkflowActivity)activity; foreach (Activity child in block.Activities) { ProcessActivity(wfDescription, child, dt, level); } } else if (activity is BlockActivity) { BlockActivity block = (BlockActivity)activity; foreach (Activity child in block.Activities) { ProcessActivity(wfDescription, child, dt, level); } } }
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(); } }