我需要在人们的 MySites 上的个人新闻源中添加自定义通知。我在网上找到了几个 SharePoint 2010 的教程和代码示例,并尝试对 SharePoint 2013 做同样的事情。它们都是关于ActivityEvents
使用ActivityManager
.
这是我尝试过的代码:
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);
函数中的 Id 用于17
活动类型,其布局类似于资源文件中的布局,因此我提供了我的.CreateActivityEvent
StatusMessage
{Publisher} says: {Value}
Value
ActivityEvent
代码运行没有任何异常,在User Profile Service Application_ProfileDB
数据库中我可以看到正确的条目出现在ActivityEventsConsolidated
表中。但是该活动在活动提要中不可见,无论是在所有者的提要上,还是在发布者的提要上,即使这些人互相关注。我在 CA 中手动运行了活动源作业以更新活动源。此外,我尝试对自定义ActivityTypes
资源文件执行相同操作,结果相同:出现表中的条目ActivityEventsConsolidated
(或者ActivityEventsPublished
如果 Owner=Publisher),但 MySite 上没有条目。
任何人都可以帮忙吗?