Export (0) Print
Expand All

Part 3: Getting Activities Information by Using the Proxy Library for Outlook Social Connector Provider Extensibility

Office 2010

Office Visual How To

Summary:  Learn how to return activity information from an Outlook Social Connector Provider by using the Outlook Social Connector Provider Proxy Library framework.

Last modified: September 12, 2012

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

Overview

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

Relationship of sample provider with 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.

Code It

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:

  • OSCProvider—This project is an unmodified version of the OSC Provider Proxy Library that is used to simplify the creation of the OfficeTalk OSC provider.

  • OfficeTalkOSCProvider—This project includes the source code files that are specific to the OfficeTalk OSC provider.

The OfficeTalkOSCProvider project includes the following source code files:

  • OfficeTalkHelper—This class contains helper methods that are used throughout the sample solution.

  • OTProvider—This is a partial class that contains the OSC Provider Proxy Library override methods that return information about the OSC provider, information about the social network, and information for the currently logged-on user.

  • OTProvider_Activities—This is a partial class that contains the OSC Provider Proxy Library override methods that return activity information.

  • OTProvider_Friends—This is a partial class that contains the OSC Provider Proxy Library override methods that return friends information.

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.

using System;
using System.Globalization;
using System.Collections.Generic;
using System.Text.RegularExpressions;

// Using statements for the OSC Provider Proxy Library.
using OSCProvider;
using OSCProvider.Schema;

// Using statements for the social network.
using OfficeTalkAPI;

namespace OfficeTalkOSCProvider
{
    public partial class OTProvider
    {
         ...
    }
}

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

  1. In Microsoft Visual Studio 2010, right-click the OfficeTalkOSCProvider project and then click Properties.

  2. Click the Debug tab.

  3. Under Start Action, select Start External Program.

  4. Specify the full path to the version of Outlook that is installed on your computer. The default path for 32-bit Outlook on 32-bit Windows is C:\Program Files\Microsoft Office\Office14\OUTLOOK.EXE.

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.

// Returns a reference to the OfficeTalk client.
private static OfficeTalkClient officeTalkClient = null;
internal static OfficeTalkClient GetOfficeTalkClient()
{
    if (officeTalkClient == null)
    {
        officeTalkClient =
            new OfficeTalkClient(OTProvider.API_URL);
        OfficeTalkClient.UserAgent =
            @"OfficeTalkOSC/" + OTProvider.API_VERSION;
    }
    return officeTalkClient;
}

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.

ApplicationID

Identifies the application that created the item. It is used along with the TemplateID to identify which template should be used to display the activity data.

TemplateID

Identifies the Template to use to display the activity data.

ActivityID

Identifies the activity.

ActivityType

Identifies the type of activity. Values can be Status Update, Photo, Document, or Other.

Owner/OwnerID

Identifies the user on the social network who created the activity.

PublishDate

Specifies the date and time the activity was created or published.

TemplateVariables

Specifies activity data for the template. The value is a list of objects that are used to populate the tokens that are defined in this activity's template.

The OSC Provider Proxy Library Template helper class is used to represent a template. The following list shows the properties of the Template class.

ApplicationID

Identifies the application the template is for. It is used along with the TemplateID to identify which template should be used to display activity data.

TemplateID

Identifies the template.

TemplateType

Identifies the type of activity. Values can be Status Update, Photo, Document, or Other.

Title

Specifies a formatted string for the title section when the activity is displayed.

Data

Specifies a formatted string for the data section when the activity is displayed.

Icon

Specifies a LinkVariable that references the URL for the icon for the activity.

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.

EntityVariable

Represents a person.

PublisherVariable

Represents the publisher or owner of the activity.

LinkVariable

Represents a hyperlink.

TextVariable

Represents a block of text.

PictureVariable

Represents a link to a picture.

ListVariable

Represents a group of up to five link, text, or picture items.

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:

  • emailAddresses—An array of strings that contain the email addresses passed from the OSC.

  • startTime—A DateTime value. Only activities created after this value should be returned.

  • dynamic—A Boolean value that identifies whether the array of email addresses is for a single person or whether each email address is for a separate person.

  • hashed—A Boolean value that identifies whether the email addresses are hashed or plain text.

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:

  1. It first verifies that email addresses have been passed in.

  2. The GetActivities override method then initializes the ActivityFeed object and sets the NetworkName property.

  3. Finally, the method calls the OfficeTalkHelper GetOfficeTalkClient method to get an OfficeTalkClient object for communicating with OfficeTalk.

// Verify that email addresses have been passed in.
if (emailAddresses == null || emailAddresses.Length == 0)
{
    throw new OSCException(@"No emails", OSCExceptions.OSC_E_INVALIDARG);
}

