首页 新闻 会员 周边 捐助

动态生成工作流

0
悬赏园豆:50 [已关闭问题]

自定义的CallExternalMethodActivity和HandleExternalEventActivity并设置了InterfaceType等属性

接口代码:

1 using System;
2  using System.Collections.Generic;
3  using System.Linq;
4 using System.Text;
5 using System.Workflow.Activities;
6 using System.Windows.Forms;
7 using System.Workflow.ComponentModel;
8 using System.Workflow.Runtime;
9
10 namespace ActivityLibrary
11 {
12 [Serializable]
13 public class InterfaceSecondEventArgs : ExternalDataEventArgs
14 {
15 //public string _demo;
16 public InterfaceSecondEventArgs(Guid instanceID)
17 : base(instanceID)
18 {
19 //this._demo = str;
20 }
21
22 //public string DemoValue
23 //{
24 // get { return this._demo; }
25 //}
26 }
27
28
29 [ExternalDataExchange]
30 public interface IInterfaceSecond
31 {
32 event EventHandler<InterfaceSecondEventArgs> PassOK;
33 event EventHandler<InterfaceSecondEventArgs> OutNO;
34
35 void DemoMethod();
36 }
37
38 public class InterfaceClass : IInterfaceSecond
39 {
40 public event EventHandler<InterfaceSecondEventArgs> PassOK;
41 public event EventHandler<InterfaceSecondEventArgs> OutNO;
42
43 public void DemoMethod()
44 {
45 ShowWin(new InterfaceSecondEventArgs(WorkflowEnvironment.WorkflowInstanceId));
46 }
47
48 public void ShowWin(InterfaceSecondEventArgs e)
49 {
50 DialogResult result;
51 string showValue = e.InstanceId.ToString();
52 result = MessageBox.Show(string.Format("是否同意?{0}", showValue), string.Format("ceshi---{0}", showValue), MessageBoxButtons.YesNo);
53 if (result == DialogResult.Yes)
54 {
55 EventHandler<InterfaceSecondEventArgs> okaction = this.PassOK;
56 if (okaction != null)
57 {
58 PassOK(null, e);
59 }
60 }
61 else
62 {
63 EventHandler<InterfaceSecondEventArgs> noaction = this.OutNO;
64 if (noaction != null)
65 {
66 OutNO("chengHy", e);
67 }
68 }
69 }
70
71 }
72 }
73

我动态生成一个.xoml文件......并且生成了DLL文件...可就是运行这个工作流时...不报错也不提示成功...

生成DLL代码:

代码
String[] assemblyNames = { AdditionalAssembies };
WorkflowCompiler compiler
= new WorkflowCompiler();
WorkflowCompilerParameters parameters
= new WorkflowCompilerParameters(assemblyNames);
//parameters.LibraryPaths.Add(Path.GetDirectoryName(typeof(ActivityLibrary.MessageActivity).Assembly.Location));
//parameters.GenerateInMemory = true;

string newDll = this.XomlFile.Replace("xoml", "dll");
parameters.OutputAssembly
= newDll;

WorkflowCompilerResults compilerResults
= compiler.Compile(parameters, this.XomlFile);

inMemoryAssembly
= compilerResults.CompiledAssembly;

StringBuilder errors
= new StringBuilder();

foreach (CompilerError compilerError in compilerResults.Errors)
{
errors.Append(compilerError.ToString()
+ '\n');
}

if (errors.Length != 0)
{
MessageBox.Show(
this, errors.ToString(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
compileOK
= false;
}
else if (showMessage)
{
MessageBox.Show(
this, "Workflow compiled successfully. Compiled assembly:\n" + compilerResults.CompiledAssembly.GetName(), this.Text, MessageBoxButtons.OK, MessageBoxIcon.Information);
}

 

运行工作流代码:

代码
public void Run()
{
// Start the runtime engine
if (this.workflowRuntime == null)
{
this.workflowRuntime = new WorkflowRuntime();
this.workflowRuntime.StartRuntime();
}

this.workflowRuntime.WorkflowCompleted += new EventHandler<WorkflowCompletedEventArgs>(workflowRuntime_WorkflowCompleted);
string typeName = string.Format("{0}.{1}", this.GetType().Namespace, this.WorkflowName);
this.workflowRuntime.CreateWorkflow(AppDomain.CurrentDomain.CreateInstanceAndUnwrap(inMemoryAssembly.FullName, typeName).GetType()).Start();

}

void workflowRuntime_WorkflowCompleted(object sender, WorkflowCompletedEventArgs e)
{
MessageBox.Show(
"Workflow complete");
}

 

望高手解答,谢谢.....

问题补充: 帮帮忙了
时代宠儿的主页 时代宠儿 | 初学一级 | 园豆:150
提问于:2010-04-30 13:17
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册