Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Cleaning up the source in Microsoft.AspNet.Mvc.Facebook

  • Loading branch information...
commit e01ea550728e8fe1e025274d2920deab65c58a52 1 parent 05f4b86
yaohuang authored
Showing with 97 additions and 158 deletions.
  1. +1 −0  packages/repositories.config
  2. +8 −9 src/Microsoft.AspNet.Mvc.Facebook/Attributes/FacebookAuthorizeAttribute.cs
  3. +3 −1 src/Microsoft.AspNet.Mvc.Facebook/Attributes/FacebookUserFieldsAttribute.cs
  4. +0 −16 src/Microsoft.AspNet.Mvc.Facebook/Controllers/FacebookRealTimeHub.cs
  5. +0 −12 src/Microsoft.AspNet.Mvc.Facebook/Controllers/FacebookRealTimeUpdate.cs
  6. +1 −1  src/Microsoft.AspNet.Mvc.Facebook/Controllers/FacebookRealtimeController.cs
  7. +3 −2 src/Microsoft.AspNet.Mvc.Facebook/Extensions/HtmlHelperExtensions.cs
  8. +13 −22 src/Microsoft.AspNet.Mvc.Facebook/Microsoft.AspNet.Mvc.Facebook.csproj
  9. +0 −1  src/Microsoft.AspNet.Mvc.Facebook/Models/FacebookObjectList.cs
  10. +10 −23 src/Microsoft.AspNet.Mvc.Facebook/Models/FacebookObjectModelBinder.cs
  11. +6 −6 src/Microsoft.AspNet.Mvc.Facebook/Models/FacebookUserModelBinder.cs
  12. +3 −8 src/Microsoft.AspNet.Mvc.Facebook/Services/DefaultFacebookObjectStorageService.cs
  13. +32 −34 src/Microsoft.AspNet.Mvc.Facebook/Services/DefaultFacebookService.cs
  14. +3 −8 src/Microsoft.AspNet.Mvc.Facebook/Services/DefaultFacebookUserStorageService.cs
  15. +2 −1  src/Microsoft.AspNet.Mvc.Facebook/Services/IFacebookService.cs
  16. +12 −14 src/Microsoft.AspNet.Mvc.Facebook/packages.config