// Initialize the Activity Feed that will be returned.
ActivityFeed activityFeed = new ActivityFeed();
activityFeed.NetworkName = NETWORK_NAME;

// Get a client for interacting with OfficeTalk.
OfficeTalkClient otClient = OfficeTalkHelper.GetOfficeTalkClient();

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:

  1. The GetActivities override method checks the hashed parameter to identify whether the email addresses from the OSC are already hashed.

    • If the email addresses are not hashed, the GetActivities override method calls the OSC Provider Proxy Library Hash helper method to hash the email address. The GetActivities override method then calls the OfficeTalk GetUserFromHash method to look up the OfficeTalk user.

    • If the email addresses are hashed, the GetActivities override method calls the OfficeTalk GetUserFromHash method directly. If the GetActivities override method finds an OfficeTalk user, and the user is not already included in the list of unique users, the user is added to the list of unique users.

  2. The GetActivities override method then checks the dynamic parameter to see whether the email addresses are for a single person.

  3. If the email addresses are for a single person, the GetActivities override method exits the foreach loop as soon it finds an OfficeTalk user.

// First use the email addresses to create a list of unique 
// OfficeTalk users to get activities for.
List<OTUser> uniquePeople = new List<OTUser>();

// For each email address, call the OfficeTalk API to get the user.
foreach (string emailAddress in emailAddresses)
{
    OTUser otUser = null;

    // Check to see whether the email addresses are already hashed.
    if (!hashed)
    {
        // Hash the email address to find the user in OfficeTalk.
        string hashedEmailAddress =
            OSCProvider.Helpers.Hash(emailAddress, HashFunction.SHA1);

        otUser = otClient.GetUserFromHash(hashedEmailAddress, Format.JSON);
    }
    else
    {
        // Email is already hashed; find the user in OfficeTalk.
        otUser = otClient.GetUserFromHash(emailAddress, Format.JSON);
    }

    // If an OfficeTalk user was found and they are not already in the 
    // uniquePeople list, add them to the list.
    if (otUser != null)
    {
        if (!uniquePeople.Contains(otUser))
        {
            uniquePeople.Add(otUser);
        }
    }

    // If the dynamic parameter was set, all email addresses will be for 
    // one person, and any remaining email addresses can be ignored.
    if (dynamic && uniquePeople.Count > 0)
    {
        break;
    }
}

The following section of the GetActivities override method populates the ActivityFeed with messages from OfficeTalk. The code completes the following steps:

  1. The GetActivities override method calls the OfficeTalk GetUserMessages method for each OfficeTalk user in the list of unique users to get the OfficeTalk messages for that user.

  2. The GetActivities override method checks each message's created_atAsDateTime property against the startTime parameter to determine whether the message was created before the minimum start time that was passed in from the OSC.

  3. If the message was created before the minimum start time, the GetActivities override method skips the message and processes the next message.

  4. The GetUserMessages method returns all OfficeTalk messages that the user created or replied to.

  5. The GetActivities override method checks to see whether user created the message, or whether it is a message that the user replied to.

    • If the message is one that the user replied to, the GetActivities override method calls the AddReplyMessagesToActivityFeed method to add each reply message to the ActivityFeed.

    • If the user created the message, the GetActivities override method calls the AddMessageToActivityFeed method to add the message to the ActivityFeed.

The AddReplyMessagesToActivityFeed and AddMessageToActivityFeed helper methods are covered in their own sections.

// For each of the OfficeTalk users, get the messages from OfficeTalk 
// and add them to the activity feed.
foreach (OTUser otUser in uniquePeople)
{
    // Call OfficeTalk to get all messages for the OfficeTalk User.
    // The GetUserMessages method will return all messages that the user
    // created, as well as all messages that the user responded to.
    List<OTMessage> messages =
        otClient.GetUserMessages(otUser.alias, Format.JSON);

    if (messages != null)
    {
        foreach (OTMessage message in messages)
        {
            // Skip any messages that have a created date that is earlier
            // than the startTime.
            if (message.created_atAsDateTime < startTime)
            {
                continue;
            }

            // Check to see whether the OfficeTalk user created this message,
            // or whether it is a message that the OfficeTalk user
            // replied to.
            if (message.user.id != otUser.id)
            {
                // Add the OfficeTalk reply messages to the activity feed.
                AddReplyMessagesToActivityFeed(activityFeed, otUser, message);
            }
            else
            {
                // Add the OfficeTalk message to the activity feed.
                AddMessageToActivityFeed(activityFeed, otUser, message);
            }
        }
    }
}

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.

