您的位置:首页 > 其它

DNN 模块间通信实现的总结

2008-01-22 14:45 232 查看
作为DNN的初学者,最近有两个任务,一个是IMC,IMC的全称是Inter Module Communication,另一个就是对数据库任意表的操作练习。

现在将IMC搞定了。

以自己的方式总结如下:

主要认真看了这几篇资料:
http://forums.asp.net/t/784444.aspx?PageIndex=2 http://kodhedz.net/Default.aspx?tabid=38 http://www.cnblogs.com/zhangwenbo/archive/2006/03/19/DnnIMC.html
特别是中文的那篇,虽然是用的vb,不过我还是看了多遍。不过,也没能认为自己可以动手练习。

搜了一大堆,也没什么实质性的内容,最后下了个老外的据说是DNN2.x的IMC 示例文件。打开看,的确很简单的,依葫芦画瓢,新建了两个module,一个作sender,一个用receiver,改过多次,结果还是失败。

最后用google的代码搜索找到别人的代码,改一下,就成功。URL:http://www.google.com/codesearch?hl=zh-CN&q=+lang:c%23+IModuleCommunicator+module+show:sVj8o_uXslk:meV3DLP5bSQ:OMyiiCKkvdo&sa=N&cd=2&ct=rc&cs_p=http://www.xs4all.nl/~walaco/Visibility.zip&cs_f=Visibility/Detail.ascx.cs#l60

这个任务,我只完成了string传值,按资料上讲的,应该可以实现object传送,还得继续关注,如果有朋友已经实现了,请回在评论里,为我,也为更多的朋友指点一下。

在最后,我贴一下,老外的代码(我最终没有用这个代码试成功,不过,看了代码,就明白这简单,可以实践了,不用只看资料)// www.123de6.cn

private void btnSend_Click(object s, System.EventArgs e)

{

Type target = Type.GetType("object");

Type sender = Type.GetType("object");

string from = sender.Name;

string to = target.Name;

ModuleCommunicationEventArgs oArgs = new ModuleCommunicationEventArgs();

oArgs.Text = txtText.Text;

oArgs.Sender = from;

oArgs.Target = to;

if(ModuleCommunication != null)

ModuleCommunication(this, oArgs);

}//这是发送,当然得引用using DotNetNuke.Entities.Modules.Communications;并且定义类时得继承IModuleCommunicator,在类里还要定义public event ModuleCommunicationEventHandler ModuleCommunication;

另一module里接收代码:

public void OnModuleCommunication(object s, ModuleCommunicationEventArgs e)

{

lblReceive.Text = e.Text;

}//同样得在类定义时,继承 IModuleListener,并在命名空间引用 using DotNetNuke.Entities.Modules.Communications;

这是传送object的代码,在google code URL里的,是我试验成功了的,传string的代码。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: