动态 SharePoint 2007 WebPart 连接
我正在对在运行时动态连接 Web 部件的最佳方法进行原型设计。本质上,该应用程序将允许多个不同的应用程序组创建将在 SharePoint 前端中使用的 Web 部件。所有 Web 部件都需要自动检测使用者和提供者以在运行时创建连接。
我们想要做的是让 Web 部件发现并自动连接到其他兼容的 Web 部件。当用户将两个兼容部分添加到页面时,这些部分应该能够创建适当的连接。我们有一个定义良好的接口,用于在各部分之间传递数据,因此唯一的问题是如何管理连接。需要明确的是,我们不希望用户担心必须自己创建连接。
就我们的目的而言,“最佳方式”意味着最高效、最优雅和/或最标准。我们希望尽可能遵循既定的共享点设计模式,但代码效率有些重要。
我已经能够起草一个概念证明,该概念证明使用基本 Web 部件类在每个子类 Web 部件的 oninit 事件期间执行此操作。 oninit 事件获取当前页面的 SPWebPartManager 并迭代每个部分,为从基类继承的每个 Web 部件创建使用者和提供者连接:
SPWebPartManager spManager = SPWebPartManager.GetCurrentWebPartManager(Page) as SPWebPartManager;
foreach (BaseWebPart provider in parts)
{
foreach (BaseWebPart consumer in parts)
{
if (provider != consumer)
{
string connectionId = string.Format("WebPartConnection{0}{1}", consumer.ID, provider.ID);
SPWebPartConnection conn = spManager.SPWebPartConnections[connectionId];
if (conn == null)
{
conn = new SPWebPartConnection()
{
ID = connectionId,
ConsumerID = consumer.ID,
ConsumerConnectionPointID = "WebPartConnectableConsumer",
ProviderID = provider.ID,
ProviderConnectionPointID = "WebPartConnectableProvider"
};
spManager.SPWebPartConnections.Add(conn);
}
}
}
}
I'm prototyping the best way to dynamically connect web parts at runtime. Essentailly, the application will allow for several disparate application groups to create web parts that will be consumed within the SharePoint front end. All of the web parts will need to automatically detect consumers and providers to create connections at runtime.
What we are looking to do is have webparts discover and automatically connect to other compatible webparts. When a user adds the two compatible parts to a page, the parts should be able create the appropriate connections. We have a well defined interface for passing data between the parts, so the only issue is how to manage the connections. To be clear, we do not want user's to worry about having to create connections themselves.
For our purposes "best way" means most efficient, elegant and/or standard. We'd like to follow established sharepoint design patterns as much as possible, but code efficiency is somewhat important.
I've been able to draft a proof of concept that uses a base web part class to do this during the oninit event of each subclassed webpart. The oninit event grabs the current page's SPWebPartManager and itereates through each part creating consumer and provider connections for every webpart inheriting from the base class:
SPWebPartManager spManager = SPWebPartManager.GetCurrentWebPartManager(Page) as SPWebPartManager;
foreach (BaseWebPart provider in parts)
{
foreach (BaseWebPart consumer in parts)
{
if (provider != consumer)
{
string connectionId = string.Format("WebPartConnection{0}{1}", consumer.ID, provider.ID);
SPWebPartConnection conn = spManager.SPWebPartConnections[connectionId];
if (conn == null)
{
conn = new SPWebPartConnection()
{
ID = connectionId,
ConsumerID = consumer.ID,
ConsumerConnectionPointID = "WebPartConnectableConsumer",
ProviderID = provider.ID,
ProviderConnectionPointID = "WebPartConnectableProvider"
};
spManager.SPWebPartConnections.Add(conn);
}
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我强烈建议您重新考虑,然后放弃这个想法。
我知道,教所有用户连接 Web 部件可能很困难,而且您的功能可能会在有限的场景中运行。
但在更复杂的情况下,您只是自找麻烦,并且限制了高级用户的可能性。
我的建议是,您开发您的 Web 部件,以便它们可以在有连接和无连接的情况下工作(如果连接,可能会隐藏部分 UI),并教您的用户使用连接
或者您可以半途而废,在设计中显示您的 Web 部件时模式下,将其可以连接到的 Web 部件列为链接,用户可以单击这些链接来建立连接。
I will highly recommend that you reconsider and then drop this idea.
I know that it may be hard to teach all users to connect web parts, and you might get your functionallity to work in limited scenarios.
But in more complicated scenarios you're just asking for trouble and you're limiting the possiblities of advanvced users.
My recommendation is that you develop your web parts so they can work both with and without connections (maybe hiding part of the UI if connected) and teach your users to use connections
Or you could go halfway and when showing your webpart in design mode, list the web parts it can be connected to as links, which the user can click to make connections.