SharePoint Integration

SharePoint integration is handled by OpenWaves.ActivityFeed.Sharepoint NuGet package. The package adds a SharePoint feature and DLL library. Feature is responsible for setup web.config and add event receivers to SharePoint objects. DLL contains base classes for feature, event receivers and SharePoint connector.

The "ActivityFeedFeatureReceiverBase" feature

Feature class added through NuGet to SharePoint project is is inheriting from ActivityFeedFeatureReceiverBase. Feature is responsible for initializing list event receivers. Base class have virtual methods that should be customized in feature class.

public abstract class ActivityFeedFeatureReceiverBase : SPFeatureReceiver
{
  ...
  
  protected  virtual Type GetEventReceiverClassName()
  {
    return typeof (ActivityFeedEventReceiverBase);
  }
  
  protected virtual bool CanAddList(SPList list)
  {
    return list.BaseTemplate == SPListTemplateType.DocumentLibrary ||
         list.BaseTemplate == SPListTemplateType.WebPageLibrary;
  }

  protected abstract string GetActivityFeedConectionString();

  ...
}
GetActivityFeedConectionString is an abstract method used to get connectionstring to ActivityFeed RavenDb datastore. By default value is set to "Url=http://localhost:8080".
CanAddList is used to limit list types associated with ActivityFeed. By default events are activated for Documents and Pages.
GetEventReceiverClassName returns class used as event receiver. By default it's ActivityFeedEventReceiver class.

The "ActivityFeedEventReceiverBase" event receiver

When event is received, then instance of * IActivityFeedSharepointConnector* is created using CreateConnector method. CreateConnector is virtual method, which by default creates instance of ActivityFeedSharepointConnectorBase class. This class is responsible for publishing update.

public class ActivityFeedEventReceiverBase : SPItemEventReceiver
{
  public override void ItemAdded(SPItemEventProperties properties)
  {
    using (var documentSession = ActivityFeedDocumentStore.Current.OpenSession())
    {
      var connector = this.CreateConnector(new ActivityFeedService(documentSession));

      connector.OnItemEvent(properties, SPEventReceiverType.ItemAdded);

      documentSession.SaveChanges();
    }
  }

  protected virtual IActivityFeedSharepointConnector CreateConnector(IActivityFeedService activityFeedService)
  {
    return new ActivityFeedSharepointConnectorBase(activityFeedService);
  }
}

The "ActivityFeedSharepointConnectorBase" class

This class is responsible for publishing updates from SharePoint to ActivityFeed. You can derive from this class to create custom connector.

public class ActivityFeedSharepointConnectorBase : IActivityFeedSharepointConnector
{
  protected override string GetUserName(SPItemEventProperties properties)
  {
    // Returns creator of update 
    // Default implementation returns UserLoginName
    return base.GetUserName(properties);
  }

  protected override IEnumerable<UserGroup> GetUserGroups(SPItemEventProperties properties)
  {    
    // User groups required to get update
    //
    // Default implementation returns roles assigned to list
    return GetUserGroups(properties);
  }

  protected override IEnumerable<Topic> GetTopics(SPItemEventProperties properties)
  {
    // Topics assigned to update
    // 
    // Default implementation returns topics 
    // retrieved from list, web, site and current user
    return base.GetTopics(properties);
  }

  protected override UpdateContent GetUpdateContent(SPItemEventProperties properties, SPEventReceiverType eventType)
  {
    // Update custom content
    // 
    // Default implementation contains list item title, item url and event type
    return base.GetUpdateContent(properties, eventType);
  }
}

Topic converters

ActivityFeed SharePoint connector provides extension methods to converting SPObjects to topic. Extensions are available for:
  • SPList
  • SPWeb
  • SPList
  • SPUser

ActivityFeed web part sample

The source code includes project ActivityFeed.SharePoint.Sample ,which is an example of nesting ActivityFeed control in SharePoint.

Last edited Jul 17, 2012 at 10:17 AM by grzwie, version 20

Comments

No comments yet.