本文整理汇总了C#中Fiddler.Session.getFilePath方法的典型用法代码示例。如果您正苦于以下问题:C# Session.getFilePath方法的具体用法?C# Session.getFilePath怎么用?C# Session.getFilePath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Fiddler.Session
的用法示例。
在下文中一共展示了Session.getFilePath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FiddlerApplication_BeforeResponse
private void FiddlerApplication_BeforeResponse(Session oSession) {
if (oSession.PathAndQuery.StartsWith("/kcs/")) {
string filePath = Utility.Config.Instance.CacheFolder + oSession.getFilePath();
if (oSession.responseCode == 304) {
// code 304, 文件沒有修改, 使用本地文件
if (!string.IsNullOrEmpty(filePath) && File.Exists(filePath)) {
oSession.bBufferResponse = true;
oSession.ResponseBody = File.ReadAllBytes(filePath);
oSession.oResponse.headers.HTTPResponseCode = 200;
oSession.oResponse.headers.HTTPResponseStatus = "200 OK";
oSession.oResponse.headers["Last-Modified"] = oSession.oRequest.headers["If-Modified-Since"];
oSession.oResponse.headers["Accept-Ranges"] = "bytes";
oSession.oResponse.headers.Remove("If-Modified-Since");
oSession.oRequest.headers.Remove("If-Modified-Since");
if (filePath.EndsWith(".swf"))
oSession.oResponse.headers["Content-Type"] = "application/x-shockwave-flash";
Utility.Logger.Add("Response > [304, 返回本地]" + filePath);
}
} else if (oSession.responseCode == 200) {
// code 200, 更新緩存紀錄
Cache.UpdataCache(oSession.PathAndQuery);
if (File.Exists(filePath)) {
string resBody = oSession.GetResponseBodyAsString();
string cacheBody = File.ReadAllText(filePath);
// 比對緩存
if (resBody.Equals(cacheBody)) {
Utility.Logger.Add("Response > [200, 檔案相同]" + filePath);
} else {
if (Utility.Config.Instance.AutoBackupCache) {
// 保存舊緩存
int index = filePath.LastIndexOf('.');
if (index > 0) {
string iPath = filePath.Substring(0, index);
string iType = filePath.Substring(index); // .swf
DateTime dateNow = DateTime.Now;
string dateTime = (dateNow.Year % 100).ToString() + dateNow.Month.ToString("00") + dateNow.Day.ToString("00");
string newFilePath = iPath + "_" + dateTime + iType;
File.Move(filePath, newFilePath);
}
}
try {
oSession.SaveResponseBody(filePath);
} catch (Exception ex) {
DateTime dateNow = DateTime.Now;
string dateTime = dateNow.Year.ToString() + dateNow.Month.ToString("00") + dateNow.Day.ToString("00") + "_" +
dateNow.Hour.ToString("00") + dateNow.Minute.ToString("00") + dateNow.Second.ToString("00");
Utility.Logger.CmdLog("dateTime: ");
Utility.Logger.CmdLog(ex.ToString());
}
Utility.Logger.Add("Response > [200, 更新緩存]" + filePath);
}
// code 200, 更新時間
GMTHelper._SaveModifiedTime(filePath, oSession.oResponse.headers["Last-Modified"]);
} else {
// 儲存快取並設置時間
try {
oSession.SaveResponseBody(filePath);
} catch (Exception ex) {
DateTime dateNow = DateTime.Now;
string dateTime = dateNow.Year.ToString() + dateNow.Month.ToString("00") + dateNow.Day.ToString("00") + "_" +
dateNow.Hour.ToString("00") + dateNow.Minute.ToString("00") + dateNow.Second.ToString("00");
Utility.Logger.CmdLog("dateTime: ");
Utility.Logger.CmdLog(ex.ToString());
}
GMTHelper._SaveModifiedTime(filePath, oSession.oResponse.headers["Last-Modified"]);
Utility.Logger.Add("Response > [200, 建立緩存]" + filePath);
}
}
// 魔改
if (filePath.Contains(@"kcs\resources\swf\ships\")) {
string fileName = filePath.getFileName();
if (CosManager.Instance.IsPaired(fileName)) {
Utility.Logger.Add("IsPaired > " + fileName);
//filePath = filePath.Replace(fileName, CosManager.Instance.GetPair(fileName));
filePath = Utility.Config.Instance.CostumeFolder + @"\" + CosManager.Instance.GetPair(fileName) + ".swf";
oSession.ResponseBody = File.ReadAllBytes(filePath);
}
}
} else if (oSession.PathAndQuery.StartsWith("/kcsapi/")) {
//.........这里部分代码省略.........