- Visual C++源码
- Visual Basic源码
- C++ Builder源码
- Java源码
- Delphi源码
- C/C++源码
- PHP源码
- Perl源码
- Python源码
- Asm源码
- Pascal源码
- Borland C++源码
- Others源码
- SQL源码
- VBScript源码
- JavaScript源码
- ASP/ASPX源码
- C#源码
- Flash/ActionScript源码
- matlab源码
- PowerBuilder源码
- LabView源码
- Flex源码
- MathCAD源码
- VBA源码
- IDL源码
- Lisp/Scheme源码
- VHDL源码
- Objective-C源码
- Fortran源码
- tcl/tk源码
- QT源码
- // -- FILE ------------------------------------------------------------------
- // name : VirtualUserFormFileProvider.cs
- // project : Itenso Web User Forms
- // created : Jani Giannoudis - 2008.10.30
- // language : c#
- // environment: .NET 2.0
- // copyright : (c) 2008 by Itenso GmbH, Switzerland
- // --------------------------------------------------------------------------
- using System;
- using System.IO;
- using System.Text;
- using System.Collections.Generic;
- using Itenso.WebUserForms.Controls;
- namespace Itenso.WebUserForms.Runtime
- {
- // ------------------------------------------------------------------------
- public class VirtualUserFormFileProvider : VirtualUserFormProvider, IUserFormProvider
- {
- // ----------------------------------------------------------------------
- public VirtualUserFormFileProvider( string virtualPath, string physicalPath )
- : base( virtualPath )
- {
- if ( string.IsNullOrEmpty( physicalPath ) )
- {
- throw new ArgumentNullException( "physicalPath" );
- }
- if ( !Directory.Exists( physicalPath ) )
- {
- throw new ArgumentException( "invalid physical path" );
- }
- this.physicalPath = physicalPath;
- } // VirtualUserFormFileProvider
- // ----------------------------------------------------------------------
- public string PhysicalPath
- {
- get { return this.physicalPath; }
- } // PhysicalPath
- // ----------------------------------------------------------------------
- public string GetVirtualFormName( string formName )
- {
- if ( string.IsNullOrEmpty( formName ) )
- {
- throw new ArgumentNullException( "formName" );
- }
- string virtualFormName = VirtualPath;
- if ( !virtualFormName.EndsWith( "/" ) )
- {
- virtualFormName += "/";
- }
- virtualFormName += formName;
- if ( !virtualFormName.EndsWith( UserFormInfo.FileExtension ) )
- {
- virtualFormName += UserFormInfo.FileExtension;
- }
- return virtualFormName;
- } // GetVirtualFormName
- // ----------------------------------------------------------------------
- public List<string> GetAvailableUserForms()
- {
- return ( (IUserFormProvider)this ).GetAvailableUserForms( null );
- } // GetAvailableUserForms
- // ----------------------------------------------------------------------
- List<string> IUserFormProvider.GetAvailableUserForms( string formType )
- {
- List<string> formInfos = new List<string>();
- DirectoryInfo directoryInfo = new DirectoryInfo( this.physicalPath );
- foreach ( FileInfo fileInfo in directoryInfo.GetFiles( "*" + UserFormInfo.FileExtension ) )
- {
- formInfos.Add( fileInfo.Name.Replace( fileInfo.Extension, string.Empty ) );
- }
- return formInfos;
- } // IUserFormProvider.GetAvailableUserForms
- // ----------------------------------------------------------------------
- protected override Stream LoadUserForm( string virtualPath )
- {
- MemoryStream stream = null;
- string baseVirtualPath = VirtualPath.TrimStart( '~' );
- int pathIndex = virtualPath.IndexOf( baseVirtualPath );
- if ( pathIndex >= 0 )
- {
- string physicalFileName = Path.Combine(
- PhysicalPath,
- virtualPath.Substring( pathIndex + baseVirtualPath.Length + 1 ) );
- using ( StreamReader streamReader = new StreamReader( physicalFileName ) )
- {
- stream = new MemoryStream( Encoding.Default.GetBytes( streamReader.ReadToEnd() ) );
- }
- }
- return stream;
- } // LoadUserForm
- // ----------------------------------------------------------------------
- // members
- private readonly string physicalPath;
- } // class VirtualUserFormFileProvider
- } // namespace Itenso.WebUserForms.Runtime
- // -- EOF -------------------------------------------------------------------