Newsfeed 中的 SharePoint 2013 Activity 事件

SharePoint 2013 Activity Event in Newsfeed

我需要向人们的“我的网站”上的个人新闻源添加自定义通知。我在网上找到了几个关于 SharePoint 2010 的教程和代码示例,并尝试对 SharePoint 2013 做同样的事情。它们都是关于使用 ActivityManager.

创建 ActivityEvents

这是我试过的代码:

        var targetSite = new SPSite("URL to MySite webapp");
        SPServiceContext context = SPServiceContext.GetContext(targetSite);
        var userProfileManager = new UserProfileManager(context);

        var ownerProfile = userProfileManager.GetUserProfile("domain\user1");
        var publisherProfile = userProfileManager.GetUserProfile("domain\user2");

        var activityManager = new ActivityManager(ownerProfile, context);

        Entity publisher = new MinimalPerson(publisherProfile).CreateEntity(activityManager);
        Entity owner = new MinimalPerson(ownerProfile).CreateEntity(activityManager);
        ActivityEvent activityEvent = ActivityEvent.CreateActivityEvent(activityManager, 17, owner, publisher);
        activityEvent.Name = "StatusMessage";
        activityEvent.ItemPrivacy = (int)Privacy.Public;
        activityEvent.Owner = owner;
        activityEvent.Publisher = publisher;
        activityEvent.Value = "HELLOOOO";
        activityEvent.Commit();

        ActivityFeedGatherer.BatchWriteActivityEvents(new List<ActivityEvent> { activityEvent }, 0, 1);

CreateActivityEvent函数中的Id17是针对StatusMessageactivity类型的,在资源文件中的布局类似于{Publisher} says: {Value},所以我提供 Value 属性 我的 ActivityEvent.

代码运行没有任何异常,在 User Profile Service Application_ProfileDB 数据库中,我可以看到正确的条目出现在 ActivityEventsConsolidated table 中。 但是 activity 在 activity 提要中不可见,无论是在所有者的提要中,还是在发布者的提要中,即使这些人相互关注。我在 CA 中 运行 Activity 提要作业手动更新 activity 提要。 此外,我尝试对自定义 ActivityTypes 和自己的资源文件执行相同的操作,结果相同: ActivityEventsConsolidated table 中的条目(或 ActivityEventsPublished 如果 Owner=Publisher)出现, 但 MySite 上没有条目。

有人能帮忙吗?

我自己找到了这个问题的解决方案。 在 Central AdministrationSetup MySites 中,您必须启用 Newsfeed 部分中的 Enable SharePoint 2010 activity migration 设置才能支持 SP2013 中的 SP1010 遗留活动。