Ewl » Canonical The canonical version of EWL Read More
Clone URL:  
Pushed to 2 repositories · View In Graph Contained in tip and canonical

Created EwfSafeRequestHandler to support a data-modification method and take
another step toward the web-service framework goal.

Changeset 81c7cfc8c280

Parent 2c41d463859b

by Profile picture of William GrossWilliam Gross

Changes to 10 files · Browse files at 81c7cfc8c280 Showing diff from parent 2c41d463859b Diff from another changeset...

Change 1 of 2 Show Entire File Core/​Core.csproj Stacked
 
377
378
379
380
381
382
383
 
593
594
595
 
 
 
596
597
598
599
600
 
377
378
379
 
380
381
382
 
592
593
594
595
596
597
598
 
599
600
601
@@ -377,7 +377,6 @@
  <Compile Include="EnterpriseWebFramework\Error Display\Styles\ListErrorDisplayStyle.cs" />   <Compile Include="EnterpriseWebFramework\Error Display\Styles\SectionErrorDisplayStyle.cs" />   <Compile Include="EnterpriseWebFramework\EwfInitializationOps.cs" /> - <Compile Include="EnterpriseWebFramework\EwfSafeResponseWriter.cs" />   <Compile Include="EnterpriseWebFramework\FontAwesomeIcon.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Check Boxes\BlockCheckBoxSetup.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Date and Time\DateAndTimeControl.cs" /> @@ -593,8 +592,10 @@
  <Compile Include="EnterpriseWebFramework\Page Infrastructure\SecondaryPostBackOperation.cs" />   <Compile Include="EnterpriseWebFramework\PaymentProcessing\PaymentProcessingStatics.cs" />   <Compile Include="EnterpriseWebFramework\PaymentProcessing\StatusMessageAndDestination.cs" /> + <Compile Include="EnterpriseWebFramework\Request Handling\EwfSafeRequestHandler.cs" /> + <Compile Include="EnterpriseWebFramework\Request Handling\EwfSafeResponseWriter.cs" /> + <Compile Include="EnterpriseWebFramework\Request Handling\StaticFileHandler.cs" />   <Compile Include="EnterpriseWebFramework\RevisionDisplayStatics.cs" /> - <Compile Include="EnterpriseWebFramework\StaticFileHandler.cs" />   <Compile Include="EnterpriseWebFramework\Text\EmphasizedContent.cs" />   <Compile Include="EnterpriseWebFramework\Text\ImportantContent.cs" />   <Compile Include="EnterpriseWebFramework\Text\LineBreak.cs" />
 
74
75
76
 
77
78
79
 
74
75
76
77
78
79
80
@@ -74,6 +74,7 @@
  <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cpage_0020infrastructure_005Cpage_0020structure_005Cnodes/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cpage_0020infrastructure_005Cpartial_0020updating/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=EnterpriseWebFramework_005CPaymentProcessing/@EntryIndexedValue">True</s:Boolean> + <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Crequest_0020handling/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=EnterpriseWebFramework_005CResource_0020Meta_0020Logic/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=EnterpriseWebFramework_005CResource_0020Meta_0020Logic_005CAlternative_0020Resource_0020Modes/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Ctext/@EntryIndexedValue">True</s:Boolean>
 
3
4
5
6
7
8
9
10
11
12
 
 
 
13
14
15
 
3
4
5
 
 
 
 
 
 
 
6
7
8
9
10
11
@@ -3,13 +3,9 @@
   namespace EnterpriseWebLibrary.EnterpriseWebFramework {   public abstract class AutoCompleteService: EwfPage { - protected override EwfSafeResponseWriter responseWriter { - get { - return - new EwfSafeResponseWriter( - EwfResponse.Create( ContentTypes.PlainText, new EwfResponseBodyCreator( () => new JavaScriptSerializer().Serialize( getItems() ) ) ) ); - } - } + protected override EwfSafeRequestHandler requestHandler => + new EwfSafeResponseWriter( + EwfResponse.Create( ContentTypes.PlainText, new EwfResponseBodyCreator( () => new JavaScriptSerializer().Serialize( getItems() ) ) ) );     protected abstract IEnumerable<AutoCompleteItem> getItems();   }
 
191
192
193
194
 
195
196
197
 
198
199
200
 
208
209
210
211
 
212
213
 
214
215
216
 
191
192
193
 
194
195
196
 
197
198
199
200
 
208
209
210
 
211
212
 
213
214
215
216
@@ -191,10 +191,10 @@
  if( disabledMode != null )   throw new PageDisabledException( disabledMode.Message );   - if( responseWriter != null ) { + if( requestHandler != null ) {   Response.ClearHeaders();   Response.ClearContent(); - responseWriter.WriteResponse(); + requestHandler.WriteResponse();     // Calling Response.End() is not a good practice; see http://stackoverflow.com/q/1087777/35349. We should be able to remove this call when we separate   // EWF from Web Forms. This is EnduraCode goal 790. @@ -208,9 +208,9 @@
  protected abstract void initEntitySetup();     /// <summary> - /// Gets the response writer for this page. NOTE: We should re-implement this such that the classes that override this are plain old HTTP handlers instead of pages. + /// Gets the request handler for this page, which will override the page.   /// </summary> - protected virtual EwfSafeResponseWriter responseWriter { get { return null; } } + protected virtual EwfSafeRequestHandler requestHandler => null;     /// <summary>   /// Performs EWF activities in addition to the normal InitComplete activities.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
 
@@ -0,0 +1,37 @@
+using System; +using EnterpriseWebLibrary.DataAccess; + +namespace EnterpriseWebLibrary.EnterpriseWebFramework { + /// <summary> + /// An object that handles a safe HTTP request (e.g. GET, HEAD). + /// </summary> + public sealed class EwfSafeRequestHandler { + public static implicit operator EwfSafeRequestHandler( EwfSafeResponseWriter responseWriter ) { + return new EwfSafeRequestHandler( responseWriter ); + } + + private readonly EwfSafeResponseWriter responseWriter; + + /// <summary> + /// Creates a request handler from the result of the specified data-modification method. If you do not need to modify data, do not call this constructor; + /// use <see cref="EwfSafeResponseWriter"/>, which can be implicitly converted to a request handler. + /// </summary> + public EwfSafeRequestHandler( Func<EwfSafeResponseWriter> dataModificationMethod ) { + DataAccessState.Current.DisableCache(); + try { + responseWriter = dataModificationMethod(); + } + finally { + DataAccessState.Current.ResetCache(); + } + } + + private EwfSafeRequestHandler( EwfSafeResponseWriter responseWriter ) { + this.responseWriter = responseWriter; + } + + internal void WriteResponse() { + responseWriter.WriteResponse(); + } + } +} \ No newline at end of file
Show Entire File Core/​EnterpriseWebFramework/​Request Handling/​EwfSafeResponseWriter.cs Stacked
renamed from Core/EnterpriseWebFramework/EwfSafeResponseWriter.cs
(No changes)
Show Entire File Core/​EnterpriseWebFramework/​Request Handling/​StaticFileHandler.cs Stacked
renamed from Core/EnterpriseWebFramework/StaticFileHandler.cs
(No changes)
 
9
10
11
12
 
13
14
15
16
17
 
 
18
19
 
 
9
10
11
 
12
13
14
 
 
 
15
16
17
18
 
@@ -9,11 +9,10 @@
  throw new ApplicationException();   }   - protected override ConnectionSecurity ConnectionSecurity { get { return ConnectionSecurity.MatchingCurrentRequest; } } + protected override ConnectionSecurity ConnectionSecurity => ConnectionSecurity.MatchingCurrentRequest;   }   - protected override EwfSafeResponseWriter responseWriter { - get { return new EwfSafeResponseWriter( new EwfResponse( StandardLibrarySessionState.Instance.ResponseToSend ) ); } - } + protected override EwfSafeRequestHandler requestHandler => + new EwfSafeResponseWriter( new EwfResponse( StandardLibrarySessionState.Instance.ResponseToSend ) );   }  } \ No newline at end of file
 
16
17
18
19
 
20
21
22
23
24
25
26
27
28
29
 
 
 
 
 
30
31
 
 
16
17
18
 
19
20
21
 
 
 
 
 
 
 
 
22
23
24
25
26
27
28
 
@@ -16,16 +16,13 @@
  throw new ApplicationException( "File does not exist." );   }   - protected override ConnectionSecurity ConnectionSecurity { get { return ConnectionSecurity.NonSecure; } } + protected override ConnectionSecurity ConnectionSecurity => ConnectionSecurity.NonSecure;   }   - protected override EwfSafeResponseWriter responseWriter { - get { - return new EwfSafeResponseWriter( - () => EwfResponse.Create( ContentTypes.Xml, new EwfResponseBodyCreator( () => File.ReadAllText( info.FilePath ) ) ), - EwlStatics.EwlBuildDateTime, - () => "getSchema" + info.FileName ); - } - } + protected override EwfSafeRequestHandler requestHandler => + new EwfSafeResponseWriter( + () => EwfResponse.Create( ContentTypes.Xml, new EwfResponseBodyCreator( () => File.ReadAllText( info.FilePath ) ) ), + EwlStatics.EwlBuildDateTime, + () => "getSchema" + info.FileName );   }  } \ No newline at end of file
 
1
2
3
4
5
6
7
8
 
9
10
 
 
 
1
2
3
4
5
6
 
7
8
9
 
@@ -1,10 +1,9 @@
-using EnterpriseWebLibrary;  using EnterpriseWebLibrary.EnterpriseWebFramework;    // Parameter: string text    namespace EnterpriseWebLibrary.WebSite.TestPages {   partial class GetImage: EwfPage { - protected override EwfSafeResponseWriter responseWriter { get { return new EwfSafeResponseWriter( NetTools.CreateImageFromText( info.Text, null ) ); } } + protected override EwfSafeRequestHandler requestHandler => new EwfSafeResponseWriter( NetTools.CreateImageFromText( info.Text, null ) );   }  } \ No newline at end of file