My favorites | Sign in
Project Logo
       
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web.Mvc;
using System.Reflection;
using System.Web;
using System.Diagnostics;

using Facebook.Web;
using Facebook.Web.Configuration;
using Facebook.Service;
using Facebook.Service.Core;

namespace ManagedFusion.Web.Mvc
{
/// <summary>
///
/// </summary>
public class FacebookAttribute : ActionFilterAttribute
{
/// <summary>
/// Initializes a new instance of the <see cref="FacebookAttribute"/> class.
/// </summary>
public FacebookAttribute()
{
ActionParameterFacebookSession = "facebookSession";
ActionParameterFacebookService = "facebookService";
}

/// <summary>
/// The application key used to uniquely identify the application that is available
/// at application registration time.
/// This can only be set during initialization of the page.
/// </summary>
public string ApplicationKey
{
get;
set;
}

/// <summary>
/// The name of the application. This is used to create the application's canvas
/// page URL, i.e. http://apps.facebook.com/[name]/.
/// On the server, this is used to load settings from configuration. Specifically,
/// the facebook section in configuration is looked up for an application object
/// with the given name.
/// </summary>
public string ApplicationName
{
get;
set;
}

/// <summary>
/// The application secret used to authenticate API calls issued by the application that is
/// available at application registration time.
/// This can only be set during initialization of the page.
/// </summary>
public string Secret
{
get;
set;
}

/// <summary>
/// Gets or sets the action parameter facebook session.
/// </summary>
/// <value>The action parameter facebook session.</value>
public string ActionParameterFacebookSession
{
get;
set;
}

/// <summary>
/// Gets or sets the action parameter facebook service.
/// </summary>
/// <value>The action parameter facebook service.</value>
public string ActionParameterFacebookService
{
get;
set;
}

/// <summary>
/// Called when [action executing].
/// </summary>
/// <param name="filterContext">The filter context.</param>
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
FacebookApplicationSettings settings = FacebookSection.GetApplication(ApplicationName);

ApplicationKey = ApplicationKey ?? settings.ApiKey;
Secret = Secret ?? settings.Secret;

FacebookWebSession session = new FacebookWebSession(ApplicationKey, Secret);
session.Initialize(HttpContext.Current);

FacebookService service = new FacebookService(session);

if (filterContext.ActionParameters.ContainsKey(ActionParameterFacebookSession))
filterContext.ActionParameters[ActionParameterFacebookSession] = session;

if (filterContext.ActionParameters.ContainsKey(ActionParameterFacebookService))
filterContext.ActionParameters[ActionParameterFacebookService] = service;
}
}
}
Show details Hide details

Change log

r20 by nberardi on Jun 06, 2008   Diff
[No log message]
Go to: 

Older revisions

All revisions of this file

File info

Size: 3141 bytes, 109 lines
Hosted by Google Code