11using System ;
2- using System . Collections . Generic ;
32using System . Linq ;
4- using System . Web ;
5- using System . Text ;
63using System . ServiceModel ;
4+ using System . Text ;
5+ using System . Web ;
76using DotNetOAuth . Messages ;
87
98/// <summary>
10- /// Summary description for Global
9+ /// The web application global events and properties.
1110/// </summary>
1211public 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}
0 commit comments