📄 wxdwfsequentialview.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using System.ComponentModel.Design;
using System.ComponentModel.Design.Serialization;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.Activities;
using System.Workflow.ComponentModel.Design;
using System.Runtime.InteropServices;
using System.Collections;
using System.Collections.ObjectModel;
using System.IO;
using System.Workflow.ComponentModel.Serialization;
using System.Xml;
using System.CodeDom.Compiler;
using System.Workflow.Runtime;
using System.Reflection;
using System.Threading;
namespace wxwinter.wf.Design
{
public class wxdWFSequentialView : UserControl, IDisposable, IServiceProvider
{
private WorkflowView workflowView; //工作查看器
private DesignSurface designSurface;
private wxdWFLoader loader;
SequentialWorkflowActivity workflow;
public wxdWFSequentialView()
{
WorkflowTheme.CurrentTheme.ReadOnly = false;
WorkflowTheme.CurrentTheme.AmbientTheme.ShowConfigErrors = true ;
WorkflowTheme.CurrentTheme.ReadOnly = true;
}
public void ProcessZoom(int zoomFactor)
{
this.workflowView.Zoom = zoomFactor;
this.workflowView.Update();
}
public new object GetService(Type serviceType)
{
return (this.workflowView != null) ? ((IServiceProvider)this.workflowView).GetService(serviceType) : null;
}
//从XML文件加载工作流到设计器的核心
private void LoadWorkflow(string xoml)
{
SuspendLayout();
DesignSurface designSurface = new DesignSurface();
wxdWFLoader loader = new wxdWFLoader("");
loader.Xoml = xoml;
designSurface.BeginLoad(loader);
IDesignerHost designerHost;
designerHost = designSurface.GetService(typeof(IDesignerHost)) as IDesignerHost;
if (designerHost != null && designerHost.RootComponent != null)
{
IRootDesigner rootDesigner = designerHost.GetDesigner(designerHost.RootComponent) as IRootDesigner;
if (rootDesigner != null)
{
UnloadWorkflow();
this.designSurface = designSurface;
this.loader = loader;
this.workflowView = rootDesigner.GetView(ViewTechnology.Default) as WorkflowView;
this.Controls.Add(this.workflowView);
this.workflowView.Dock = DockStyle.Fill;
ISelectionService selectionService = GetService(typeof(ISelectionService)) as ISelectionService;
}
}
ResumeLayout(true);
}
private void UnloadWorkflow()
{
IDesignerHost designerHost;
designerHost = GetService(typeof(IDesignerHost)) as IDesignerHost;
if (designerHost != null && designerHost.Container.Components.Count > 0)
wxdWFLoader.DestroyObjectGraphFromDesignerHost(designerHost, designerHost.RootComponent as Activity);
if (this.designSurface != null)
{
this.designSurface.Dispose();
this.designSurface = null;
}
if (this.workflowView != null)
{
Controls.Remove(this.workflowView);
this.workflowView.Dispose();
this.workflowView = null;
}
}
//显示默认的工作流
public void ShowWorkflow(SequentialWorkflowActivity v)
{
this.workflow = v;
using (StringWriter stringWriter = new StringWriter())
{
using (XmlWriter xmlWriter = XmlWriter.Create(stringWriter))
{
WorkflowMarkupSerializer serializer = new WorkflowMarkupSerializer();
serializer.Serialize(xmlWriter, workflow);
LoadWorkflow(stringWriter.ToString());
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -