📄 enginemanager.cs
字号:
{
if (send != null)
{ send.sendMsg(v); }
}
#endregion
#region 实例控制
/// <summary>
/// 持久化实例
/// </summary>
/// <param name="guid"></param>
/// <param name="tryunload"></param>
/// <returns></returns>
public bool PersistInstance(string guid, bool tryunload)
{
WorkflowInstance temp = GetInstance(guid);
if (temp != null)
{
if (tryunload)
{
temp.TryUnload();
}
else
{
temp.Unload();
}
return true;
}
else
{
return false;
}
}
/// <summary>
/// 用xoml文件创建工作流实例
/// </summary>
/// <param name="xomlfile">xomlfile文件</param>
/// <returns>实例guid或错误信息</returns>
public string CreateWorkflowFromXomlFile(string xomlfile)
{
try
{
System.Workflow.Runtime.WorkflowInstance instance;
XmlReader xr = XmlReader.Create(xomlfile);
instance = WFEngine.CreateWorkflow(xr);
return instance.InstanceId.ToString();
}
catch (System.Workflow.ComponentModel.Compiler.WorkflowValidationFailedException ex)
{
string s="err:" + ex.Message;
engineLog.Add(s);
return s;
}
}
/// <summary>
/// 从xoml字串创建工作流实例
/// </summary>
/// <param name="xomlstring">xoml字符串</param>
/// <returns>实例guid或错误信息</returns>
public string CreateWorkflowFormXomlString(string xomlstring)
{
try
{
System.Text.UTF8Encoding utf8 = new System.Text.UTF8Encoding();
byte[] b = utf8.GetBytes(xomlstring);
System.IO.MemoryStream ms = new System.IO.MemoryStream(b);
XmlReader xr = XmlReader.Create(ms);
System.Workflow.Runtime.WorkflowInstance instance;
instance = WFEngine.CreateWorkflow(xr);
return instance.InstanceId.ToString();
}
catch (System.Workflow.ComponentModel.Compiler.WorkflowValidationFailedException ex)
{
string s = "err:" + ex.Message;
engineLog.Add(s);
return s;
}
}
/// <summary>
/// 得到实例列表
/// </summary>
/// <returns></returns>
public ArrayList GetInstanceList()
{
System.Collections.ObjectModel.ReadOnlyCollection<WorkflowInstance> ls;
ls = WFEngine.GetLoadedWorkflows();
ArrayList al = new ArrayList();
foreach (WorkflowInstance temp in ls)
{
al.Add(temp.InstanceId.ToString());
}
return al;
}
/// <summary>
/// 启动实例
/// </summary>
/// <param name="guid"></param>
/// <returns></returns>
public bool StartInstance(string guid)
{
WorkflowInstance temp = GetInstance(guid);
if (temp != null)
{
temp.Start();
return true;
}
else
{
return false;
}
}
/// <summary>
/// 暂停实例
/// </summary>
/// <param name="guid"></param>
/// <param name="message"></param>
/// <returns></returns>
public bool SuspendInstance(string guid, string message)
{
WorkflowInstance temp = GetInstance(guid);
if (temp != null)
{
temp.Suspend(message);
return true;
}
else
{
return false;
}
}
/// <summary>
/// 恢复暂停的实例
/// </summary>
/// <param name="guid"></param>
/// <returns></returns>
public bool ResumeInstance(string guid)
{
WorkflowInstance temp = GetInstance(guid);
if (temp != null)
{
temp.Resume();
return true;
}
else
{
return false;
}
}
/// <summary>
/// 终止实例
/// </summary>
/// <param name="guid"></param>
/// <returns></returns>
public bool AbortInstance(string guid)
{
WorkflowInstance temp = GetInstance(guid);
if (temp != null)
{
temp.Abort();
return true;
}
else
{
return false;
}
}
/// <summary>
/// 中止实例
/// </summary>
/// <param name="guid"></param>
/// <param name="message"></param>
/// <returns></returns>
public bool TerminateInstance(string guid, string message)
{
WorkflowInstance temp = GetInstance(guid);
if (temp != null)
{
temp.Terminate(message);
return true;
}
else
{
return false;
}
}
#endregion
#region 引擎加载的服务列表
/// <summary>
/// 得到引擎加载的服务列表
/// </summary>
/// <returns></returns>
public ArrayList GetServiceList()
{
ArrayList al=new ArrayList();
System.Collections.ObjectModel.ReadOnlyCollection<WorkflowRuntimeService> ls;
//WorkflowRuntimeService是所用服务的基类
ls = WFEngine.GetAllServices<WorkflowRuntimeService>();
foreach (WorkflowRuntimeService o in ls)
{
al.Add(o.GetType().Name);
}
return al;
}
#endregion
#region 实例计数器
int nCreateInstance = 0;
/// <summary>
/// 创建的实例
/// </summary>
public int NCreateInstance
{
get { return nCreateInstance; }
}
int nStarteInstance = 0;
/// <summary>
/// 启动的实例
/// </summary>
public int NStarteInstance
{
get { return nStarteInstance; }
}
int nCompletedInstance = 0;
/// <summary>
/// 完成的实例
/// </summary>
public int NCompletedInstance
{
get { return nCompletedInstance; }
}
/// <summary>
/// 没完成的实例
/// </summary>
public int NActiveINstance
{
get { return NCreateInstance - nCompletedInstance; }
}
#endregion
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -