Skip to content
This repository was archived by the owner on Mar 20, 2019. It is now read-only.

Commit 1890e5d

Browse files
committed
StyleCop clean.
1 parent c419836 commit 1890e5d

8 files changed

Lines changed: 69 additions & 51 deletions

File tree

Settings.StyleCop

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
<StyleCopSettings Version="4.3">
2+
<Parsers>
3+
<Parser ParserId="Microsoft.StyleCop.CSharp.CsParser">
4+
<ParserSettings>
5+
<BooleanProperty Name="AnalyzeDesignerFiles">False</BooleanProperty>
6+
</ParserSettings>
7+
</Parser>
8+
</Parsers>
29
<Analyzers>
310
<Analyzer AnalyzerId="Microsoft.StyleCop.CSharp.SpacingRules">
411
<Rules>

samples/Consumer/SampleWcf.aspx.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
using System;
2-
using System.Linq;
2+
using System.Collections.Generic;
33
using System.Globalization;
4+
using System.Linq;
45
using System.Net;
56
using System.ServiceModel;
67
using System.ServiceModel.Channels;
8+
using System.ServiceModel.Security;
9+
using System.Web.UI.WebControls;
710
using DotNetOAuth;
811
using DotNetOAuth.ChannelElements;
912
using DotNetOAuth.Messaging;
1013
using SampleServiceProvider;
11-
using System.Collections.Generic;
12-
using System.Web.UI.WebControls;
13-
using System.ServiceModel.Security;
1414

