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

Reimplemented FileUpload form control to fit new component model.

Changeset c9909248b98d

Parent 493468370a73

by Profile picture of William GrossWilliam Gross

Changes to 14 files · Browse files at c9909248b98d Showing diff from parent 493468370a73 Diff from another changeset...

Change 1 of 5 Show Entire File Core/​Core.csproj Stacked
 
218
219
220
 
 
 
221
222
223
 
310
311
312
 
 
 
 
 
313
314
315
 
392
393
394
395
396
397
 
398
399
400
 
479
480
481
482
483
484
485
486
487
488
489
490
491
 
817
818
819
 
820
821
822
 
218
219
220
221
222
223
224
225
226
 
313
314
315
316
317
318
319
320
321
322
323
 
400
401
402
 
403
404
405
406
407
408
 
487
488
489
 
 
 
 
 
 
 
490
491
492
 
818
819
820
821
822
823
824
@@ -218,6 +218,9 @@
  <Compile Include="Configuration\WebApplication.cs" />   <Compile Include="Cultures.cs" />   <Compile Include="DataAccess\AutomaticTransactionDisablingProvider.cs" /> + <Compile Include="DataAccess\BlobStorage\BlobFile.cs" /> + <Compile Include="DataAccess\BlobStorage\BlobStorageStatics.cs" /> + <Compile Include="DataAccess\BlobStorage\SystemBlobStorageProvider.cs" />   <Compile Include="DataAccess\CommandWriting\Commands\InlineSelect.cs" />   <Compile Include="DataAccess\CommandWriting\InlineConditionAbstraction\Conditions\InequalityCondition.cs" />   <Compile Include="DataAccess\CommandWriting\InlineConditionAbstraction\Conditions\LikeCondition.cs" /> @@ -310,6 +313,11 @@
  <Compile Include="EnterpriseWebFramework\Action Controls\ToolTipButton.cs" />   <Compile Include="EnterpriseWebFramework\AutoLayout\FormItemLabel.cs" />   <Compile Include="EnterpriseWebFramework\AutoLayout\FormItemSetup.cs" /> + <Compile Include="EnterpriseWebFramework\BLOB Management\BlobFileCollectionManager.cs" /> + <Compile Include="EnterpriseWebFramework\BLOB Management\BlobFileManager.cs" /> + <Compile Include="EnterpriseWebFramework\BLOB Management\BlobManagementStatics.cs" /> + <Compile Include="EnterpriseWebFramework\BLOB Management\MarkFileAsReadMethod.cs" /> + <Compile Include="EnterpriseWebFramework\BLOB Management\NewFileNotificationMethod.cs" />   <Compile Include="EnterpriseWebFramework\Charting\Chart.cs" />   <Compile Include="EnterpriseWebFramework\Charting\ChartSetup.cs" />   <Compile Include="EnterpriseWebFramework\Charting\ChartType.cs" /> @@ -392,9 +400,9 @@
  <Compile Include="EnterpriseWebFramework\Form Controls\Date and Time\DurationControlSetup.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Email Address Control\EmailAddressControl.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Email Address Control\EmailAddressControlSetup.cs" /> - <Compile Include="EnterpriseWebFramework\Form Controls\EwfFileUpload.cs" />   <Compile Include="EnterpriseWebFramework\Controls\Strong.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\EwfHiddenField.cs" /> + <Compile Include="EnterpriseWebFramework\Form Controls\FileUpload.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\FormControl.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\FormControlExtensionCreators.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\FormControlLabeler.cs" /> @@ -479,13 +487,6 @@
  <Compile Include="EnterpriseWebFramework\NamingPlaceholder.cs" />   <Compile Include="ContentTypes.cs" />   <Compile Include="EnterpriseWebFramework\Controls\ActionControl.cs" /> - <Compile Include="EnterpriseWebFramework\Controls\BlobFileManagers\BlobFile.cs" /> - <Compile Include="EnterpriseWebFramework\Controls\BlobFileManagers\BlobFileCollectionManager.cs" /> - <Compile Include="EnterpriseWebFramework\Controls\BlobFileManagers\SystemBlobFileManagementProvider.cs" /> - <Compile Include="EnterpriseWebFramework\Controls\BlobFileManagers\BlobFileManager.cs" /> - <Compile Include="EnterpriseWebFramework\Controls\BlobFileManagers\BlobFileOps.cs" /> - <Compile Include="EnterpriseWebFramework\Controls\BlobFileManagers\MarkFileAsReadMethod.cs" /> - <Compile Include="EnterpriseWebFramework\Controls\BlobFileManagers\NewFileNotificationMethod.cs" />   <Compile Include="EnterpriseWebFramework\Controls\Block.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Check Boxes\BlockCheckBox.cs" />   <Compile Include="EnterpriseWebFramework\Form Controls\Check Boxes\CommonCheckBox.cs" /> @@ -817,6 +818,7 @@
  <ItemGroup>   <Content Include="WebTestingFramework\Read me.txt" />   </ItemGroup> + <ItemGroup />   <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />   <!-- To modify your build process, add your task inside one of the targets below and uncomment it.   Other similar extension points exist, see Microsoft.Common.targets.
 
7
8
9
 
10
11
12
 
7
8
9
10
11
12
13
@@ -7,6 +7,7 @@
  <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Caction_0020components_005Chyperlink_005Cstyles/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Caction_0020controls/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=EnterpriseWebFramework_005CAutoLayout/@EntryIndexedValue">True</s:Boolean> + <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Cblob_0020management/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=EnterpriseWebFramework_005CCharting/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=enterprisewebframework_005Ccomponent_0020display/@EntryIndexedValue">True</s:Boolean>   <s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=EnterpriseWebFramework_005CControls_005CActionControls/@EntryIndexedValue">True</s:Boolean>
Change 1 of 1 Show Entire File Core/​DataAccess/​BlobStorage/​BlobFile.cs Stacked
renamed from Core/EnterpriseWebFramework/Controls/BlobFileManagers/BlobFile.cs
 
1
2
3
 
4
5
6
 
1
2
 
3
4
5
6
@@ -1,6 +1,6 @@
 using System;   -namespace EnterpriseWebLibrary.EnterpriseWebFramework.Controls { +namespace EnterpriseWebLibrary.DataAccess.BlobStorage {   /// <summary>   /// Contains basic attributes of a file stored in a database, including the ID and the name.   /// </summary>
Change 1 of 2 Show Entire File Core/​DataAccess/​BlobStorage/​BlobStorageStatics.cs Stacked
renamed from Core/EnterpriseWebFramework/Controls/BlobFileManagers/BlobFileOps.cs
 
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
 
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
 
 
1
2
3
 
 
4
5
 
6
7
 
 
 
 
 
8
9
10
 
11
12
13
 
14
15
16
 
17
18
19
20
 
40
41
42
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
44
45
@@ -1,27 +1,20 @@
-using System;  using System.Collections.Generic;  using System.IO;  using System.Linq; -using System.Web.UI; -using System.Web.UI.WebControls;  using Aspose.Pdf.Facades;  using EnterpriseWebLibrary.Configuration; -using EnterpriseWebLibrary.InputValidation;  using EnterpriseWebLibrary.IO;   -namespace EnterpriseWebLibrary.EnterpriseWebFramework.Controls { - /// <summary> - /// Contains methods for working with BLOB files. - /// </summary> - public static class BlobFileOps { +namespace EnterpriseWebLibrary.DataAccess.BlobStorage { + public static class BlobStorageStatics {   private const string providerName = "BlobFileManagement"; - private static SystemBlobFileManagementProvider provider; + private static SystemBlobStorageProvider provider;     internal static void Init() { - provider = ConfigurationStatics.GetSystemLibraryProvider( providerName ) as SystemBlobFileManagementProvider; + provider = ConfigurationStatics.GetSystemLibraryProvider( providerName ) as SystemBlobStorageProvider;   }   - internal static SystemBlobFileManagementProvider SystemProvider { + internal static SystemBlobStorageProvider SystemProvider {   get {   if( provider == null )   throw ConfigurationStatics.CreateProviderNotFoundException( providerName ); @@ -47,109 +40,6 @@
  }     /// <summary> - /// Uploaded file cannot be null. But if uploadedFile.HasFile is false, this will be a no-op. - /// Pass null for acceptableFileExtensions if there is no restriction on file extension. - /// PerformAdditionalImageValidation cannot be null but may be an empty delegate. - /// </summary> - public static void ValidateUploadedFile( - Validator validator, EwfFileUpload uploadedFile, string[] acceptableFileExtensions, Action<Validator, System.Drawing.Image> performAdditionalImageValidation, - bool mustBeRenderableImage ) { - var file = uploadedFile.GetPostBackValue( AppRequestState.Instance.EwfPageRequestState.PostBackValues ); - if( file == null ) - return; - - // Perform generic file validation. - if( acceptableFileExtensions != null && !FileExtensions.MatchesAGivenExtension( file.FileName, acceptableFileExtensions ) ) { - validator.NoteErrorAndAddMessage( Translation.UnacceptableFileExtension + " " + acceptableFileExtensions.GetCommaDelimitedStringFromCollection() ); - // Don't bother trying to see if it's an image and parse the image. The file extension message be more detailed than the messages those errors produce. - return; - } - - // Perform image-specific validation if necessary. - if( mustBeRenderableImage ) - // Make sure it is an image according to its content type. - if( !ContentTypes.IsImageType( GetContentTypeForPostedFile( file ) ) ) - validator.NoteErrorAndAddMessage( "Please upload a valid image file." ); - else - // Make sure it is an image type that we understand. Also perform optional custom validation. - try { - using( var stream = new MemoryStream( file.Contents ) ) { - var image = System.Drawing.Image.FromStream( stream ); - performAdditionalImageValidation( validator, image ); - } - } - catch( ArgumentException ) { - // If we end up in this catch block, it means that System.Drawing.Image does not understand our image. Since we already know that our content type - // is image at this point, this usually means that the file is some sort of unsupported image format, like NEF. - validator.NoteErrorAndAddMessage( "The uploaded image file is in an unsupported format." ); - } - } - - /// <summary> - /// Provides a height/width image validation method without you having to create a custom validation method. - /// </summary> - public static Action<Validator, System.Drawing.Image> GetWidthAndHeightImageValidationMethod( string subject, int width, int height ) { - return ( validator2, image ) => { - if( image.Height != height || image.Width != width ) - validator2.NoteErrorAndAddMessage( subject + " must be " + width + "x" + height + " pixels." ); - }; - } - - /// <summary> - /// Returns null if the file is null, the file is not an image, or there is no thumbnail resource info creator. - /// </summary> - internal static IEnumerable<Control> GetThumbnailControl( BlobFile file, Func<decimal, ResourceInfo> thumbnailResourceInfoCreator ) { - // NOTE: We'd like to check here whether the file is a renderable image or not. But we can't because we don't have the file contents. - // So, we'll have to make sure that all ThumbnailPageInfoCreators provide a page that knows how to handle NEF files (ideally we'd want - // it to behave as if there was no thumbnail at all if there is an unrenderable image file). - // The only alternative to this that I can think of is creating a new file table field called "IsRenderable" that we store when - // we first save the image. - if( file == null || !ContentTypes.IsImageType( file.ContentType ) || thumbnailResourceInfoCreator == null ) - return Enumerable.Empty<Control>(); - return new EwfImage( new ImageSetup( null, sizesToAvailableWidth: true ), thumbnailResourceInfoCreator( file.FileId ) ).ToCollection().GetControls(); - } - - // NOTE: Use this from blob file manager, etc. - /// <summary> - /// Returns a link to download a file with the given file collection ID. - /// If no file is associated with the given file collection ID, returns a literal control with textIfNoFile text. - /// The file name is used as the label unless labelOverride is specified. - /// SystemBlobFileManagementProvider must be implemented. - /// </summary> - public static Control GetFileLink( int fileCollectionId, string labelOverride = null, string textIfNoFile = "" ) { - var file = GetFirstFileFromCollection( fileCollectionId ); - if( file == null ) - return new PlaceHolder().AddControlsReturnThis( textIfNoFile.ToComponents().GetControls() ); - return new PostBackButton( - new TextActionControlStyle( labelOverride ?? file.FileName ), - usesSubmitBehavior: false, - postBack: PostBack.CreateFull( - id: PostBack.GetCompositeId( "ewfFile", file.FileId.ToString() ), - actionGetter: () => new PostBackAction( - new PageReloadBehavior( - secondaryResponse: new SecondaryResponse( new BlobFileResponse( GetFirstFileFromCollection( fileCollectionId ).FileId, () => true ), false ) ) ) ) ); - } - - /// <summary> - /// Returns a link to download a file with the given file ID. - /// If no file is associated with the given file collection ID, returns a literal control with textIfNoFile text. - /// The file name is used as the label unless labelOverride is specified. - /// SystemBlobFileManagementProvider must be implemented. - /// </summary> - public static Control GetFileLinkFromFileId( int fileId, string labelOverride = null, string textIfNoFile = "" ) { - var file = SystemProvider.GetFile( fileId ); - if( file == null ) - return new PlaceHolder().AddControlsReturnThis( textIfNoFile.ToComponents().GetControls() ); - return new PostBackButton( - new TextActionControlStyle( labelOverride ?? file.FileName ), - usesSubmitBehavior: false, - postBack: PostBack.CreateFull( - id: PostBack.GetCompositeId( "ewfFile", file.FileId.ToString() ), - actionGetter: () => - new PostBackAction( new PageReloadBehavior( secondaryResponse: new SecondaryResponse( new BlobFileResponse( fileId, () => true ), false ) ) ) ) ); - } - - /// <summary>   /// SystemBlobFileManagementProvider must be implemented.   /// You should check other meta information about the file (such as the extension) before calling this expensive method.   /// </summary>
Change 1 of 1 Show Entire File Core/​DataAccess/​BlobStorage/​SystemBlobStorageProvider.cs Stacked
renamed from Core/EnterpriseWebFramework/Controls/BlobFileManagers/SystemBlobFileManagementProvider.cs
 
1
2
3
 
4
5
 
6
7
 
8
9
10
 
1
2
 
3
4
 
5
6
 
7
8
9
10
@@ -1,10 +1,10 @@
 using System.Collections.Generic;   -namespace EnterpriseWebLibrary.EnterpriseWebFramework.Controls { +namespace EnterpriseWebLibrary.DataAccess.BlobStorage {   /// <summary> - /// Defines how file management operations will be carried out against a database. + /// System-specific BLOB-storage logic.   /// </summary> - public interface SystemBlobFileManagementProvider { + public interface SystemBlobStorageProvider {   /// <summary>   /// Retrieves the file with the specified ID.   /// </summary>
Change 1 of 7 Show Entire File Core/​EnterpriseWebFramework/​BLOB Management/​BlobFileCollectionManager.cs Stacked
renamed from Core/EnterpriseWebFramework/Controls/BlobFileManagers/BlobFileCollectionManager.cs
 
5
6
7
 
 
8
9
10
11
12
 
13
14
15
 
109
110
111
112
 
113
114
115
 
141
142
143
144
 
145
146
147
 
157
158
159
160
161
 
 
162
163
164
 
177
178
179
180
 
181
182
183
 
195
196
197
198
 
 
 
 
 
199
200
201
202
 
 
 
 
 
203
204
205
 
207
208
209
210
211
212
213
214
215
216
217
 
 
 
 
 
218
219
220
 
5
6
7
8
9
10
11
12
13
 
14
15
16
17
 
111
112
113
 
114
115
116
117
 
143
144
145
 
146
147
148
149
 
159
160
161
 
 
162
163
164
165
166
 
179
180
181
 
182
183
184
185
 
197
198
199
 
200
201
202
203
204
205
206
207
 
208
209
210
211
212
213
214
215
 
217
218
219
 
 
 
 
 
 
 
 
220
221
222
223
224
225
226
227
@@ -5,11 +5,13 @@
 using System.Web.UI;  using System.Web.UI.HtmlControls;  using System.Web.UI.WebControls; +using EnterpriseWebLibrary.DataAccess.BlobStorage; +using EnterpriseWebLibrary.EnterpriseWebFramework.Controls;  using EnterpriseWebLibrary.InputValidation;  using EnterpriseWebLibrary.IO;  using EnterpriseWebLibrary.WebSessionState;   -namespace EnterpriseWebLibrary.EnterpriseWebFramework.Controls { +namespace EnterpriseWebLibrary.EnterpriseWebFramework {   /// <summary>   /// A control for managing a collection of files stored in a database.   /// </summary> @@ -109,7 +111,7 @@
    var table = new DynamicTable( columnSetups.ToArray() ) { Caption = Caption };   - files = BlobFileOps.SystemProvider.GetFilesLinkedToFileCollection( fileCollectionId ); + files = BlobStorageStatics.SystemProvider.GetFilesLinkedToFileCollection( fileCollectionId );   files = ( sortByName ? files.OrderByName() : files.OrderByUploadedDateDescending() ).ToArray();     var deleteModMethods = new List<Func<bool>>(); @@ -141,7 +143,7 @@
  private void addFileRow( DynamicTable table, BlobFile file, List<Func<bool>> deleteModMethods ) {   var cells = new List<EwfTableCell>();   - var thumbnailControl = BlobFileOps.GetThumbnailControl( file, ThumbnailResourceInfoCreator ).ToImmutableArray(); + var thumbnailControl = BlobManagementStatics.GetThumbnailControl( file, ThumbnailResourceInfoCreator ).ToImmutableArray();   if( thumbnailControl.Any() )   cells.Add( thumbnailControl.ToCell() );   @@ -157,8 +159,8 @@
  if( fileIsUnread )   markFileAsReadMethod?.Invoke( file.FileId );   }, - actionGetter: () => - new PostBackAction( new PageReloadBehavior( secondaryResponse: new SecondaryResponse( new BlobFileResponse( file.FileId, () => true ), false ) ) ) ) ) + actionGetter: () => new PostBackAction( + new PageReloadBehavior( secondaryResponse: new SecondaryResponse( new BlobFileResponse( file.FileId, () => true ), false ) ) ) ) )   {   ToolTip = file.FileName   } ); @@ -177,7 +179,7 @@
  () => {   if( !delete )   return false; - BlobFileOps.SystemProvider.DeleteFile( file.FileId ); + BlobStorageStatics.SystemProvider.DeleteFile( file.FileId );   return true;   } );   @@ -195,11 +197,19 @@
  var existingFile = files.SingleOrDefault( i => i.FileName == file.FileName );   int newFileId;   if( existingFile != null ) { - BlobFileOps.SystemProvider.UpdateFile( existingFile.FileId, file.FileName, file.Contents, BlobFileOps.GetContentTypeForPostedFile( file ) ); + BlobStorageStatics.SystemProvider.UpdateFile( + existingFile.FileId, + file.FileName, + file.Contents, + BlobStorageStatics.GetContentTypeForPostedFile( file ) );   newFileId = existingFile.FileId;   }   else - newFileId = BlobFileOps.SystemProvider.InsertFile( fileCollectionId, file.FileName, file.Contents, BlobFileOps.GetContentTypeForPostedFile( file ) ); + newFileId = BlobStorageStatics.SystemProvider.InsertFile( + fileCollectionId, + file.FileName, + file.Contents, + BlobStorageStatics.GetContentTypeForPostedFile( file ) );     NewFileNotificationMethod?.Invoke( newFileId );   EwfPage.AddStatusMessage( StatusMessageType.Info, "File uploaded successfully." ); @@ -207,14 +217,11 @@
  return FormState.ExecuteWithDataModificationsAndDefaultAction(   dm.ToCollection(),   () => { - var fi = FormItem.Create( - "", - new EwfFileUpload(), - validationGetter: control => new EwfValidation( - ( pbv, validator ) => { - BlobFileOps.ValidateUploadedFile( validator, control, acceptableFileExtensions, ValidateImage, AcceptOnlyImages ); - file = control.GetPostBackValue( pbv ); - } ) ); + var fi = new FileUpload( + validationMethod: ( postBackValue, validator ) => { + BlobManagementStatics.ValidateUploadedFile( validator, postBackValue, acceptableFileExtensions, ValidateImage, AcceptOnlyImages ); + file = postBackValue; + } ).ToFormItem();     return ControlList.CreateWithControls(   true,
Change 1 of 4 Show Entire File Core/​EnterpriseWebFramework/​BLOB Management/​BlobFileManager.cs Stacked
renamed from Core/EnterpriseWebFramework/Controls/BlobFileManagers/BlobFileManager.cs
 
1
2
3
 
 
4
 
5
6
 
7
8
9
10
11
12
13
14
 
15
16
17
 
23
24
25
26
27
28
29
30
31
32
33
 
34
35
36
37
 
38
39
40
 
48
49
50
51
 
52
53
54
 
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
110
111
112
113
114
115
116
117
118
119
 
120
121
122
123
124
 
 
 
 
 
 
 
125
126
127
 
1
2
3
4
5
6
7
8
 
9
10
11
12
13
14
 
 
 
15
16
17
18
 
24
25
26
 
 
 
 
 
 
 
 
27
28
29
 
 
30
31
32
33
 
41
42
43
 
44
45
46
47
 
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
@@ -1,17 +1,18 @@
 using System;  using System.Web.UI;  using System.Web.UI.WebControls; +using EnterpriseWebLibrary.DataAccess.BlobStorage; +using EnterpriseWebLibrary.EnterpriseWebFramework.Controls;  using EnterpriseWebLibrary.InputValidation; +using EnterpriseWebLibrary.IO;   -namespace EnterpriseWebLibrary.EnterpriseWebFramework.Controls { +namespace EnterpriseWebLibrary.EnterpriseWebFramework {   /// <summary>   /// A control for managing a single file stored in a database.   /// </summary>   public sealed class BlobFileManager: WebControl, INamingContainer {   private int? fileCollectionId; - private readonly BlobFile file; - private readonly EwfFileUpload uploadedFile; - private string[] acceptableFileExtensions; + private RsFile uploadedFile;     /// <summary>   /// Default is false. Set to true if you do not want the manager to show "No existing file" when there is no file in the database. @@ -23,18 +24,10 @@
  /// </summary>   public Func<decimal, ResourceInfo> ThumbnailResourceInfoCreator { private get; set; }   - /// <summary> - /// Prevents the user from uploading a file of a type other than those provided. File type constants found in EnterpriseWebLibrary.FileExtensions. - /// </summary> - public void SetFileTypeFilter( params string[] acceptableFileExtensions ) { - this.acceptableFileExtensions = acceptableFileExtensions; - } - - public BlobFileManager( int? fileCollectionId ) { + public BlobFileManager( int? fileCollectionId, bool requireUploadIfNoFile, Action<RsFile, Validator> validationMethod ) {   this.fileCollectionId = fileCollectionId;   - if( fileCollectionId != null ) - file = BlobFileOps.GetFirstFileFromCollection( fileCollectionId.Value ); + var file = fileCollectionId != null ? BlobStorageStatics.GetFirstFileFromCollection( fileCollectionId.Value ) : null;     var controlStack = ControlStack.Create( true );   if( file != null ) { @@ -48,7 +41,7 @@
  return new PostBackAction(   new PageReloadBehavior(   secondaryResponse: new SecondaryResponse( - new BlobFileResponse( BlobFileOps.GetFirstFileFromCollection( fileCollectionId.Value ).FileId, () => true ), + new BlobFileResponse( BlobStorageStatics.GetFirstFileFromCollection( fileCollectionId.Value ).FileId, () => true ),   false ) ) );   } ) );   controlStack.AddControls( download ); @@ -56,72 +49,53 @@
  else if( !HideNoExistingFileMessage )   controlStack.AddControls( new Label { Text = Translation.NoExistingFile } );   - uploadedFile = new EwfFileUpload(); - if( file != null ) { - uploadedFile.SetInitialDisplay( false ); - var replaceExistingFileLink = new ToggleButton( - uploadedFile.ToCollection(), - new TextActionControlStyle( Translation.ClickHereToReplaceExistingFile ), - false, - ( postBackValue, validator ) => {} ) { AlternateText = "" }; - controlStack.AddControls( replaceExistingFileLink ); - } + var fileUploadDisplayedPmv = new PageModificationValue<string>(); + controlStack.AddControls( + new FileUpload( + displaySetup: fileUploadDisplayedPmv.ToCondition( bool.TrueString.ToCollection() ).ToDisplaySetup(), + validationMethod: ( postBackValue, validator ) => { + if( requireUploadIfNoFile && file == null && postBackValue == null ) { + validator.NoteErrorAndAddMessage( Translation.PleaseUploadAFile ); + return; + }   - controlStack.AddControls( uploadedFile ); + uploadedFile = postBackValue; + validationMethod( postBackValue, validator ); + } ).ToFormItem() + .ToControl() ); + var fileUploadDisplayedHiddenFieldId = new HiddenFieldId(); + new EwfHiddenField( ( file == null ).ToString(), id: fileUploadDisplayedHiddenFieldId, pageModificationValue: fileUploadDisplayedPmv ).PageComponent + .ToCollection() + .AddEtherealControls( controlStack ); + if( file != null ) + controlStack.AddControls( + new PlaceHolder().AddControlsReturnThis( + new EwfButton( + new StandardButtonStyle( Translation.ClickHereToReplaceExistingFile, buttonSize: ButtonSize.ShrinkWrap ), + displaySetup: fileUploadDisplayedPmv.ToCondition( bool.FalseString.ToCollection() ).ToDisplaySetup(), + behavior: new ChangeValueBehavior( fileUploadDisplayedHiddenFieldId, bool.TrueString ) ).ToCollection() + .GetControls() ) );   - this.AddControlsReturnThis( BlobFileOps.GetThumbnailControl( file, ThumbnailResourceInfoCreator ) ); + this.AddControlsReturnThis( BlobManagementStatics.GetThumbnailControl( file, ThumbnailResourceInfoCreator ) );   Controls.Add( controlStack );   }     /// <summary> - /// Call this during ValidateFormValues. - /// </summary> - public void ValidateFormValues( Validator validator, string subject, bool requireUploadIfNoFile ) { - validateFormValues( validator, subject, requireUploadIfNoFile, delegate {}, false ); - } - - /// <summary> - /// Performs validate form values, but also forces the file to be an image. - /// </summary> - public void ValidateAsImage( Validator validator, string subject, bool requireUploadIfNoFile ) { - ValidateAsImage( validator, subject, requireUploadIfNoFile, delegate {} ); - } - - /// <summary> - /// Performs validate form values, but also forces the file to be an image of the specified dimensions. - /// </summary> - public void ValidateAsImage( Validator validator, string subject, bool requireUploadIfNoFile, int width, int height ) { - ValidateAsImage( validator, subject, requireUploadIfNoFile, BlobFileOps.GetWidthAndHeightImageValidationMethod( subject, width, height ) ); - } - - /// <summary> - /// Performs validate form values, but also forces the file to be an image and lets you impose additional restrictions (width, etc.) - /// using the validateImage method. - /// </summary> - public void ValidateAsImage( Validator validator, string subject, bool requireUploadIfNoFile, Action<Validator, System.Drawing.Image> validateImage ) { - validateFormValues( validator, subject, requireUploadIfNoFile, validateImage, true ); - } - - private void validateFormValues( - Validator validator, string subject, bool requireUploadIfNoFile, Action<Validator, System.Drawing.Image> validateImage, bool mustBeImage ) { - BlobFileOps.ValidateUploadedFile( validator, uploadedFile, acceptableFileExtensions, validateImage, mustBeImage ); - if( requireUploadIfNoFile && file == null && !uploadedFile.ValueChangedOnPostBack( AppRequestState.Instance.EwfPageRequestState.PostBackValues ) ) - validator.NoteErrorAndAddMessage( Translation.PleaseUploadAFile + " '" + subject + "'." ); - } - - /// <summary>   /// Call this during ModifyData. This returns the file collection ID of the existing or just-inserted file collection.   /// This will return an ID even if there are 0 files in the collection (in other words, no file). No file should always be   /// represented by a non-null file collection ID which happens to have 0 files in it. Null file collection IDs are not supported.   /// </summary>   public int ModifyData() {   if( fileCollectionId == null ) - fileCollectionId = BlobFileOps.SystemProvider.InsertFileCollection(); + fileCollectionId = BlobStorageStatics.SystemProvider.InsertFileCollection();   - var rsFile = uploadedFile.GetPostBackValue( AppRequestState.Instance.EwfPageRequestState.PostBackValues ); - if( rsFile != null ) { - BlobFileOps.SystemProvider.DeleteFilesLinkedToFileCollection( fileCollectionId.Value ); - BlobFileOps.SystemProvider.InsertFile( fileCollectionId.Value, rsFile.FileName, rsFile.Contents, BlobFileOps.GetContentTypeForPostedFile( rsFile ) ); + if( uploadedFile != null ) { + BlobStorageStatics.SystemProvider.DeleteFilesLinkedToFileCollection( fileCollectionId.Value ); + BlobStorageStatics.SystemProvider.InsertFile( + fileCollectionId.Value, + uploadedFile.FileName, + uploadedFile.Contents, + BlobStorageStatics.GetContentTypeForPostedFile( uploadedFile ) );   }   return fileCollectionId.Value;   }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
110
111
112
113
114
115
116
117
118
 
@@ -0,0 +1,118 @@
+using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Web.UI; +using System.Web.UI.WebControls; +using EnterpriseWebLibrary.DataAccess.BlobStorage; +using EnterpriseWebLibrary.EnterpriseWebFramework.Controls; +using EnterpriseWebLibrary.InputValidation; +using EnterpriseWebLibrary.IO; + +namespace EnterpriseWebLibrary.EnterpriseWebFramework { + public static class BlobManagementStatics { + /// <summary> + /// If file is null, this will be a no-op. + /// Pass null for acceptableFileExtensions if there is no restriction on file extension. + /// PerformAdditionalImageValidation cannot be null but may be an empty delegate. + /// </summary> + public static void ValidateUploadedFile( + Validator validator, RsFile file, string[] acceptableFileExtensions, Action<Validator, System.Drawing.Image> performAdditionalImageValidation, + bool mustBeRenderableImage ) { + if( file == null ) + return; + + // Perform generic file validation. + if( acceptableFileExtensions != null && !FileExtensions.MatchesAGivenExtension( file.FileName, acceptableFileExtensions ) ) { + validator.NoteErrorAndAddMessage( Translation.UnacceptableFileExtension + " " + acceptableFileExtensions.GetCommaDelimitedStringFromCollection() ); + // Don't bother trying to see if it's an image and parse the image. The file extension message be more detailed than the messages those errors produce. + return; + } + + // Perform image-specific validation if necessary. + if( mustBeRenderableImage ) + // Make sure it is an image according to its content type. + if( !ContentTypes.IsImageType( BlobStorageStatics.GetContentTypeForPostedFile( file ) ) ) + validator.NoteErrorAndAddMessage( "Please upload a valid image file." ); + else + // Make sure it is an image type that we understand. Also perform optional custom validation. + try { + using( var stream = new MemoryStream( file.Contents ) ) { + var image = System.Drawing.Image.FromStream( stream ); + performAdditionalImageValidation( validator, image ); + } + } + catch( ArgumentException ) { + // If we end up in this catch block, it means that System.Drawing.Image does not understand our image. Since we already know that our content type + // is image at this point, this usually means that the file is some sort of unsupported image format, like NEF. + validator.NoteErrorAndAddMessage( "The uploaded image file is in an unsupported format." ); + } + } + + /// <summary> + /// Provides a height/width image validation method without you having to create a custom validation method. + /// </summary> + public static Action<Validator, System.Drawing.Image> GetWidthAndHeightImageValidationMethod( int width, int height ) { + return ( validator2, image ) => { + if( image.Height != height || image.Width != width ) + validator2.NoteErrorAndAddMessage( "Image must be " + width + "x" + height + " pixels." ); + }; + } + + /// <summary> + /// Returns null if the file is null, the file is not an image, or there is no thumbnail resource info creator. + /// </summary> + internal static IEnumerable<Control> GetThumbnailControl( BlobFile file, Func<decimal, ResourceInfo> thumbnailResourceInfoCreator ) { + // NOTE: We'd like to check here whether the file is a renderable image or not. But we can't because we don't have the file contents. + // So, we'll have to make sure that all ThumbnailPageInfoCreators provide a page that knows how to handle NEF files (ideally we'd want + // it to behave as if there was no thumbnail at all if there is an unrenderable image file). + // The only alternative to this that I can think of is creating a new file table field called "IsRenderable" that we store when + // we first save the image. + if( file == null || !ContentTypes.IsImageType( file.ContentType ) || thumbnailResourceInfoCreator == null ) + return Enumerable.Empty<Control>(); + return new EwfImage( new ImageSetup( null, sizesToAvailableWidth: true ), thumbnailResourceInfoCreator( file.FileId ) ).ToCollection().GetControls(); + } + + // NOTE: Use this from blob file manager, etc. + /// <summary> + /// Returns a link to download a file with the given file collection ID. + /// If no file is associated with the given file collection ID, returns a literal control with textIfNoFile text. + /// The file name is used as the label unless labelOverride is specified. + /// SystemBlobFileManagementProvider must be implemented. + /// </summary> + public static Control GetFileLink( int fileCollectionId, string labelOverride = null, string textIfNoFile = "" ) { + var file = BlobStorageStatics.GetFirstFileFromCollection( fileCollectionId ); + if( file == null ) + return new PlaceHolder().AddControlsReturnThis( textIfNoFile.ToComponents().GetControls() ); + return new PostBackButton( + new TextActionControlStyle( labelOverride ?? file.FileName ), + usesSubmitBehavior: false, + postBack: PostBack.CreateFull( + id: PostBack.GetCompositeId( "ewfFile", file.FileId.ToString() ), + actionGetter: () => new PostBackAction( + new PageReloadBehavior( + secondaryResponse: new SecondaryResponse( + new BlobFileResponse( BlobStorageStatics.GetFirstFileFromCollection( fileCollectionId ).FileId, () => true ), + false ) ) ) ) ); + } + + /// <summary> + /// Returns a link to download a file with the given file ID. + /// If no file is associated with the given file collection ID, returns a literal control with textIfNoFile text. + /// The file name is used as the label unless labelOverride is specified. + /// SystemBlobFileManagementProvider must be implemented. + /// </summary> + public static Control GetFileLinkFromFileId( int fileId, string labelOverride = null, string textIfNoFile = "" ) { + var file = BlobStorageStatics.SystemProvider.GetFile( fileId ); + if( file == null ) + return new PlaceHolder().AddControlsReturnThis( textIfNoFile.ToComponents().GetControls() ); + return new PostBackButton( + new TextActionControlStyle( labelOverride ?? file.FileName ), + usesSubmitBehavior: false, + postBack: PostBack.CreateFull( + id: PostBack.GetCompositeId( "ewfFile", file.FileId.ToString() ), + actionGetter: () => + new PostBackAction( new PageReloadBehavior( secondaryResponse: new SecondaryResponse( new BlobFileResponse( fileId, () => true ), false ) ) ) ) ); + } + } +} \ No newline at end of file
Change 1 of 1 Show Entire File Core/​EnterpriseWebFramework/​BLOB Management/​MarkFileAsReadMethod.cs Stacked
renamed from Core/EnterpriseWebFramework/Controls/BlobFileManagers/MarkFileAsReadMethod.cs
 
1
 
2
3
4
 
 
1
2
3
4
@@ -1,4 +1,4 @@
-namespace EnterpriseWebLibrary.EnterpriseWebFramework.Controls { +namespace EnterpriseWebLibrary.EnterpriseWebFramework {   /// <summary>   /// Method that marks the file with the given ID as read.   /// </summary>
Change 1 of 1 Show Entire File Core/​EnterpriseWebFramework/​BLOB Management/​NewFileNotificationMethod.cs Stacked
renamed from Core/EnterpriseWebFramework/Controls/BlobFileManagers/NewFileNotificationMethod.cs
 
1
 
2
3
4
 
 
1
2
3
4
@@ -1,4 +1,4 @@
-namespace EnterpriseWebLibrary.EnterpriseWebFramework.Controls { +namespace EnterpriseWebLibrary.EnterpriseWebFramework {   /// <summary>   /// Method invoked when a new file is uploaded.   /// </summary>
 
1
2
 
3
4
5
 
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
 
1
 
2
3
4
5
 
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
@@ -1,5 +1,5 @@
 using System; -using EnterpriseWebLibrary.EnterpriseWebFramework.Controls; +using EnterpriseWebLibrary.DataAccess.BlobStorage;  using Humanizer;    namespace EnterpriseWebLibrary.EnterpriseWebFramework { @@ -20,31 +20,28 @@
  /// <param name="forcedImageWidthGetter">A function that gets the width in pixels to which the specified file should be scaled, while maintaining its aspect   /// ratio. The file must be an image. Pass null or return null if the file is not an image or you do not want scaling.</param>   public BlobFileResponse( int fileId, Func<bool> processAsAttachmentGetter, Func<int?> forcedImageWidthGetter = null ) { - file = BlobFileOps.SystemProvider.GetFile( fileId ); + file = BlobStorageStatics.SystemProvider.GetFile( fileId );   processAsAttachment = new Lazy<bool>( processAsAttachmentGetter ?? ( () => false ) );   forcedImageWidth = new Lazy<int?>( forcedImageWidthGetter ?? ( () => null ) );   }   - internal DateTime FileLastModificationDateAndTime { get { return file.UploadedDate; } } + internal DateTime FileLastModificationDateAndTime => file.UploadedDate;   - internal string ETagBase { get { return identifier; } } - internal string MemoryCacheKey { get { return identifier; } } + internal string ETagBase => identifier; + internal string MemoryCacheKey => identifier;   - private string identifier { - get { - return "blobFile-{0}-{1}-{2}".FormatWith( - file.FileId, - processAsAttachment.Value ? "a" : "i", - forcedImageWidth.Value.HasValue ? forcedImageWidth.Value.Value.ToString() : "nonscaled" ); - } - } + private string identifier => + "blobFile-{0}-{1}-{2}".FormatWith( + file.FileId, + processAsAttachment.Value ? "a" : "i", + forcedImageWidth.Value.HasValue ? forcedImageWidth.Value.Value.ToString() : "nonscaled" );     internal EwfResponse GetResponse() {   return EwfResponse.Create(   file.ContentType,   new EwfResponseBodyCreator(   () => { - var contents = BlobFileOps.SystemProvider.GetFileContents( file.FileId ); + var contents = BlobStorageStatics.SystemProvider.GetFileContents( file.FileId );   if( forcedImageWidth.Value.HasValue )   contents = EwlStatics.ResizeImage( contents, forcedImageWidth.Value.Value );   return contents;
 
6
7
8
9
10
11
12
 
13
14
15
 
6
7
8
 
 
 
 
9
10
11
12
@@ -6,10 +6,7 @@
  internal static string DownloadExisting { get { return getCorrectTranslation( "Download existing", "Descargar archivo existente" ); } }   internal static string NoExistingFile { get { return getCorrectTranslation( "No existing file", "No existe el archivo" ); } }   - /// <summary> - /// Intended to be used as PleaseUploadAFile + " 'File name'". - /// </summary> - internal static string PleaseUploadAFile { get { return getCorrectTranslation( "Please upload a file:", "Por favor, cargue un archivo:" ); } } + internal static string PleaseUploadAFile => getCorrectTranslation( "Please upload a file.", "Por favor, cargue un archivo." );     /// <summary>   /// "Unacceptable file extension. Acceptable file extensions are:".
Change 1 of 1 Show Entire File Core/​EnterpriseWebFramework/​Form Controls/​FileUpload.cs Stacked
renamed from Core/EnterpriseWebFramework/Form Controls/EwfFileUpload.cs
 
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
 
 
 
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
 
@@ -1,64 +1,83 @@
-using System.IO; +using System; +using System.Collections.Generic; +using System.IO;  using System.Web; -using System.Web.UI; -using System.Web.UI.WebControls; +using EnterpriseWebLibrary.InputValidation;  using EnterpriseWebLibrary.IO;    namespace EnterpriseWebLibrary.EnterpriseWebFramework {   /// <summary> - /// A file upload control. + /// A file-upload control.   /// </summary> - public class EwfFileUpload: WebControl, ControlTreeDataLoader, FormValueControl { - private readonly FormValue<HttpPostedFile> formValue; - private RsFile postBackValue; + public class FileUpload: FormControl<PhrasingComponent> { + public FormControlLabeler Labeler { get; } + public PhrasingComponent PageComponent { get; } + public EwfValidation Validation { get; }   - public EwfFileUpload() { - formValue = new FormValue<HttpPostedFile>( + /// <summary> + /// Creates a file-upload control. + /// </summary> + /// <param name="displaySetup"></param> + /// <param name="validationPredicate"></param> + /// <param name="validationMethod">The validation method. Pass null if you’re only using this control for page modification.</param> + /// <param name="validationErrorNotifier"></param> + public FileUpload( + DisplaySetup displaySetup = null, Func<bool, bool> validationPredicate = null, Action<RsFile, Validator> validationMethod = null, + Action validationErrorNotifier = null ) { + Labeler = new FormControlLabeler(); + + var id = new ElementId(); + var formValue = new FormValue<HttpPostedFile>(   () => null, - () => this.IsOnPage() ? UniqueID : "", + () => id.Id,   v => "", - rawValue => - rawValue != null - ? PostBackValueValidationResult<HttpPostedFile>.CreateValid( rawValue.ContentLength > 0 ? rawValue : null ) - : PostBackValueValidationResult<HttpPostedFile>.CreateInvalid() ); + rawValue => rawValue == null + ? PostBackValueValidationResult<HttpPostedFile>.CreateInvalid() + : PostBackValueValidationResult<HttpPostedFile>.CreateValid( rawValue.ContentLength > 0 ? rawValue : null ) ); + + PageComponent = new CustomPhrasingComponent( + new DisplayableElement( + context => { + id.AddId( context.Id ); + Labeler.AddControlId( context.Id ); + + EwfPage.Instance.Form.Enctype = "multipart/form-data"; + + return new DisplayableElementData( + displaySetup, + () => { + var attributes = new List<Tuple<string, string>>(); + attributes.Add( Tuple.Create( "type", "file" ) ); + attributes.Add( Tuple.Create( "name", context.Id ) ); + + return new DisplayableElementLocalData( + "input", + new FocusabilityCondition( true ), + isFocused => { + if( isFocused ) + attributes.Add( Tuple.Create( "autofocus", "autofocus" ) ); + return new DisplayableElementFocusDependentData( attributes: attributes ); + } ); + } ); + }, + formValue: formValue ).ToCollection() ); + + if( validationMethod != null ) + Validation = formValue.CreateValidation( + ( postBackValue, validator ) => { + if( validationPredicate != null && !validationPredicate( postBackValue.ChangedOnPostBack ) ) + return; + validationMethod( getRsFile( postBackValue.Value ), validator ); + } );   }   - void ControlTreeDataLoader.LoadData() { - Attributes.Add( "type", "file" ); - Attributes.Add( "name", UniqueID ); - - EwfPage.Instance.Form.Enctype = "multipart/form-data"; + private RsFile getRsFile( HttpPostedFile file ) { + if( file == null ) + return null; + using( var ms = new MemoryStream() ) { + file.InputStream.CopyTo( ms ); + return new RsFile( ms.ToArray(), Path.GetFileName( file.FileName ), contentType: file.ContentType ); + }   } - - FormValue FormValueControl.FormValue { get { return formValue; } } - - /// <summary> - /// Gets the post back value. - /// </summary> - public RsFile GetPostBackValue( PostBackValueDictionary postBackValues ) { - if( postBackValue == null ) { - var value = formValue.GetValue( postBackValues ); - if( value == null ) - return null; - - using( var ms = new MemoryStream() ) { - value.InputStream.CopyTo( ms ); - postBackValue = new RsFile( ms.ToArray(), Path.GetFileName( value.FileName ), contentType: value.ContentType ); - } - } - return postBackValue; - } - - /// <summary> - /// Returns true if the value changed on this post back. - /// </summary> - public bool ValueChangedOnPostBack( PostBackValueDictionary postBackValues ) { - return formValue.ValueChangedOnPostBack( postBackValues ); - } - - /// <summary> - /// Returns the tag that represents this control in HTML. - /// </summary> - protected override HtmlTextWriterTag TagKey { get { return HtmlTextWriterTag.Input; } }   }  } \ No newline at end of file
 
4
5
6
 
7
8
9
10
11
12
13
 
69
70
71
72
 
73
74
75
 
4
5
6
7
8
9
10
 
11
12
13
 
69
70
71
 
72
73
74
75
@@ -4,10 +4,10 @@
 using EnterpriseWebLibrary.Caching;  using EnterpriseWebLibrary.Configuration;  using EnterpriseWebLibrary.DataAccess; +using EnterpriseWebLibrary.DataAccess.BlobStorage;  using EnterpriseWebLibrary.Email;  using EnterpriseWebLibrary.Encryption;  using EnterpriseWebLibrary.EnterpriseWebFramework; -using EnterpriseWebLibrary.EnterpriseWebFramework.Controls;  using EnterpriseWebLibrary.EnterpriseWebFramework.UserManagement;    namespace EnterpriseWebLibrary { @@ -69,7 +69,7 @@
  new Aspose.Words.License().SetLicense( asposeWordsLicensePath );     AppMemoryCache.Init(); - BlobFileOps.Init(); + BlobStorageStatics.Init();   DataAccessStatics.Init();   DataAccessState.Init( mainDataAccessStateGetter, useLongDatabaseTimeouts );   EncryptionOps.Init();