VirtualUserFormProvider.cs
上传用户:husern
上传日期:2022-03-24
资源大小:534k
文件大小:3k
源码类别:

编辑器/阅读器

开发平台:

C#

  1. // -- FILE ------------------------------------------------------------------
  2. // name       : VirtualUserFormProvider.cs
  3. // project    : Itenso Web User Forms
  4. // created    : Jani Giannoudis - 2008.10.30
  5. // language   : c#
  6. // environment: .NET 2.0
  7. // copyright  : (c) 2008 by Itenso GmbH, Switzerland
  8. // --------------------------------------------------------------------------
  9. using System;
  10. using System.IO;
  11. using System.Web;
  12. using System.Web.Hosting;
  13. using System.Web.Caching;
  14. using System.Collections;
  15. namespace Itenso.WebUserForms.Runtime
  16. {
  17. // ------------------------------------------------------------------------
  18. public abstract class VirtualUserFormProvider : VirtualPathProvider
  19. {
  20. // ----------------------------------------------------------------------
  21. public VirtualUserFormProvider( string virtualPath )
  22. {
  23. if ( string.IsNullOrEmpty( virtualPath ) )
  24. {
  25. throw new ArgumentNullException( "virtualPath" );
  26. }
  27. this.virtualPath = virtualPath;
  28. } // VirtualUserFormProvider
  29. // ----------------------------------------------------------------------
  30. public string VirtualPath
  31. {
  32. get { return this.virtualPath; }
  33. } // VirtualPath
  34. // ----------------------------------------------------------------------
  35. private bool IsUserControlRequest( string requestPath )
  36. {
  37. string relativePath = VirtualPathUtility.ToAppRelative( requestPath );
  38. return relativePath.StartsWith( this.virtualPath, StringComparison.InvariantCultureIgnoreCase );
  39. } // IsUserControlRequest
  40. // ----------------------------------------------------------------------
  41. public override bool FileExists( string requestPath )
  42. {
  43. return IsUserControlRequest( requestPath ) || base.FileExists( requestPath );
  44. } // FileExists
  45. // ----------------------------------------------------------------------
  46. public override VirtualFile GetFile( string requestPath )
  47. {
  48. if ( IsUserControlRequest( requestPath ) )
  49. {
  50. Stream stream = LoadUserForm( requestPath );
  51. if ( stream != null )
  52. {
  53. return new VirtualUserFormFile( requestPath, stream );
  54. }
  55. }
  56. return base.GetFile( requestPath );
  57. } // GetFile
  58. // ----------------------------------------------------------------------
  59. public override CacheDependency GetCacheDependency( string requestPath, IEnumerable requestPathDependencies, DateTime utcStart )
  60. {
  61. if ( IsUserControlRequest( requestPath ) )
  62. {
  63. return null;
  64. }
  65. return base.GetCacheDependency( requestPath, requestPathDependencies, utcStart );
  66. } // GetCacheDependency
  67. // ----------------------------------------------------------------------
  68. protected abstract Stream LoadUserForm( string requestPath );
  69. // ----------------------------------------------------------------------
  70. // members
  71. private readonly string virtualPath;
  72. } // class VirtualUserFormProvider
  73. } // namespace Itenso.WebUserForms.Runtime
  74. // -- EOF -------------------------------------------------------------------