?? program.cs
字號:
?using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
using System.Workflow.Runtime;
using System.Workflow.Runtime.Hosting;
using System.Workflow.Activities;
using System.ServiceModel;
namespace WorkflowConsoleApplication2
{
class Program
{
static void Main(string[] args)
{
DataSet1 ds = new DataSet1();
WorkflowRuntime workflowRuntime = new WorkflowRuntime();
ExternalDataExchangeService exchange = new ExternalDataExchangeService();
workflowRuntime.AddService(exchange);
exchangeEvent obj = new exchangeEvent(ds);
exchange.AddService(obj);
control ctrl = new control(workflowRuntime, obj);
string WCFurl = "http://localhost:567/wxwinter/";
ServiceHost host = new ServiceHost(ctrl, new Uri(WCFurl));
string WCFClassName = "wxdTest";
host.AddServiceEndpoint(typeof(Icontrol), new BasicHttpBinding(), WCFClassName);
host.Open();
Console.WriteLine("引擎已啟動");
Console.Read();
}
}
class exchangeEvent : IExternalEvent
{
DataSet1 ds;
public exchangeEvent(DataSet1 v)
{ds = v;}
public event EventHandler<NextStepEventArgs> ApproveEvent;
public void Approve(string gid, string userResult)
{
Guid guid = new Guid(gid);
NextStepEventArgs e = new NextStepEventArgs(guid);
e.result = userResult;
ApproveEvent(null, e);
}
public System.Data.DataSet GetApproverTask(string username)
{
System.Data.DataView dv = new System.Data.DataView(ds.infoTab);
dv.RowFilter = string.Format("[approver]='{0}' and [state] = 1", username);
System.Data.DataSet temp = new System.Data.DataSet();
temp.Tables.Add(dv.ToTable());
return temp;
}
public System.Data.DataSet GetProposerTask(string username)
{
System.Data.DataView dv = new System.Data.DataView(ds.infoTab);
dv.RowFilter = string.Format("[proposer]='{0}'", username);
System.Data.DataSet temp = new System.Data.DataSet();
temp.Tables.Add(dv.ToTable());
return temp;
}
public void Notify(dataform df)
{
System.Data.DataView dv = new System.Data.DataView(ds.infoTab);
dv.RowFilter = string.Format("[guid]='{0}'", df.guid);
switch (df.state)
{
case 1:
DataSet1.infoTabRow r = ds.infoTab.NewinfoTabRow();
r.guid = df.guid;
r.approver = df.approver;
r.content = df.content;
r.proposer = df.proposer;
r.result = df.result;
r.state = df.state;
ds.infoTab.Rows.Add(r);
break;
case 2:
((DataSet1.infoTabRow)dv[0].Row).state = df.state;
((DataSet1.infoTabRow)dv[0].Row).result = df.result;
break;
case 3 :
((DataSet1.infoTabRow)dv[0].Row).state = df.state;
break ;
}
}
}
[ServiceBehavior(InstanceContextMode = InstanceContextMode.Single)]
class control : Icontrol
{
WorkflowRuntime workflowRuntime;
exchangeEvent obj;
public control(WorkflowRuntime r, exchangeEvent o)
{
workflowRuntime = r;
obj = o;
}
public void begingWF(string proposer, string approver, string content)
{
Dictionary<string, object> dc = new Dictionary<string, object>();
dataform df = new dataform();
df.approver = approver;
df.content = content;
df.proposer = proposer;
df.result = "";
dc.Add("DF", df);
WorkflowInstance instance = workflowRuntime.CreateWorkflow(typeof(Workflow1), dc);
instance.Start();
}
public void Approve(string guid, string result)
{obj.Approve(guid, result);}
public System.Data.DataSet GetApproverTask(string username)
{ return obj.GetApproverTask(username);}
public System.Data.DataSet GetProposerTask(string username)
{ return obj.GetProposerTask(username);}
}
[ServiceContract]
public interface Icontrol
{
[OperationContract]
void Approve(string guid, string result);
[OperationContract]
void begingWF(string proposer, string approver, string content);
[OperationContract]
System.Data.DataSet GetApproverTask(string username);
[OperationContract]
System.Data.DataSet GetProposerTask(string username);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -