动态 SharePoint 2007 WebPart 连接

发布于 2024-09-06 03:42:50 字数 1433 浏览 2 评论 0原文

我正在对在运行时动态连接 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

何必那么矫情 2024-09-13 03:42:52

我强烈建议您重新考虑,然后放弃这个想法。

我知道,教所有用户连接 Web 部件可能很困难,而且您的功能可能会在有限的场景中运行。

但在更复杂的情况下,您只是自找麻烦,并且限制了高级用户的可能性。

  • 如果您实现一个(或多个)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.

  • If you implement a (or multiple) web part, which can consume and provide the same interface. Then put two of these on a page => Endless loop
  • If your user puts two providers and two consumers on the same page you have no way of pairing these as the user wants.
  • ...

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文