Part 3: Getting Activities Information by Using the Proxy Library for Outlook Social Connector Provider Extensibility
Summary: Learn how to return activity information from an Outlook Social Connector Provider by using the Outlook Social Connector Provider Proxy Library framework.
Applies to: Office 2007 | Office 2010 | Outlook | Outlook 2007 | Outlook 2010 | Visual Studio
Published: January 2011
Provided by: Michael Case, iSoftStone | Angela Chu-Hatoun, Microsoft Corporation | Patrick Creehan, Microsoft Corporation
The Microsoft Outlook Social Connector (OSC) provides a communication hub for personal and professional communications. Just by selecting an Outlook item such as an email or meeting request and clicking the sender or a recipient of that item, users can see, in the People Pane, activities, photos, and status updates for the person on their favorite social networks. The OSC obtains social network data by calling an OSC provider, which behaves like a translation layer between Outlook and the social network. The OSC provider model is open, and you can develop a custom OSC provider by implementing the required OSC provider extensibility interfaces. To retrieve social network data, the OSC makes calls to the OSC provider through these interface members. The OSC provider communicates with the social network and returns the social network data to the OSC as a string or as XML that conforms to the Outlook Social Connector XML schema. Figure 1 shows the various components of the sample OfficeTalk OSC provider reviewed in this Visual How To. Figure 1. Relationships of the sample OfficeTalk OSC provider with related components This Visual How To focuses on returning activity social network data from OfficeTalk. OfficeTalk is not publicly available and is being used as an example of the kind of social network you might want to develop a custom OSC provider for. You can use the techniques to return activity social network data from OfficeTalk to return activity social network data from any social network. The OfficeTalk provider uses the Outlook Social Connector Provider Proxy Library to simplify implementing the OSC provider extensibility interfaces. The OSC Provider Proxy Library implements all of the OSC provider extensibility interface members. These interface members, in turn, call a consolidated set of abstract and virtual methods that provide the social network data that the OSC requires. To create a custom OSC provider that uses the OSC Provider Proxy Library, a developer overrides these abstract and virtual methods with the business logic to communicate with the social network. The sample solution for this article includes all of the code for a custom OSC provider for OfficeTalk. However, this Visual How To does not show all of the code in the sample solution. Instead it focuses on returning activity social network data. The sample solution contains two projects:
The OfficeTalkOSCProvider project includes the following source code files:
The following sections show the procedures to add OSC Provider Proxy Library override methods for activity-related methods for the OTProvider class in the OTProvider_Activities source file. Creating the OfficeTalk OSC Provider Solution Reviewing the steps to create a Visual Studio solution for an OfficeTalk OSC provider is outside the scope of this Visual How To. For information about creating a custom OSC provider solution, see Part 1: Developing a Real Outlook Social Connector Provider by Using a Proxy Library. Creating the OTProvider_Activities Source File Use the OSC Provider Proxy Library to create a subclass of the OSCProvider class, OTProvider, which represents the sample OSC provider. OTProvider is defined as a partial class so that the logic for OSC provider core methods, friends, and activities can be defined in separate source code files. The OTProvider_Activities source file extends the OTProvider partial class and contains the override methods for providing OfficeTalk activities information. Add a class named OTProvider_Activities to the OfficeTalkOSCProvider project. Replace the class definition with the following code. The code example starts with the using statements for the OSC Provider Proxy Library and OfficeTalk API. The code example then defines the OTProvider partial class. The OTProvider source file defines inheriting from the OSCProvider class.
Allowing for Debugging To debug the OfficeTalkOSCProvider, you must modify the OfficeTalkOSCProvider project to start using Outlook and register the OfficeTalkOSCProvider as an Outlook Social Connector. To set up the OfficeTalkOSCProvider project for debugging
The Outlook Social Connector will not call the OfficeTalkOSCProvider until it is registered as an OSC Provider. The sample solution includes a file named RegisterProvider.reg that updates the registry with the entries required to register the OfficeTalkOSCProvider as an OSC provider. You can update the registry by opening the RegistryProvider.reg file in Windows Explorer. The RegisterProvider.reg file assumes that the sample solution is located in the C:\temp directory. If the sample solution is located in a different directory, update the CodeBase entry in the RegisterProvider.reg file to point to the correct location. Adding Helper Methods The OfficeTalkHelper class contains helper methods, including the GetOfficeTalkClient method, that are used throughout the sample solution. The following GetOfficeTalkClient method returns an OfficeTalkClient object that is used to communicate with OfficeTalk. If the OfficeTalkClient has not been initialized, GetOfficeTalkClient creates and configures a new OfficeTalkClient by using the API_URL and API_VERSION constants that are defined in OTProvider.
Activity Feed Overview OSC providers return activity social network data as an ActivityFeed object. An ActivityFeed contains a collection of activities and a collection of templates. Activities contain the data for the activity, and templates define the format to display the activity data in the Outlook People Pane. Templates use named tokens within their format strings as placeholders for activity data. Activities pass information to the template by using template variables. The OSC replaces template named tokens with an activity template variable whenever there is a match between the name of the token and the name of an activity template variable. There is a many-to-one relationship between activities and templates. An activity defines which template in the ActivityFeed to use to display its information by setting its ApplicationID and TemplateID properties. To display the activity data, the OSC uses the template in the ActivityFeed that has the same values for its ApplicationID and TemplateID properties as the activity’s ApplicationID and TemplateId property values. The OSC Provider Proxy Library includes helper classes for defining the ActivityFeed. The Activity class is a helper class that represents an activity. The Activity class has properties that the OSC Provider Proxy Library translates into an XML string that conforms to the Outlook Social Connector XML schema. The following list shows the properties of the Activity class.
The OSC Provider Proxy Library Template helper class is used to represent a template. The following list shows the properties of the Template class.
The OSC defines a limited set of template variable types that are used to pass information between the activity and its template. The OSC Proxy Provider Library includes helper classes for each template variable type. The following list shows the template variable type helper classes.
Overriding the GetActivities Method The OSC ISocialSession.GetActivities, ISocialSession2.GetActivitiesEx, ISocialPerson.GetActivities, and ISocialProfile.GetActivitiesOfFriendsAndColleagues interface members return activity social network data as an ActivityFeed. The OSC Provider Proxy Library provides the GetActivities abstract method, which you can override to return activity information from the social network. The OSC calls each of these interface methods differently. The OSC Provider Proxy Library passes both the parameters sent from the OSC along with flags that identify what the parameter values represent. The GetActivities method has the following parameters:
The OfficeTalk OSC provider in the sample solution supports hybrid synchronization of activity information. Using hybrid synchronization, the OSC stores activity information for friends as Outlook RSS items in a hidden News Feed folder, and stores activities for non-friends in memory. The OSC calls the ISocialSession2.GetActivitiesEx method after 60 minutes to refresh activities information for friends and after 30 minutes to refresh activities information for non-friends. The following section of the GetActivities override method completes these steps:
The email address array from the OSC may contain multiple email addresses for the same social network person. The following section of the GetActivities override method creates a list of unique OfficeTalk users from the list of email addresses that the OSC provides. The code completes the following steps:
The following section of the GetActivities override method populates the ActivityFeed with messages from OfficeTalk. The code completes the following steps:
The AddReplyMessagesToActivityFeed and AddMessageToActivityFeed helper methods are covered in their own sections.
The following section of the GetActivities override method evaluates whether there are activities to return. If there are no activities to return, the GetActivities override method throws an OSCException of type OSC_E_NO_CHANGES, which returns the OSC_E_NO_CHANGES error that the OSC expects.
Creating the AddReplyMessagesToActivityFeed Method The OfficeTalk GetUserMessages method returns OfficeTalk messages that the user replied to. The AddReplyMessagesToActivityFeed method adds to the activity feed each reply message that the OfficeTalk user created. The AddReplyMessagesToActivityFeed method uses the OSC Proxy Library CreateTemplate helper method to create the template and update the activity that was added to the activity feed. Activity feed templates contain three main sections: title, data, and icon. The CreateTemplate method takes a formatted string and list of template variables for each of these sections and creates a template and updates the activity by using the template variables. The formatted strings that are passed into the CreateTemplate helper method use integer indexed placeholders to identify where template variable replacements should take place. The following is an example: "First Value {0} and second value {1}" The list of template variables for each section includes a template variable for each placeholder in the formatted string. For the preceding example, there would be a list with two template variables. The CreateTemplate method evaluates the formatted string for each section and replaces each integer index placeholder with the template named token that the OSC requires. The name of the named token is based on the name of the template variable at the same index position in the list of template variables for that section. Because the AddReplyMessagesToActivityFeed method uses the CreateTemplate method, it does not define the activity or template objects directly. Instead, the AddReplyMessagesToActivityFeed defines the formatted strings and lists of activity template variables that the CreateTemplate method uses. The original message's recent_replies property contains the reply messages. The following section of the AddReplyMessagesToActivityFeed method evaluates each message's recent_replies property and adds each reply message that the OfficeTalk user created to a list of OfficeTalk messages to be added to the activity feed.
The AddReplyMessagesToActivityFeed method then adds each of the messages to the activity feed. The following section of the AddReplyMessagesToActivityFeed method initializes the activity and sets general properties. The code completes the following steps:
The following section of the AddReplyMessagesToActivityFeed method builds the title section based on the reply message text. The code completes the following steps:
The following section of the AddReplyMessagesToActivityFeed method then adds, to the beginning of the title, information about the OfficeTalk user who created the original message. The code completes the following steps:
The following section of the AddReplyMessagesToActivityFeed method builds the data section. The data section displays any pictures that are included in the OfficeTalk reply message, and a hyperlink to the original OfficeTalk message. The code completes the following steps:
Because pictures may not be included in the message, the AddReplyMessagesToActivityFeed method handles the picture template variables manually instead of using the CreateTemplate method. The AddReplyMessagesToActivityFeed method adds the PicturesListVariable directly to the ActivityTemplateVariables property.
The following section of the AddReplyMessagesToActivityFeed method adds to the data section a hyperlink to the original OfficeTalk message. The text for the hyperlink displays the number of replies to the original OfficeTalk message. The code completes the following steps:
The following section of the AddReplyMessagesToActivityFeed method builds the icon section. The code completes the following steps:
Next, the AddReplyMessagesToActivityFeed method calls the OSC Proxy Library CreateTemplate helper method to create the template used for the activity. The CreateTemplate method takes the title, data, and icon formatted strings and combines them with the title, data, and icon TemplateListVariables to create a Template with named tokens. CreateTemplate also adds the title, data, and icon template variables to the activity's TemplateVariables property.
Next, the AddReplyMessagesToActivityFeed method checks whether pictures were included in the data section. If pictures were included, the AddReplyMessagestoActivityFeed method updates the template's Data property to display the pictures before the hyperlink for the original OfficeTalk message. Because the AddReplyMessagesToActivityFeed method has already called the CreateTemplate helper method, it uses the named tokens that the OSC expects. The token names used for the pictures match the template variable names that were added to the activity's TemplateVariables for the picture list and pictures.
Before adding the activity and template to the activity feed, the AddReplyMessagesToActivityFeed method verifies that the activity and template define valid XML. If the XML is not valid, the AddReplyMEssagesToActivityFeed method does not add the activity and template to the activity feed and processes the next reply message.
Creating the AddMessageToActivityFeed Method The AddMessageToActivityFeed method adds to the activity feed the OfficeTalk message that the OfficeTalk user created. The AddMessageToActivityFeed method follows the same process outlined previously for the AddReplyMessagesToActivityFeed method:
The only difference in the AddMessageToActivityFeed method is that all information that is used to define the activity and template that are added to the activity feed is based on the OfficeTalk message. Overriding OSC Provider Proxy Library Core Methods A custom OSC provider that uses the OSC Provider Proxy Library must override the abstract and virtual methods for returning information about the OSC provider, the social network capabilities, and the currently logged-on user. In the sample solution, the overrides for these OTProvider methods are located in the OTProvider source file. The core abstract and virtual methods are as follows:
Reviewing these methods is outside the scope of this Visual How To. For more information, see Part 1: Developing a Real Outlook Social Connector Provider by Using a Proxy Library. Overriding OSC Provider Proxy Library Friends Methods A custom OSC Provider that uses the OSC Provider Proxy Library must override the abstract and virtual methods for returning friends social network data. In the sample solution, the overrides for these OTProvider methods are located in the OTProvider_Friends source file. The abstract and virtual methods for friends are as follows:
Reviewing these methods is outside of the scope of this Visual How To. For more information about returning friends social network data, see Part 2: Getting Friends Information by Using the Proxy Library for Outlook Social Connector Provider Extensibility. Creating a custom Outlook Social Connector (OSC) provider for a social network is a straightforward process of implementing the OSC provider extensibility interfaces to return social network data. The OSC Provider Proxy Library simplifies this process by removing the requirement to implement each individual interface member. Instead the OSC Provider Proxy Library defines a consolidated set of abstract and virtual methods to provide social network data. The developer of the OSC provider can focus on overriding these methods with the business logic required to interface with the social network API. The sample solution for this Visual How To includes sample code for a custom OSC provider for OfficeTalk. This Visual How To does not cover all of the code in the sample solution. This Visual How To focuses on returning friends social network data from OfficeTalk. The social network data returned by the OfficeTalk provider is shown in Figure 2. Figure 2. OSC showing OfficeTalk social network data in the People Pane For more information about creating the OfficeTalk OSC provider, see Part 1: Developing a Real Outlook Social Connector Provider by Using a Proxy Library. For more information about returning friends social network data, see Part 2: Getting Friends Information by Using the Proxy Library for Outlook Social Connector Provider Extensibility. |
> [!VIDEO https://www.microsoft.com/en-us/videoplayer/embed/96543682-bb11-49e8-aef8-a9e05483c7b5] Length: 16:11 |