使用 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
主要成员:
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
主要成员:
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
主要成员:
{建立缓存流; 如需特别指定第一个参数时, 不如选用下面三个函数}
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}
使用 IntraWeb (30) - TIWAppInfo、TIWMimeTypes、TIWAppCache的更多相关文章
- IntraWeb XIV 类型速查表
tkClass ================== IWUserSessionBase.TIWUserSessionBase < TDataModule < TComponent < ...
- 使用 IntraWeb (45) - 活用 IntraWeb
asp.net 刚开始时, 也是拖拉控件, 但后来有了 MVC.xNext. 换个思路使用 IntraWeb 吧: 界面全部用 html+js+css 实现(有些会是用 Delphi 动态生成), 然 ...
- 总结30个CSS3选择器
或许大家平时总是在用的选择器都是:#id .class 以及标签选择器.可是这些还远远不够,为了在开发中更加得心应手,本文总结了30个CSS3选择器,希望对大家有所帮助. 1 *:通用选择器 ;; ...
- 值得收藏!国外最佳互联网安全博客TOP 30
如果你是网络安全从业人员,其中重要的工作便是了解安全行业的最新资讯以及技术趋势,那么浏览各大安全博客网站或许是信息来源最好的方法之一.最近有国外网站对50多个互联网安全博客做了相关排名,小编整理其中排 ...
- CSharpGL(30)用条件渲染(Conditional Rendering)来提升OpenGL的渲染效率
CSharpGL(30)用条件渲染(Conditional Rendering)来提升OpenGL的渲染效率 当场景中有比较复杂的模型时,条件渲染能够加速对复杂模型的渲染. 条件渲染(Conditio ...
- 30分钟学会XAML
1.狂妄的WPF 相对传统的Windows图形编程,需要做很多复杂的工作,引用许多不同的API.例如:WinForm(带控件表单).GDI+(2D图形).DirectX API(3D图形)以及流媒体和 ...
- Shell脚本编程30分钟入门
Shell脚本编程30分钟入门 转载地址: Shell脚本编程30分钟入门 什么是Shell脚本 示例 看个例子吧: #!/bin/sh cd ~ mkdir shell_tut cd shell_t ...
- ViEmu 3.6.0 过期 解除30天限制的方法
下载:链接: http://pan.baidu.com/s/1c2HUuWw 密码: sak8 删除下面2个地方 HKEY_CLASSES_ROOT\Wow6432Node\CLSID\{B9CDA4 ...
- AlloyTouch全屏滚动插件发布--30秒搞定顺滑H5页
原文链接:https://github.com/AlloyTeam/AlloyTouch/wiki/AlloyTouch-FullPage-Plugin 先验货 插件代码可以在这里找到. 注意,虽然是 ...
随机推荐
- nagios系列(八)之nagios通过nsclient监控windows主机
nagios通过nsclient监控windows主机 1.下载NSClient -0.3.8-Win32.rar安装在需要被监控的windows主机中 可以设置密码,此处密码留空 2.通过在nagi ...
- 从LeNet-5到DenseNet
一篇不错的总结:https://zhuanlan.zhihu.com/p/31006686
- jquery中对父节点和子节点的利用
<tr id='new_tr'> <td id="td_1">td1</td> <td id="td_2">td ...
- ireport 添加行自增序号
ireport 添加行自增序号 在ireport报表中加入行的自增序号方法: 添加一个变量,如变量名为 index: 设置变量类型为Integer,计算类型为count:变量表达式为$V{index} ...
- 谷歌云ssh开启root密码登录
修改配置 1.先选择从浏览器打开ssh连接服务器 连接登录成功后,输入以下命令 sudo -i #切换到root passwd #修改密码 然后会要求输入新密码,然后再重复一次密码,输入密码的时候不会 ...
- IntentService用法
IntentService 用完即走 IntentService,可以看做是Service和HandlerThread的结合体,在完成了使命之后会自动停止,适合需要在工作线程处理UI无关任务的 ...
- 矩阵优化dp
链接:https://www.luogu.org/problemnew/show/P1939 题解: 矩阵优化dp模板题 搞清楚矩阵是怎么乘的构造一下矩阵就很简单了 代码: #include < ...
- day17--JQuery实例
1.表格选择框--全选,反选,取消 <!DOCTYPE html> <html lang="en"> <head> <meta c ...
- asp.net core服务的生命周期
Transient:每一次GetService都会创建一个新的实例 Scoped:在同一个Scope内只初始化一个实例 ,可以理解为( 每一个request级别只创建一个实例,同一个http requ ...
- 安装Numpy方法
Numpy安装(要先安装好python,见<windows下的python环境搭建(python2和python3不兼容,python2用的多)>) Numpy是Python的一个科学计算 ...