MyOpenSpace.CreateActivityRequest
You use this CLR object to create activities that will go into a user's activity stream
Properties
- TemplateName the Template's name as entered in the MySpace Developer Platform
- Priority the creation priority: opensocial.CreateActivityPriority.HIGH or opensocial.CreateActivityPriority.Low
- MediaItems a List of the Media Item URLs
Methods
- MakeRequest() Make the request to create the activity. You should save the state of the control to isolated storage beforem making this request because the opensocial.requestCreateActivity() method will trigger a popup window in MySpace which removes the Silverlight application from the DOM.
Using this class
- Derive a class from this MyOpenSpace.CreateActivityRequest</description>
- Add parameters specific to this activity request as class properties</description>
- Override OnGetTemplateParameters() to add the parameters to the dictionary
Example from Activities sample
MyCreateActivitiesRequest.cs
namespace Activities
{
using System.Collections.Generic;
using MyOpenSpace;
/// <summary>
/// Activity request with an adjective parameter
/// </summary>
/// <remarks>this template has a ${adjective} parameter in its body</remarks>
public class MyCreateActivityRequest : CreateActivityRequest
{
/// <summary>
/// Gets or sets the adjective
/// </summary>
public string Adjective { get; set; }
/// <summary>
/// Add the parameters for this activity request
/// </summary>
/// <param name="parameters">the parameters collection</param>
public override void OnGetTemplateParameters(IDictionary<string, object> parameters)
{
parameters.Add("adjective", this.Adjective);
}
}
}
The Silverlight Page which hosts the MyCreateActivityRequest as a resource:
<UserControl x:Class="Activities.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:local="clr-namespace:Activities"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<UserControl.Resources>
<local:MyCreateActivityRequest x:Key="CreateActivityRequest" Adjective="Cool"
TemplateName="Template_1" Priority="opensocial.CreateActivityPriority.HIGH">
<local:MyCreateActivityRequest.MediaItems>
<sys:String>http://api.myspace.com/v1/users/228722276</sys:String>
</local:MyCreateActivityRequest.MediaItems>
</local:MyCreateActivityRequest>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" Background="Azure">
<StackPanel Orientation="Horizontal" VerticalAlignment="Top">
<TextBlock Text="Adjective: "/>
<TextBox
Text="{Binding Adjective, Source={StaticResource CreateActivityRequest}, Mode=TwoWay}"
MinWidth="100"/>
<Button Content="Create Activity" Click="OnCreateActivity"/>
</StackPanel>
</Grid>
</UserControl>
The Silverlight page code behind
namespace Activities
{
using System.Windows;
using System.Windows.Browser;
using System.Windows.Controls;
/// <summary>
/// Silverlight test page for CreateActivityRequest
/// </summary>
public partial class Page : UserControl
{
/// <summary>
/// Initializes a new instance of the Page class.
/// </summary>
public Page()
{
InitializeComponent();
}
/// <summary>
/// Create a new activity
/// </summary>
/// <param name="sender">the button</param>
/// <param name="e">the routed event arguments</param>
private void OnCreateActivity(object sender, RoutedEventArgs e)
{
var request = this.Resources["CreateActivityRequest"] as MyCreateActivityRequest;
request.MakeRequest();
}
}
}