1515
/// <summary>
1616
/// Sample consumer of our Service Provider sample's WCF service.
@@ -33,9 +33,10 @@ protected void getAuthorizationButton_Click(object sender, EventArgs e) {
3333
Consumer consumer = this.CreateConsumer();
3434
UriBuilder callback = new UriBuilder(Request.Url);
3535
callback.Query = null;
36-
string scope = string.Join("|", (from item in scopeList.Items.OfType<ListItem>()
37-
where item.Selected
38-
select item.Value).ToArray());
36+
string[] scopes = (from item in scopeList.Items.OfType<ListItem>()
37+
where item.Selected
38+
select item.Value).ToArray();
39+
string scope = string.Join("|", scopes);
3940
var requestParams = new Dictionary<string, string> {
4041
{ "scope", scope },
4142
};
Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
using System.Linq;
2-
using System.Globalization;
32
using System.ServiceModel;
4-
using System.Text;
53

64
public class DataApi : IDataApi {
5+
private static OAuthToken AccessToken {
6+
get { return OperationContext.Current.IncomingMessageProperties["OAuthAccessToken"] as OAuthToken; }
7+
}
8+
79
public int? GetAge() {
810
return AccessToken.User.Age;
911
}
@@ -15,8 +17,4 @@ public string GetName() {
1517
public string[] GetFavoriteSites() {
1618
return AccessToken.User.FavoriteSites.Select(site => site.SiteUrl).ToArray();
1719
}
18-
19-
private static OAuthToken AccessToken {
20-
get { return OperationContext.Current.IncomingMessageProperties["OAuthAccessToken"] as OAuthToken; }
21-
}
2220
}

samples/ServiceProvider/App_Code/DatabaseTokenManager.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
//-----------------------------------------------------------------------
66

77
using System;
8-
using System.Linq;
9-
using System.Data.Linq;
108
using System.Collections.Generic;
119
using System.Diagnostics;
10+
using System.Linq;
1211
using DotNetOAuth.ChannelElements;
13-
using DotNetOAuth.Messaging;
1412

1513
public class DatabaseTokenManager : ITokenManager {
1614
#region ITokenManager Members

samples/ServiceProvider/App_Code/Global.cs

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
using System;
2-
using System.Collections.Generic;
32
using System.Linq;
4-
using System.Web;
5-
using System.Text;
63
using System.ServiceModel;
4+
using System.Text;
5+
using System.Web;
76
using DotNetOAuth.Messages;
87

98
/// <summary>
10-
/// Summary description for Global
9+
/// The web application global events and properties.
1110
/// </summary>
1211
public class Global : HttpApplication {
1312
/// <summary>
@@ -20,32 +19,6 @@ public class Global : HttpApplication {
2019
/// </summary>
2120
public static log4net.ILog Logger = log4net.LogManager.GetLogger("DotNetOAuth.ConsumerSample");
2221

23-
private static DataClassesDataContext dataContextSimple {
24-
get {
25-
if (HttpContext.Current != null) {
26-
return HttpContext.Current.Items["DataContext"] as DataClassesDataContext;
27-
} else if (OperationContext.Current != null) {
28-
object data;
29-
if (OperationContext.Current.IncomingMessageProperties.TryGetValue("DataContext", out data)) {
30-
return data as DataClassesDataContext;
31-
} else {
32-
return null;
33-
}
34-
} else {
35-
throw new InvalidOperationException();
36-
}
37-
}
38-
set {
39-
if (HttpContext.Current != null) {
40-
HttpContext.Current.Items["DataContext"] = value;
41-
} else if (OperationContext.Current != null) {
42-
OperationContext.Current.IncomingMessageProperties["DataContext"] = value;
43-
} else {
44-
throw new InvalidOperationException();
45-
}
46-
}
47-
}
48-
4922
/// <summary>
5023
/// Gets the transaction-protected database connection for the current request.
5124
/// </summary>
@@ -74,6 +47,38 @@ public static DirectUserToServiceProviderMessage PendingOAuthAuthorization {
7447
set { HttpContext.Current.Session["authrequest"] = value; }
7548
}
7649

50+
private static DataClassesDataContext dataContextSimple {
51+
get {
52+
if (HttpContext.Current != null) {
53+
return HttpContext.Current.Items["DataContext"] as DataClassesDataContext;
54+
} else if (OperationContext.Current != null) {
55+
object data;
56+
if (OperationContext.Current.IncomingMessageProperties.TryGetValue("DataContext", out data)) {
57+
return data as DataClassesDataContext;
58+
} else {
59+
return null;
60+
}
61+
} else {
62+
throw new InvalidOperationException();
63+
}
64+
}
65+
66+
set {
67+
if (HttpContext.Current != null) {
68+
HttpContext.Current.Items["DataContext"] = value;
69+
} else if (OperationContext.Current != null) {
70+
OperationContext.Current.IncomingMessageProperties["DataContext"] = value;
71+
} else {
72+
throw new InvalidOperationException();
73+
}
74+
}
75+
}
76+
77+
public static void AuthorizePendingRequestToken() {
78+
TokenManager.AuthorizeRequestToken(PendingOAuthAuthorization.RequestToken, LoggedInUser);
79+
PendingOAuthAuthorization = null;
80+
}
81+
7782
private static void CommitAndCloseDatabaseIfNecessary() {
7883
var dataContext = dataContextSimple;
7984
if (dataContext != null) {
@@ -93,6 +98,7 @@ private void Application_Start(object sender, EventArgs e) {
9398

9499
private void Application_End(object sender, EventArgs e) {
95100
Logger.Info("Sample shutting down...");
101+
96102
// this would be automatic, but in partial trust scenarios it is not.
97103
log4net.LogManager.Shutdown();
98104
}
@@ -104,9 +110,4 @@ private void Application_Error(object sender, EventArgs e) {
104110
private void Application_EndRequest(object sender, EventArgs e) {
105111
CommitAndCloseDatabaseIfNecessary();
106112
}
107-
108-
public static void AuthorizePendingRequestToken() {
109-
TokenManager.AuthorizeRequestToken(PendingOAuthAuthorization.RequestToken, LoggedInUser);
110-
PendingOAuthAuthorization = null;
111-
}
112113
}

samples/ServiceProvider/App_Code/OAuthAuthorizationManager.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ protected override bool CheckAccessCore(OperationContext operationContext) {
2222
var auth = sp.GetProtectedResourceAuthorization(httpDetails, requestUri);
2323
if (auth != null) {
2424
var accessToken = Global.DataContext.OAuthTokens.Single(token => token.Token == auth.AccessToken);
25+
2526
// Only allow this method call if the access token scope permits it.
2627
string[] scopes = accessToken.Scope.Split('|');
2728
if (scopes.Contains(operationContext.IncomingMessageHeaders.Action)) {

samples/ServiceProvider/App_Code/TokenAuthorizationState.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,18 @@
77
/// Various states an OAuth token can be in.
88
/// </summary>
99
public enum TokenAuthorizationState : int {
10+
/// <summary>
11+
/// An unauthorized request token.
12+
/// </summary>
1013
UnauthorizedRequestToken = 0,
14+
15+
/// <summary>
16+
/// An authorized request token.
17+
/// </summary>
1118
AuthorizedRequestToken = 1,
19+
20+
/// <summary>
21+
/// An authorized access token.
22+
/// </summary>
1223
AccessToken = 2,
1324
}

samples/ServiceProvider/Members/Authorize.aspx.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ protected void allowAccessButton_Click(object sender, EventArgs e) {
3232
response.Send();
3333
}
3434
}
35+
3536
protected void denyAccessButton_Click(object sender, EventArgs e) {
3637
// erase the request token.
3738
multiView.ActiveViewIndex = 2;

0 commit comments

Comments
 (0)