?? 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 + -