使用 IntraWeb (30) - TIWAppInfo、TIWMimeTypes、TIWAppCache



 
TIWAppInfo  //IntraWeb 12.2.15 开始使用 TIWAppInfo 来获取应用的相关信息, 和 IWServerController、WebApplication 的某些属性有重复 TIWMimeTypes //IntraWeb 14.0.11 新增, 可方便处理 Http Mime Types; Mime 类型? 我的理解是: 浏览器接受到一个文件或数据流, 如果让浏览器解析(而不是下载), 浏览器该按什么类型来解析呢? 所以需要指定类型. TIWAppCache  //IntraWeb 14.0.29 新增, 可以方便处理缓存文件; 之前有类似的功能, 如: IWServerController.NewCacheFile {三个类提供的都是 class 方法, 使用时无须实例化} 


TIWAppInfo 所在单元及继承链:
IW.Common.AppInfo.TIWAppInfo < TObject

主要成员:




 
class function GetAppFullFileName: string class function GetAppFileName: string class function GetAppLogFileName: string class function GetAppPath: string class function GetAppName: string class function GetSystemPath: string class function GetTempPath: string class function GetCurrentPath: string class function GetComputerName: string class function GetFileInfo(const aFileName: string; aFileInfo: TFileInfo): string class function GetAppVersion: string 


测试:




 
uses IW.Common.AppInfo; procedure TIWForm1.IWButton1Click(Sender: TObject); var   str: string;   i: Integer; begin   IWMemo1.Lines.Add(TIWAppInfo.GetAppFullFileName);   IWMemo1.Lines.Add(TIWAppInfo.GetAppFileName);   IWMemo1.Lines.Add(TIWAppInfo.GetAppLogFileName);   IWMemo1.Lines.Add(TIWAppInfo.GetAppPath);   IWMemo1.Lines.Add(TIWAppInfo.GetAppName);   IWMemo1.Lines.Add(TIWAppInfo.GetSystemPath);   IWMemo1.Lines.Add(TIWAppInfo.GetTempPath);   IWMemo1.Lines.Add(TIWAppInfo.GetCurrentPath);   IWMemo1.Lines.Add(TIWAppInfo.GetComputerName);   IWMemo1.Lines.Add(TIWAppInfo.GetAppVersion);   IWMemo1.Lines.Add('===============');   for i := 0 to 9 do   begin     str := TIWAppInfo.GetFileInfo(TIWAppInfo.GetSystemPath + 'NotePad.exe', TFileInfo(i));     IWMemo1.Lines.Add(str);   end;   IWMemo1.Lines.Add('==============='); end; 



TIWMimeTypes 所在单元及继承链:
IWMimeTypes.TIWMimeTypes < TObject

主要成员:




 
class function IsStaticFile(const aFileName: string; out aMimeType: string): Boolean // class function GetAsString(const aFileExtension: string): string //根据扩展名即可获取类型的标准字符串很方便, 譬如 TIWMimeTypes.GetAsString('.pdf') 将返回 application/pdf class function GetAsString(const aMimeType: TMimeType): string  //TIWMimeTypes.GetAsString(mtPDF) 结果也是 application/pdf class procedure RegisterType(const aFileExtension: string; const aMimeTypeDesc: string; const aIsStatic: Boolean) //能自行注册 class procedure UnregisterType(const aFileExtension: string)    // {IWMimeTypes.TIWMimeType 枚举的定义} TIWMimeType = (mtUnknown, mtBinary, mtJPG, mtGIF, mtPNG, mtRSS, mtXML, mtTXT, mtICO, mtHTML, mtJavaScript, mtPDF, mtZIP, mtCSS, mtMP3, mtOGG, mtWAV, mtEXE, mtFlash, mtWMV, mtMOV, mtAVI, mtMPEG, mtXSL); {IWMimeTypes 单元提供的常用的 Mime 类型常量} MIME_JPG        =  'image/jpeg';                            MIME_GIF        =  'image/gif';                              MIME_PNG        =  'image/png';                              MIME_RSS        =  'application/rss+xml; charset=UTF-8';    MIME_XML        =  'text/xml; charset=UTF-8';                MIME_XSL        =  'text/xsl; charset=UTF-8';                MIME_TXT        =  'text/plain; charset=UTF-8';              MIME_ICO        =  'image/x-ico';                            MIME_JavaScript =  'application/x-javascript; charset=UTF-8'; MIME_PDF        =  'application/pdf';                        MIME_CSS        =  'text/css; charset=UTF-8';                MIME_MP3        =  'audio/mpeg';                            MIME_OGG        =  'audio/ogg';                              MIME_WAV        =  'audio/wav';                              MIME_Flash      =  'application/x-shockwave-flash';          MIME_WMV        =  'video/x-ms-wmv';                        MIME_MOV        =  'video/quicktime';                        MIME_AVI        =  'video/x-msvideo';                        MIME_MPEG      =  'video/mpeg';                            MIME_Binary    =  'application/octet-stream';              MIME_HTML      =  'text/html; charset=UTF-8'; { 更多不常用的类型可参见: http://www.iana.org/assignments/media-types/media-types.xhtml } 



TIWAppCache 所在单元及继承链:
IWAppCache.TIWAppCache < TObject

主要成员:




 
{建立缓存流; 如需特别指定第一个参数时, 不如选用下面三个函数} class procedure NewCacheStream(aOwner: TObject;       //建立页面级的缓存要指定当前窗体(一般用 Self); 建立 Session 级缓存可指定 WebApplication; 建立应用级缓存指定 nil                                const aContentType: string;    //Mime Type 字符串, 如: application/pdf       aCacheType: TCacheType;       //缓存期选项:ctOneTime、ctApp、ctSession、ctForm       out ACacheStream: TCacheStream; //输出流       out aFileHRef: string       //输出缓存文件地址       ) {建立建立应用级缓存流; 参数 1 将被忽略, 其它同上} class procedure NewAppCacheStream(aOwner: TObject; const aContentType: string; out ACacheStream: TCacheStream; out aFileHRef: string) {建立建立 Session 级缓存流; 参数 1 将被忽略, 其它同上} class procedure NewSessionCacheStream(aOwner: TObject; const aContentType: string; out ACacheStream: TCacheStream; out aFileHRef: string) {建立建立页面级缓存流; 参数 1 将被忽略, 其它同上} class procedure NewFormCacheStream(aOwner: TObject; const aContentType: string; out ACacheStream: TCacheStream; out aFileHRef: string) {保存流到缓存文件} class function StreamToCacheFile(aOwner: TObject; AStream: TStream; const aContentType: string; const aCacheType: TCacheType): string {保存图像到缓存文件} class function GraphicToCacheFile(aOwner: TObject; AGraphic: TGraphic; const aCacheType: TCacheType; const PreferPNG: Boolean): string class function GraphicToCacheFile(aOwner: TObject; AGraphic: TGraphic; imgType: TIWImageOutput; const aCacheType: TCacheType): string  //TIWImageOutput = (ioGIF, ioJPEG, ioPNG) {保存资源到缓存文件} class function ResourceToCacheFile(aOwner: TObject; const aResourceName: string; const aContentType: string; const aCacheType: TCacheType): string {情况缓存} class function ClearCache(ACacheList: TStrings): Integer {创建一个临时文件, 位置在用户临时文件夹} class function NewTempFileName: string {添加文件到缓存} class function AddFileToCache(aOwner: TObject; const aFileName: string; const aContentType: string; const aCacheType: TCacheType): string 


测试 - 将资源中的图片提取到缓存, 然后呈现出来:


 



 
uses IWAppCache, IWServerInternalFiles; procedure TIWForm1.IWButton1Click(Sender: TObject); var   fStream: TStream;   fPath: string; begin   fStream := TIWServerInternalFiles.GetResourceStream('IW_GFX_LogoIntraWeb');   fPath := TIWAppCache.StreamToCacheFile(Self, fStream, 'image/png');   IWImageFile1.ImageFile.Filename := fPath;   fStream.Free; end; 


常用路径:


 



 
{获取代码:-------------------------------------------------------} uses ServerController, IW.Common.AppInfo; procedure TIWForm1.IWAppFormCreate(Sender: TObject); begin   IWMemo1.Lines.Add(IWServerController.ContentPath + #9'{IWServerController.ContentPath}');   IWMemo1.Lines.Add(IWServerController.CacheDir + #9'{IWServerController.CacheDir}');   IWMemo1.Lines.Add(IWServerController.TemplateDir + #9'{IWServerController.TemplateDir}' + sLineBreak);   IWMemo1.Lines.Add(WebApplication.AppUrlBase + #9'{WebApplication.AppUrlBase}');   IWMemo1.Lines.Add(WebApplication.InternalUrlBase + #9'{WebApplication.InternalUrlBase}');   IWMemo1.Lines.Add(WebApplication.SessionInternalUrlBase + #9'{WebApplication.SessionInternalUrlBase}');   IWMemo1.Lines.Add(WebApplication.SessionUrlBase + #9'{WebApplication.SessionUrlBase}');   IWMemo1.Lines.Add(WebApplication.UserCacheUrlBase + #9'{WebApplication.UserCacheUrlBase}');   IWMemo1.Lines.Add(WebApplication.ApplicationURL + #9'{WebApplication.ApplicationURL}');   IWMemo1.Lines.Add(WebApplication.ApplicationPath + #9'{WebApplication.ApplicationPath}');   IWMemo1.Lines.Add(WebApplication.ReferringURL + #9'{WebApplication.ReferringURL}');   IWMemo1.Lines.Add(WebApplication.UserCacheDir + #9'{WebApplication.UserCacheDir}' + sLineBreak);   IWMemo1.Lines.Add(TIWAppInfo.GetAppFullFileName + #9'{TIWAppInfo.GetAppFullFileName}');   IWMemo1.Lines.Add(TIWAppInfo.GetAppPath + #9'{TIWAppInfo.GetAppPath}');   IWMemo1.Lines.Add(TIWAppInfo.GetAppFileName + #9'{TIWAppInfo.GetAppFileName}');   IWMemo1.Lines.Add(TIWAppInfo.GetAppName + #9'{TIWAppInfo.GetAppName}');   IWMemo1.Lines.Add(TIWAppInfo.GetTempPath + #9'{TIWAppInfo.GetTempPath}');   IWMemo1.Lines.Add(TIWAppInfo.GetCurrentPath + #9'{TIWAppInfo.GetCurrentPath}'); end; {参考结果:-------------------------------------------------------} C:\Users\wy\Documents\RAD Studio\Projects\MyTest6\Win32\Debug\wwwroot\ {IWServerController.ContentPath} C:\Users\wy\AppData\Local\Temp\01a3ozdw6r\ {IWServerController.CacheDir} C:\Users\wy\Documents\RAD Studio\Projects\MyTest6\Win32\Debug\Templates\ {IWServerController.TemplateDir} / {WebApplication.AppUrlBase} /$/ {WebApplication.InternalUrlBase} /$/ {WebApplication.SessionInternalUrlBase} / {WebApplication.SessionUrlBase} /$/MyApp/0pnlkje0r4hi7j19tzrq30eq0k2i/ {WebApplication.UserCacheUrlBase} http://127.0.0.1:3126 {WebApplication.ApplicationURL} C:\Users\wy\Documents\RAD Studio\Projects\MyTest6\Win32\Debug\ {WebApplication.ApplicationPath} http://127.0.0.1:3126/$/start {WebApplication.ReferringURL} C:\Users\wy\AppData\Local\Temp\01a3ozdw6r\user\0pnlkje0r4hi7j19tzrq30eq0k2i\ {WebApplication.UserCacheDir} C:\Users\wy\Documents\RAD Studio\Projects\MyTest6\Win32\Debug\MyTest6.exe {TIWAppInfo.GetAppFullFileName} C:\Users\wy\Documents\RAD Studio\Projects\MyTest6\Win32\Debug\ {TIWAppInfo.GetAppPath} MyTest6.exe {TIWAppInfo.GetAppFileName} MyTest6 {TIWAppInfo.GetAppName} C:\Users\wy\AppData\Local\Temp\ {TIWAppInfo.GetTempPath} C:\Users\wy\Documents\RAD Studio\Projects\MyTest6\Win32\Debug\ {TIWAppInfo.GetCurrentPath}
New property TIWForm.KeepAlive property. When true, IntraWeb will generate JavaScript code that will send a special request to IWServer avoiding session expiration. New method ReleaseAndRedirect() in TIWBaseForm. It can be used to release the current active form and redirect to other URL internal to the IntraWeb application, e.g. a registered content handler. New properties of TContentBase (content handlers base class): CanStartSession: Boolean; RequireSessionStart: Boolean; A Slim Reader/Writer lock object is used in TIWStandAloneServer and TIWServerInternalFiles instead of TMultiReadExclusiveWriteSynchronizer object. This new lock is available under Windows Vista and up, and should increase IW server performance under heavy concurrency/load. New Event description tab in IWScriptEvents editor with some valuable information about JavaScript events Modification in TIWBaseForm: ExecuteForm() and GenerateForm() methods were made static (non virtual). These methods now call DoExecuteForm() and DoGenerateForm() virtual (protected) methods. Bug fix: User cache directory is deleted when session expires. Modification in routines responsible for cache directory removal. In our tests it fixed cache directory removal when application terminates. Bug fix: TIWDBCheckBox could raise an exception during rendering when attached to a empty DataSet Bug fix: When deploying the application as ISAPI, session tracking without cookies would fail Bug fix: When a IW application was compiled with runtime packages, TIWAppInfo.GetAppFullFileName was returning the name and path of the BPL file, not the EXE/DLL main file Bug fix: TContentRedirect could fail if ServerController.AllowMultipleSessionsPerUser = True Bug fix: IW Splitter didn't work with Internet Explorer 11
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值