View
1  packages/repositories.config
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<repositories>
+ <repository path="..\src\Microsoft.AspNet.Mvc.Facebook\packages.config" />
<repository path="..\src\Microsoft.Web.Http.Data.EntityFramework\packages.config" />
<repository path="..\src\Microsoft.Web.Http.Data.Helpers\packages.config" />
<repository path="..\src\Microsoft.Web.Http.Data\packages.config" />
View
17 src/Microsoft.AspNet.Mvc.Facebook/Attributes/FacebookAuthorizeAttribute.cs
@@ -27,7 +27,6 @@ public FacebookAuthorizeAttribute(IFacebookService facebookService)
public void OnAuthorization(AuthorizationContext filterContext)
{
-
// TODO: (ntotten) - Handle scenario where user denies authorization
// https://www.facebook.com/dialog/oauth?perms=email&redirect_uri=https://apps.facebook.com/mvctetmsadsf/Home/Test?error_reason=user_denied&error=access_denied&error_description=The+user+denied+your+request.&client_id=202821839850333
@@ -72,10 +71,10 @@ public void OnAuthorization(AuthorizationContext filterContext)
redirect_uri = redirectUri,
client_id = FacebookSettings.AppId
});
- var fbAuthResult = new ContentResult();
- fbAuthResult.ContentType = "text/html";
- fbAuthResult.Content = String.Format("<script>window.top.location = '{0}';</script>", loginUrl.AbsoluteUri);
- filterContext.Result = fbAuthResult;
+ var facebookAuthResult = new ContentResult();
+ facebookAuthResult.ContentType = "text/html";
+ facebookAuthResult.Content = String.Format("<script>window.top.location = '{0}';</script>", loginUrl.AbsoluteUri);
+ filterContext.Result = facebookAuthResult;
}
}
@@ -111,10 +110,10 @@ private ContentResult GetRedirectTopResult(HttpRequestBase request, string url)
FacebookSettings.AppNamespace,
url);
- var fbAuthResult = new ContentResult();
- fbAuthResult.ContentType = "text/html";
- fbAuthResult.Content = String.Format("<script>window.top.location = '{0}';</script>", url);
- return fbAuthResult;
+ var facebookAuthResult = new ContentResult();
+ facebookAuthResult.ContentType = "text/html";
+ facebookAuthResult.Content = String.Format("<script>window.top.location = '{0}';</script>", url);
+ return facebookAuthResult;
}
}
}
View
4 src/Microsoft.AspNet.Mvc.Facebook/Attributes/FacebookUserFieldsAttribute.cs
@@ -9,7 +9,9 @@ namespace Microsoft.AspNet.Mvc.Facebook.Attributes
[AttributeUsage(AttributeTargets.Parameter, Inherited = true)]
public class FacebookUserFieldsAttribute : CustomModelBinderAttribute
{
- public FacebookUserFieldsAttribute() { }
+ public FacebookUserFieldsAttribute()
+ {
+ }
public FacebookUserFieldsAttribute(string fields)
{
View
16 src/Microsoft.AspNet.Mvc.Facebook/Controllers/FacebookRealTimeHub.cs
@@ -1,16 +0,0 @@
-// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
-
-using SignalR.Hubs;
-using System;
-
-namespace Microsoft.AspNet.Mvc.Facebook.Controllers
-{
- [CLSCompliant(false)]
- public class FacebookRealTimeHub : Hub
- {
- public void Send(string data)
- {
- Clients.addMessage(data);
- }
- }
-}
View
12 src/Microsoft.AspNet.Mvc.Facebook/Controllers/FacebookRealTimeUpdate.cs
@@ -1,12 +0,0 @@
-// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
-
-using SignalR.Hubs;
-using System;
-
-namespace Microsoft.AspNet.Mvc.Facebook.Controllers
-{
- [CLSCompliant(false)]
- public class FacebookRealTimeUpdate : Hub
- {
- }
-}
View
2  src/Microsoft.AspNet.Mvc.Facebook/Controllers/FacebookRealtimeController.cs
@@ -28,7 +28,7 @@ public FacebookRealtimeController(IFacebookService facebookService, IFacebookUse
this.facebookUserStorageService = facebookUserStorageService;
}
- [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
+ [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Handled by the infrastructure")]
public HttpResponseMessage Get([FromUri(Name = "hub")] SubscriptionVerification subscriptionVerification)
{
if (subscriptionVerification.Mode == "subscribe" && subscriptionVerification.Verify_Token == facebookService.VerificationToken)
View
5 src/Microsoft.AspNet.Mvc.Facebook/Extensions/HtmlHelperExtensions.cs
@@ -1,5 +1,6 @@
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
+using System;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Html;
@@ -11,11 +12,11 @@ public static class HtmlHelperExtensions
public static IHtmlString FacebookSignedRequest(this HtmlHelper helper)
{
var signedRequest = helper.ViewContext.HttpContext.Request.Params["signed_request"];
- if (!string.IsNullOrEmpty(signedRequest))
+ if (!String.IsNullOrEmpty(signedRequest))
{
return helper.Hidden("signed_request", signedRequest);
}
- return new HtmlString("");
+ return new HtmlString(String.Empty);
}
}
}
View
35 src/Microsoft.AspNet.Mvc.Facebook/Microsoft.AspNet.Mvc.Facebook.csproj
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
- <Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
+ <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory),Runtime.sln))\tools\WebStack.settings.targets" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
@@ -11,15 +11,7 @@
<AssemblyName>Microsoft.AspNet.Mvc.Facebook</AssemblyName>
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
- <SccProjectName>
- </SccProjectName>
- <SccLocalPath>
- </SccLocalPath>
- <SccAuxPath>
- </SccAuxPath>
- <SccProvider>
- </SccProvider>
- <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\</SolutionDir>
+ <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir>
<RestorePackages>true</RestorePackages>
<TargetFrameworkProfile />
</PropertyGroup>
@@ -28,7 +20,7 @@
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>..\..\bin\Extensions\Debug\</OutputPath>
- <DefineConstants>DEBUG;TRACE</DefineConstants>
+ <DefineConstants>DEBUG;TRACE;ASPNETMVC;$(DefineConstants)</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@@ -36,7 +28,7 @@
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\..\bin\Extensions\Release\</OutputPath>
- <DefineConstants>TRACE</DefineConstants>
+ <DefineConstants>TRACE;ASPNETMVC;$(DefineConstants)</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
@@ -55,12 +47,6 @@
<Reference Include="Newtonsoft.Json">
<HintPath>..\..\packages\Newtonsoft.Json.4.5.9\lib\net40\Newtonsoft.Json.dll</HintPath>
</Reference>
- <Reference Include="SignalR">
- <HintPath>..\..\packages\SignalR.Server.0.5.3\lib\net40\SignalR.dll</HintPath>
- </Reference>
- <Reference Include="SignalR.Hosting.Common">
- <HintPath>..\..\packages\SignalR.Hosting.Common.0.5.3\lib\net40\SignalR.Hosting.Common.dll</HintPath>
- </Reference>
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.configuration" />
@@ -111,9 +97,7 @@
<Compile Include="Attributes\FacebookUserAttribute.cs" />
<Compile Include="Attributes\FacebookObjectAttribute.cs" />
<Compile Include="Controllers\FacebookRealtimeController.cs" />
- <Compile Include="Controllers\FacebookRealTimeHub.cs" />
<Compile Include="Controllers\FacebookRealTimeLogController.cs" />
- <Compile Include="Controllers\FacebookRealTimeUpdate.cs" />
<Compile Include="Extensions\FacebookUserExtensions.cs" />
<Compile Include="Extensions\HtmlHelperExtensions.cs" />
<Compile Include="Extensions\Utilities.cs" />
@@ -136,13 +120,20 @@
<Compile Include="Services\IFacebookUserEvents.cs" />
</ItemGroup>
<ItemGroup>
+ <CodeAnalysisDictionary Include="..\CodeAnalysisDictionary.xml" />
+ </ItemGroup>
+ <ItemGroup>
<Compile Include="..\ExtensionsCommonAssemblyInfo.cs">
<Link>Properties\ExtensionsCommonAssemblyInfo.cs</Link>
</Compile>
</ItemGroup>
<ItemGroup>
- <None Include="App.config" />
- <None Include="packages.config" />
+ <None Include="App.config">
+ <SubType>Designer</SubType>
+ </None>
+ <None Include="packages.config">
+ <SubType>Designer</SubType>
+ </None>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="$(SolutionDir)\.nuget\nuget.targets" />
View
1  src/Microsoft.AspNet.Mvc.Facebook/Models/FacebookObjectList.cs
@@ -7,6 +7,5 @@ namespace Microsoft.AspNet.Mvc.Facebook.Models
[Attributes.FacebookObject]
public class FacebookObjectList<FacebookObject> : List<FacebookObject>
{
- //public DateTime? LastUpdated { get; set; }
}
}
View
33 src/Microsoft.AspNet.Mvc.Facebook/Models/FacebookObjectModelBinder.cs
@@ -48,14 +48,12 @@ public object BindModel(ControllerContext controllerContext, ModelBindingContext
private object GetObjects(Type modelType, string userFacebookId, global::Facebook.FacebookClient client)
{
var typeName = GetTypeName(modelType);
- if (string.IsNullOrEmpty(typeName))
+ if (String.IsNullOrEmpty(typeName))
{
return null;
}
- //TODO: (ErikPo) Figure out how to call a generic method with only the modelType
- var mi = facebookObjectStorageService.GetType().GetMethod("GetObjects");
- var objects = (FacebookObjectList<FacebookObject>)mi.Invoke(facebookObjectStorageService, new object[] { userFacebookId }); //facebookObjectStorageService.GetObjects(userFacebookId);
+ var objects = facebookObjectStorageService.GetObjects(userFacebookId);
if (objects == null || objects.Count == 0/* || Some other time period has been met and we should sync again */)
{
@@ -102,15 +100,6 @@ private Type GetGenericType(Type modelType)
private object LoadObjects(global::Facebook.FacebookClient client, Type modelType, string userFacebookId, string query)
{
- //var lastUpdated = user.GetType().GetProperties().FirstOrDefault(pi => pi.PropertyType == typeof(DateTime?) && pi.Name == "FriendsLastUpdated");
- //if (lastUpdated != null) {
- // var lastUpdatedValue = (DateTime?)lastUpdated.GetValue(user, null);
- // //TODO: (ErikPo) Decide if this should be configurable
- // if (lastUpdatedValue.HasValue && lastUpdatedValue.Value.AddHours(1) < DateTime.UtcNow) {
- // return false;
- // }
- //}
-
dynamic objects = Activator.CreateInstance(modelType);
dynamic objectList = client.Get(query);
var genericType = GetGenericType(modelType);
@@ -172,8 +161,6 @@ private object LoadObjects(global::Facebook.FacebookClient client, Type modelTyp
}
}
- //lastUpdated.SetValue(user, DateTime.UtcNow, null);
-
return objects;
}
@@ -193,7 +180,7 @@ private void ApplyFields(FacebookObject obj, dynamic values)
{
var facebookFields = GetObjectFields(obj.GetType());
PropertyInfo userProperty;
- string fbFieldName;
+ string fieldName;
object fieldValue;
foreach (var field in facebookFields)
{
@@ -202,14 +189,14 @@ private void ApplyFields(FacebookObject obj, dynamic values)
continue;
}
userProperty = field.Key;
- fbFieldName = field.Value != null ? field.Value.JsonField : "";
- if (!string.IsNullOrEmpty(fbFieldName))
+ fieldName = field.Value != null ? field.Value.JsonField : String.Empty;
+ if (!String.IsNullOrEmpty(fieldName))
{
- fieldValue = GetFBFieldValue(values, fbFieldName.Split('.'));
+ fieldValue = GetFacebookFieldValue(values, fieldName.Split('.'));
}
else
{
- fieldValue = GetFBFieldValue(values, new[] { userProperty.Name });
+ fieldValue = GetFacebookFieldValue(values, new[] { userProperty.Name });
}
if (fieldValue != null)
{
@@ -237,12 +224,12 @@ private void ApplyFields(FacebookObject obj, dynamic values)
return fields;
}
- private object GetFBFieldValue(dynamic facebookObject, IEnumerable<string> fieldNameParts)
+ private object GetFacebookFieldValue(dynamic facebookObject, IEnumerable<string> fieldNameParts)
{
dynamic subFacebookObject;
try
{
- subFacebookObject = facebookObject[fieldNameParts.ElementAt(0).ToLower()];
+ subFacebookObject = facebookObject[fieldNameParts.ElementAt(0).ToLowerInvariant()];
}
catch
{
@@ -256,7 +243,7 @@ private object GetFBFieldValue(dynamic facebookObject, IEnumerable<string> field
{
return subFacebookObject;
}
- return GetFBFieldValue(subFacebookObject, fieldNameParts.Skip(1));
+ return GetFacebookFieldValue(subFacebookObject, fieldNameParts.Skip(1));
}
}
}
View
12 src/Microsoft.AspNet.Mvc.Facebook/Models/FacebookUserModelBinder.cs
@@ -56,7 +56,7 @@ private object GetUser(Type modelType, string facebookId, global::Facebook.Faceb
//TODO: (ErikPo) Fill in the other half of this condition
if (user == null/* or this is the first time the app has started */)
{
- object userFields = client.Get("me" + (!string.IsNullOrEmpty(fields) ? "?fields=" + fields.Replace(" ", "") : facebookService.GetFields(modelType)));
+ object userFields = client.Get("me" + (!String.IsNullOrEmpty(fields) ? "?fields=" + fields.Replace(" ", String.Empty) : facebookService.GetFields(modelType)));
if (modelType == typeof(FacebookUser))
{
@@ -72,7 +72,7 @@ private object GetUser(Type modelType, string facebookId, global::Facebook.Faceb
var facebookFields = GetUserFields(modelType);
PropertyInfo userProperty;
- string fbFieldName;
+ string facebookFieldName;
object fieldValue;
foreach (var field in facebookFields)
{
@@ -81,10 +81,10 @@ private object GetUser(Type modelType, string facebookId, global::Facebook.Faceb
continue;
}
userProperty = field.Key;
- fbFieldName = field.Value != null ? field.Value.JsonField : "";
- if (!string.IsNullOrEmpty(fbFieldName))
+ facebookFieldName = field.Value != null ? field.Value.JsonField : String.Empty;
+ if (!String.IsNullOrEmpty(facebookFieldName))
{
- fieldValue = GetFBFieldValue(userFields, fbFieldName.Split('.'));
+ fieldValue = GetFBFieldValue(userFields, facebookFieldName.Split('.'));
}
else
{
@@ -126,7 +126,7 @@ private object GetFBFieldValue(dynamic facebookObject, IEnumerable<string> field
dynamic subFacebookObject;
try
{
- subFacebookObject = facebookObject[fieldNameParts.ElementAt(0).ToLower()];
+ subFacebookObject = facebookObject[fieldNameParts.ElementAt(0).ToLowerInvariant()];
}
catch
{
View
11 src/Microsoft.AspNet.Mvc.Facebook/Services/DefaultFacebookObjectStorageService.cs
@@ -9,22 +9,17 @@ namespace Microsoft.AspNet.Mvc.Facebook.Services
public class DefaultFacebookObjectStorageService : IFacebookObjectStorageService
{
private readonly SortedList<string, FacebookObjectList<FacebookObject>> objects;
- private static DefaultFacebookObjectStorageService instance;
+ private static DefaultFacebookObjectStorageService instance = new DefaultFacebookObjectStorageService();
public DefaultFacebookObjectStorageService()
{
- objects = new SortedList<string, FacebookObjectList<FacebookObject>>(100);
+ objects = new SortedList<string, FacebookObjectList<FacebookObject>>();
}
public static DefaultFacebookObjectStorageService Instance
{
get
{
- if (instance == null)
- {
- instance = new DefaultFacebookObjectStorageService();
- }
-
return instance;
}
}
@@ -36,7 +31,7 @@ public FacebookObjectList<FacebookObject> GetObjects(string userFacebookId)
return objects[userFacebookId];
}
- return null;
+ return new FacebookObjectList<FacebookObject>();
}
public void AddObject(FacebookObject obj)
View
66 src/Microsoft.AspNet.Mvc.Facebook/Services/DefaultFacebookService.cs
@@ -16,7 +16,10 @@ namespace Microsoft.AspNet.Mvc.Facebook.Services
public class DefaultFacebookService : IFacebookService
{
private readonly IFacebookUserStorageService facebookUserStorageService;
- private static DefaultFacebookService instance;
+ private static DefaultFacebookService instance = new DefaultFacebookService();
+ private string verificationToken;
+ private static bool isRealtimeInitialized;
+ private static string _accessTokenUrl = "https://graph.facebook.com/oauth/access_token?client_id={0}&client_secret={1}&grant_type=client_credentials";
public DefaultFacebookService()
: this(FacebookSettings.DefaultUserStorageService)
@@ -32,11 +35,6 @@ public static DefaultFacebookService Instance
{
get
{
- if (instance == null)
- {
- instance = new DefaultFacebookService();
- }
-
return instance;
}
}
@@ -49,8 +47,6 @@ public IFacebookUserStorageService Storage
}
}
- //TODO: (ErikPo) Confirm if this being app instance specific is ok or not
- private static string verificationToken;
public string VerificationToken
{
get
@@ -69,11 +65,11 @@ public string VerificationToken
}
//TODO: (ErikPo) Cache this for a while
- [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope")]
+ [SuppressMessage("Microsoft.Reliability", "CA2000:Dispose objects before losing scope", Justification = "Should be auto-disposed")]
public string GetAppAccessToken()
{
var client = new WebClient();
- var value = client.DownloadString(string.Format("https://graph.facebook.com/oauth/access_token?client_id={0}&client_secret={1}&grant_type=client_credentials", FacebookSettings.AppId, FacebookSettings.AppSecret));
+ var value = client.DownloadString(String.Format(_accessTokenUrl, FacebookSettings.AppId, FacebookSettings.AppSecret));
if (value.StartsWith("access_token="))
{
return value.Substring("access_token=".Length);
@@ -92,7 +88,7 @@ private TUser RefreshUser<TUser>(TUser user, string accessToken) where TUser : F
return user;
}
- var userFieldsQuery = userFields.Count() > 0 ? "?fields=" + string.Join(",", userFields) : "";
+ var userFieldsQuery = userFields.Count() > 0 ? "?fields=" + String.Join(",", userFields) : String.Empty;
var client = CreateClient(accessToken);
if (user == null)
@@ -301,7 +297,6 @@ public FacebookAuthorizationInfo Authorize(HttpContextBase httpContext, string[]
if (!String.IsNullOrWhiteSpace(accessToken) && !String.IsNullOrWhiteSpace(facebookId))
{
-
// Get permissions from storage service and check if user has all required permissions
currentPermissions = this.facebookUserStorageService.GetPermissions(facebookId);
isAuthorized = HasRequiredPermissions(currentPermissions, permissions);
@@ -322,7 +317,9 @@ public FacebookAuthorizationInfo Authorize(HttpContextBase httpContext, string[]
{
var permsData = data[0] as IDictionary<string, object>;
if (permsData == null)
+ {
currentPermissions = new string[0];
+ }
else
{
currentPermissions = (from perm in permsData
@@ -335,7 +332,6 @@ public FacebookAuthorizationInfo Authorize(HttpContextBase httpContext, string[]
// Since the permissions have been retrieved from Graph API request
// update the storage service with the most current permissions.
this.facebookUserStorageService.SetPermissions(facebookId, currentPermissions);
-
}
catch (FacebookOAuthException)
{
@@ -358,7 +354,7 @@ public FacebookAuthorizationInfo Authorize(HttpContextBase httpContext, string[]
public void RefreshUserFields(FacebookUser user, params string[] fields)
{
var client = CreateClient();
- dynamic facebookUserFields = client.Get(user.FacebookId + (fields != null && fields.Length > 0 ? "?fields=" + string.Join(",", fields) : ""));
+ dynamic facebookUserFields = client.Get(user.FacebookId + (fields != null && fields.Length > 0 ? "?fields=" + String.Join(",", fields) : String.Empty));
RefreshUserFields(user, facebookUserFields, fields);
#if Debug
@@ -370,15 +366,15 @@ public void RefreshUserFields(FacebookUser user, dynamic userFields, params stri
{
var facebookFields = GetActualFields(user.GetType());
PropertyInfo userProperty;
- string fbFieldName;
+ string facebookFieldName;
object fieldValue;
foreach (var facebookField in facebookFields)
{
userProperty = facebookField.Key;
- fbFieldName = facebookField.Value != null ? facebookField.Value.JsonField : "";
- if (!string.IsNullOrEmpty(fbFieldName))
+ facebookFieldName = facebookField.Value != null ? facebookField.Value.JsonField : String.Empty;
+ if (!String.IsNullOrEmpty(facebookFieldName))
{
- fieldValue = GetFBFieldValue(userFields, fbFieldName.Split('.'));
+ fieldValue = GetFBFieldValue(userFields, facebookFieldName.Split('.'));
}
else
{
@@ -401,17 +397,17 @@ public string GetFields(Type modelType)
{
if (facebookField.Value == null)
{
- userFields.Add(facebookField.Key.Name.ToLower());
+ userFields.Add(facebookField.Key.Name.ToLowerInvariant());
}
- else if (!facebookField.Value.Ignore && !string.IsNullOrEmpty(facebookField.Value.FieldName))
+ else if (!facebookField.Value.Ignore && !String.IsNullOrEmpty(facebookField.Value.FieldName))
{
userFields.Add(facebookField.Value.FieldName);
}
}
- return "?fields=" + string.Join(",", userFields);
+ return "?fields=" + String.Join(",", userFields);
}
- return "";
+ return String.Empty;
}
private IDictionary<PropertyInfo, FacebookFieldAttribute> GetActualFields(Type modelType)
@@ -473,7 +469,7 @@ public FacebookClient CreateClient(string accessToken = null)
var client = new FacebookClient();
client.AppId = FacebookSettings.AppId;
- if (!string.IsNullOrEmpty(accessToken))
+ if (!String.IsNullOrEmpty(accessToken))
{
client.AccessToken = accessToken;
}
@@ -484,7 +480,7 @@ public string GetRealtimeFields(Type userType)
{
if (userType == null || userType == typeof(FacebookUser) || userType == typeof(object))
{
- return "";
+ return String.Empty;
}
var fields = new List<string>();
@@ -496,7 +492,7 @@ public string GetRealtimeFields(Type userType)
if (fbf != null && fbf.Length > 0 && fbf[0] is FacebookFieldAttribute)
{
var field = ((FacebookFieldAttribute)fbf[0]);
- if (!(field.Ignore || string.Equals(field.FieldName, "id", StringComparison.OrdinalIgnoreCase)))
+ if (!(field.Ignore || String.Equals(field.FieldName, "id", StringComparison.OrdinalIgnoreCase)))
{
fields.Add(field.FieldName);
}
@@ -507,14 +503,14 @@ public string GetRealtimeFields(Type userType)
}
else
{
- if (!string.Equals(property.Name, "id", StringComparison.OrdinalIgnoreCase))
+ if (!String.Equals(property.Name, "id", StringComparison.OrdinalIgnoreCase))
{
- fields.Add(property.Name.ToLower());
+ fields.Add(property.Name.ToLowerInvariant());
}
}
}
- return string.Join(",", fields);
+ return String.Join(",", fields);
}
private object GetSignedRequest(HttpContextBase httpContext)
@@ -533,18 +529,17 @@ private object GetSignedRequest(HttpContextBase httpContext)
return null;
}
- private static bool isRealtimeInitialized;
//TODO: (ErikPo) Make this async
public void InitializeRealtime(Type userType = null, string callbackUrl = null)
{
if (!isRealtimeInitialized)
{
- if (string.IsNullOrEmpty(callbackUrl))
+ if (String.IsNullOrEmpty(callbackUrl))
{
callbackUrl = FacebookSettings.RealtimeCallbackUrl;
}
- if (callbackUrl.ToLower().Contains("//localhost/") || callbackUrl.ToLower().Contains("//localhost:"))
+ if (callbackUrl.ToLowerInvariant().Contains("//localhost/") || callbackUrl.ToLowerInvariant().Contains("//localhost:"))
{
isRealtimeInitialized = true;
return;
@@ -552,12 +547,12 @@ public void InitializeRealtime(Type userType = null, string callbackUrl = null)
//TODO: (ErikPo) Replace all of this with something cleaner (HttpClient?) and make it async
var appRealtimeFields = GetRealtimeFields(userType);
- var request = WebRequest.Create(string.Format("https://graph.facebook.com/{0}/subscriptions?access_token={1}", FacebookSettings.AppId, GetAppAccessToken()));
+ var request = WebRequest.Create(String.Format("https://graph.facebook.com/{0}/subscriptions?access_token={1}", FacebookSettings.AppId, GetAppAccessToken()));
request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
using (var requestStream = request.GetRequestStream())
{
- var contentValue = "object=user" + (!string.IsNullOrEmpty(appRealtimeFields) ? "&fields=" + HttpUtility.UrlEncode(appRealtimeFields) : "") + "&callback_url=" + HttpUtility.UrlEncode(callbackUrl) + "&verify_token=" + VerificationToken;
+ var contentValue = "object=user" + (!String.IsNullOrEmpty(appRealtimeFields) ? "&fields=" + HttpUtility.UrlEncode(appRealtimeFields) : String.Empty) + "&callback_url=" + HttpUtility.UrlEncode(callbackUrl) + "&verify_token=" + VerificationToken;
#if Debug
Utilities.Log(contentValue);
#endif
@@ -570,7 +565,10 @@ public void InitializeRealtime(Type userType = null, string callbackUrl = null)
var response = request.GetResponse();
isRealtimeInitialized = true;
}
- catch { }
+ catch
+ {
+ //TODO: decide what to do with the exception
+ }
}
}
View
11 src/Microsoft.AspNet.Mvc.Facebook/Services/DefaultFacebookUserStorageService.cs
@@ -9,23 +9,18 @@ public class DefaultFacebookUserStorageService : IFacebookUserStorageService, IF
{
private readonly SortedList<string, FacebookUser> users;
private readonly SortedList<string, string[]> permissions;
- private static DefaultFacebookUserStorageService instance;
+ private static DefaultFacebookUserStorageService instance = new DefaultFacebookUserStorageService();
public DefaultFacebookUserStorageService()
{
- users = new SortedList<string, FacebookUser>(100);
- permissions = new SortedList<string, string[]>(100);
+ users = new SortedList<string, FacebookUser>();
+ permissions = new SortedList<string, string[]>();
}
public static DefaultFacebookUserStorageService Instance
{
get
{
- if (instance == null)
- {
- instance = new DefaultFacebookUserStorageService();
- }
-
return instance;
}
}
View
3  src/Microsoft.AspNet.Mvc.Facebook/Services/IFacebookService.cs
@@ -9,8 +9,9 @@ namespace Microsoft.AspNet.Mvc.Facebook.Services
{
public interface IFacebookService
{
- TUser LoadUser<TUser>(HttpContextBase httpContext) where TUser : FacebookUser, new();
string VerificationToken { get; set; }
+
+ TUser LoadUser<TUser>(HttpContextBase httpContext) where TUser : FacebookUser, new();
string GetAppAccessToken();
string GetFields(Type modelType);
void RefreshUserFields(FacebookUser user, params string[] fields);
View
26 src/Microsoft.AspNet.Mvc.Facebook/packages.config
@@ -1,19 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
- <package id="AspNetMvc" version="4.0.20710.0" targetFramework="net45" />
- <package id="AspNetWebApi" version="4.0.20710.0" targetFramework="net45" />
+ <package id="AspNetMvc" version="4.0.20710.0" targetFramework="net40" />
+ <package id="AspNetWebApi" version="4.0.20710.0" targetFramework="net40" />
<package id="EntityFramework" version="5.0.0" targetFramework="net40" />
<package id="Facebook" version="6.0.24" targetFramework="net40" />
- <package id="Microsoft.AspNet.Mvc" version="4.0.20710.0" targetFramework="net45" />
- <package id="Microsoft.AspNet.Razor" version="2.0.20710.0" targetFramework="net45" />
- <package id="Microsoft.AspNet.WebApi" version="4.0.20710.0" targetFramework="net45" />
- <package id="Microsoft.AspNet.WebApi.Client" version="4.0.20710.0" targetFramework="net45" />
- <package id="Microsoft.AspNet.WebApi.Core" version="4.0.20710.0" targetFramework="net45" />
- <package id="Microsoft.AspNet.WebApi.WebHost" version="4.0.20710.0" targetFramework="net45" />
- <package id="Microsoft.AspNet.WebPages" version="2.0.20710.0" targetFramework="net45" />
- <package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net45" />
- <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net45" />
- <package id="Newtonsoft.Json" version="4.5.9" targetFramework="net45" />
- <package id="SignalR.Hosting.Common" version="0.5.3" targetFramework="net45" />
- <package id="SignalR.Server" version="0.5.3" targetFramework="net45" />
+ <package id="Microsoft.AspNet.Mvc" version="4.0.20710.0" targetFramework="net40" />
+ <package id="Microsoft.AspNet.Razor" version="2.0.20710.0" targetFramework="net40" />
+ <package id="Microsoft.AspNet.WebApi" version="4.0.20710.0" targetFramework="net40" />
+ <package id="Microsoft.AspNet.WebApi.Client" version="4.0.20710.0" targetFramework="net40" />
+ <package id="Microsoft.AspNet.WebApi.Core" version="4.0.20710.0" targetFramework="net40" />
+ <package id="Microsoft.AspNet.WebApi.WebHost" version="4.0.20710.0" targetFramework="net40" />
+ <package id="Microsoft.AspNet.WebPages" version="2.0.20710.0" targetFramework="net40" />
+ <package id="Microsoft.Net.Http" version="2.0.20710.0" targetFramework="net40" />
+ <package id="Microsoft.Web.Infrastructure" version="1.0.0.0" targetFramework="net40" />
+ <package id="Newtonsoft.Json" version="4.5.6" targetFramework="net40" />
</packages>
Please sign in to comment.
Something went wrong with that request. Please try again.