// If there are activities to return, return the activity feed.
// If there are no activities, return the OSC_E_NO_CHANGES error 
// that the OSC expects.
if (activityFeed.Activities.Count > 0)
{
    return activityFeed;
}
else
{
    throw new OSCException(@"No activities", OSCExceptions.OSC_E_NO_CHANGES);
}

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 current user did not create this message but replied to it.
// Identify which of the replies to the message are from the current user.
List<OTMessage> replies = new List<OTMessage>();
foreach (OTMessage reply in message.recent_replies)
{
    if (reply.user.id == user.id)
    {
        replies.Add(reply);
    }

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:

  1. The ApplicationId property identifies which application this activity is for.

  2. This Visual How To has only one application, so the AddReplyMessagesToActivityFeed method sets the ApplicationID property to a value of 1.

  3. The AddReplyMessagesToActivityFeed method the sets the ActivityType property to Status Update.

  4. The AddReplyMessagesToActivityFeed method sets the ActivityID (a unique identifier) to the ID of the reply message.

  5. The AddReplyMessagesToActivityFeed method sets the OwnerID property to the OfficeTalk user for whom the activity feed is being created.

  6. Finally, the AddReplyMessagesToActivityFeed method sets the PublishDate property to the created date of the message.

// Initialize the activity feed item.
Activity activity = new Activity();
// ApplicationId is one of the two unique IDs used to match an 
// activity feed item with its template.
activity.ApplicationId = 1;
activity.ActivityType = ActivityTypes.StatusUpdate;
activity.ActivityID = reply.id.ToString(CultureInfo.InvariantCulture);
activity.OwnerID = reply.user.id.ToString(CultureInfo.InvariantCulture);
activity.PublishDate = reply.created_atAsDateTime;

The following section of the AddReplyMessagesToActivityFeed method builds the title section based on the reply message text. The code completes the following steps:

  1. The AddReplyMessagesToActivityFeed method cleans up the text by decoding it and converting any braces to parentheses.

  2. The method then calls the OSC Proxy Library AutoReplace helper method.

    The AutoReplace method replaces HTTP URLs, @tags, and #tags that are contained within a text string with integer index placeholders, and then returns a list of TemplateVariables for those placeholders.

// Build the title section based on the OfficeTalk message text.
string title = System.Net.WebUtility.HtmlDecode(reply.text);
title = title.Replace(@"{", @"(").Replace(@"}", @")");

// The OSC Provider Proxy Library AutoReplace helper method will create 
// a collection of template variables based on detecting certain types 
// of data in the input string: HTTP URLs, @tags, and #tags.
List<TemplateVariable> titleTemplateVars;
titleTemplateVars = AutoTemplate.AutoReplace(
    OTProvider.API_URL + @"/home/index/{0}#user",
    OTProvider.API_URL + @"/home/index/~{0}#user",
    ref title,
    SCHEMA_VERSION);

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:

  1. The AddReplyMessagesToActivityFeed method creates an EntityVariable for the publisher of the original message.

  2. The AddReplyMessagesToActivityFeed method sets the ID, EmailAddress, NameHint, and ProfileURL properties to the values for the user who created the original message.

  3. The method then adds the publisher EntityVariable to the list of template variables for the title.

  4. Finally, the AddReplyMessagesToActivityFeed method updates the title text to include an integer index placeholder for the publisher template variable.

// Update the title to display who created the original message.
// Add information to the title template variables about the 
// OfficeTalk user who posted the original message.
EntityVariable publisher = new EntityVariable();
publisher.Name = @"Publisher";
publisher.ID = message.user.id.ToString(CultureInfo.InvariantCulture);
publisher.EmailAddress = message.user.email;
publisher.NameHint = message.user.name;
publisher.ProfileURL =
    OTProvider.API_URL +
    string.Format(CultureInfo.InvariantCulture,
                  @"/home/index/{0}#user",
                  message.user.alias);

// Add the publisher to the title template variables.
titleTemplateVars.Add(publisher);

// Update the title format to include the publisher.
// Publisher information will be the last item in the title template variables.
int publisherIndex = titleTemplateVars.Count - 1;
title = @String.Format("Replied to {{{0}}}: ", publisherIndex) + title;

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:

  1. The AddReplyMessagesToActivityFeed method calls the GetOTPictureUrls helper method to obtain a list of picture URLs that are included in the OfficeTalk message text.

  2. Because the OSC requires that picture URLs be placed within a ListVariable, the AddReplyMessagesToActivityFeed method creates a ListVariable that has a name of "Pictures".

  3. Then the AddReplyMessagesToActivityFeed method creates a SimplePictureVariable that has a name of "Picture" for each picture URL, sets the SimplePictureVariableValue and Href properties based on the URL for the picture, and adds the SimplePictureVariable to the ListVariable.

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.

// Parse any OTPic URLs from the OfficeTalk reply message.
String[] otPictureUrls = GetOTPictureUrls(reply.text);
if (otPictureUrls != null && otPictureUrls.Length > 0)
{
    // OSC requires that picture URLs be placed in a ListVariable.
    ListVariable pictures = new ListVariable();
    pictures.Name = "Pictures";

    // Create a SimplePictureVariable for each picture and add it to the list.
    foreach (string otPictureUrl in otPictureUrls)
    {
        SimplePictureVariable picture = new SimplePictureVariable();
        picture.Name = "Picture";
        picture.Value = new Uri(FixOTPictureUrl(otPictureUrl));
        picture.Href = new Uri(otPictureUrl);
        pictures.ListItems.Add(picture);
    }
    // Add the pictures to the activity template variables.
    activity.TemplateVariables.Add(pictures);
}

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:

  1. The AddReplyMessagesToActivityFeed method evaluates the number of replies to define the appropriate text to display for the hyperlink.

  2. AddReplyMessagesToActivityFeed defines a LinkVariable by using the name "OriginalMessageLink", sets the Text property to the appropriate display text, and sets the Value property to a URL that will display the original message.

  3. Finally, the AddReplyMessagesToActivityFeed method creates the data TemplateVariables list and adds the LinkVariable to the list.

// Build the text to display for the original OfficeTalk message 
// hyperlink based on the number of replies.
// If there are no replies, View Post is displayed.
long numberOfReplies =
    message.reply_count.HasValue ? message.reply_count.Value : 0;
string replyWord = numberOfReplies == 1 ? @"Reply" : @"Replies";
string replyText = numberOfReplies > 0 ?
    string.Format(CultureInfo.CurrentCulture,
                  "{0} {1}",
                  numberOfReplies,
                  replyWord)
    : "View Post";

// Build the OfficeTalk message hyperlink.
LinkVariable messageLink = new LinkVariable();
messageLink.Name = "OriginalMessageLink";
messageLink.Text = replyText;
messageLink.Value =
    new Uri(OTProvider.API_URL
          + @"/Messages/"
          + message.id.ToString(CultureInfo.InvariantCulture));

// Add the hyperlink to the data template variables.
List<TemplateVariable> dataTemplateVars = new List<TemplateVariable>();
dataTemplateVars.Add(messageLink);

The following section of the AddReplyMessagesToActivityFeed method builds the icon section. The code completes the following steps:

  1. The AddReplyMessagesToActivityFeed method creates the icon TemplateVariables list.

  2. The AddReplyMessagesToActivityFeed method creates a LinkVariable for the icon using the name of "Icon", sets the Text property to Status Update, and sets the Value property to the URL for the icon.

  3. Finally, the AddReplyMessageToActivityFeed method adds the icon to the icon TemplateVariables list.

// Build the icon section.
// The icon displayed is the same as for the social network.
List<TemplateVariable> iconTemplateVars = new List<TemplateVariable>();
LinkVariable icon = new LinkVariable();
icon.Name = "Icon";
icon.Text = "Status Update";
icon.Value =
    new Uri(OTProvider.API_URL
          + @"/_layouts/OfficeTalk/content/images/logo.png");
iconTemplateVars.Add(icon);

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.

// Call Proxy Library's CreateTemplate helper method to create the 
// template used to display the activity data.
Template template = AutoTemplate.CreateTemplate(
    activity,           // Activity the template is being created for.
    title,              // Title format string.
    "{0}",              // Data format string.
    "{0}",              // Icon format string.
    titleTemplateVars,  // Title variables.
    dataTemplateVars,   // Data variables.
    iconTemplateVars,   // Icon variables.
    SCHEMA_VERSION);

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.

// If pictures are included, update the template's Data format to display 
// the pictures before the hyperlink for the OfficeTalk message.
if (otPictureUrls != null && otPictureUrls.Length > 0)
{
    template.Data = @"{list:Pictures({picture:Picture})}" + template.Data;
}

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.

// Add only the activity and template if both contain valid XML.
if (!String.IsNullOrEmpty(activity.Xml) && !String.IsNullOrEmpty(template.Xml))
{
    activityFeed.Activities.Add(activity);
    activityFeed.Templates.Add(template);
}

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:

  1. It defines information for the title, data, and information sections.

  2. It calls the CreateTemplate helper method to create the template for the article.

  3. It validates the article and template XML before adding them to the activity feed.

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:

  • GetProviderData—Returns information about the OSC provider capabilities and information about the social network.

  • GetMe—Returns information about the current user.

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:

  • GetPeopleDetails—Returns detailed user information for the email addresses that are passed into the method.

  • GetFriends—Returns a list of friends for the current user.

  • FollowPersonEx—Adds the person who is identified by the email address as a friend on the social network.

  • UnFollowPerson—Removes the person who is identified by the user ID as a friend on the social network.

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.

Read It

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

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.

See It

Watch the video

Watch video

Length: 16:11

Click to grab code

Grab the Code

Explore It
Show:
© 2014 Microsoft