/// <summary> /// 加载文本 /// </summary> /// <param name="context"></param> /// <param name="code"></param> private bool LoadTxt(HttpContext context, PcsClient client, string file) { var response = context.Response; response.ContentType = "text/html"; var pcsRequest = client.Download(ROOT + file); HttpWebResponse pcsResponse = null; StreamReader pcsReader = null; try { pcsResponse = pcsRequest.GetResponse() as HttpWebResponse; long size = pcsResponse.ContentLength; if (size > -1) { if (size > 2097152) { response.Write("您要查看的文件过大!"); return true; } StringBuilder builder = new StringBuilder((int)size + 1024); builder.Append("<!DOCTYPE>"); builder.Append("<html>"); builder.Append("<head>"); //builder.Append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=").Append(pcsResponse.ContentEncoding).Append("\" />"); builder.Append("<title>文本文档</title>"); builder.Append("<style type=\"text/css\">body{background: #fff;color: #000;font-size: 12px;font-family: 宋体, 新宋体, 微软雅黑, \"Helvetica Neue\" , \"Lucida Grande\" , \"Segoe UI\" , Arial, Helvetica, Verdana, sans-serif;}</style>"); builder.Append("</head>"); builder.Append("<body>"); builder.Append("<pre>"); pcsReader = new StreamReader(pcsResponse.GetResponseStream()); int cnt; char[] buf = new char[10240]; cnt = pcsReader.Read(buf, 0, buf.Length); while (cnt > 0) { DoPrint(builder, buf, cnt); cnt = pcsReader.Read(buf, 0, buf.Length); } builder.Append("</pre>"); builder.Append("</body>"); builder.Append("</html>"); response.Write(builder.ToString()); } return true; } catch (Exception) { //response.Write(exp.Message); return false; } finally { if (pcsReader != null) { pcsReader.Close(); } if (pcsResponse != null) { pcsResponse.Close(); } } }
/// <summary> /// 加载用户配置文件 /// </summary> /// <param name="context"></param> /// <param name="code"></param> private string LoadCfg(HttpContext context, PcsClient client) { var pcsRequest = client.Download(ROOT + "/Page.Me"); HttpWebResponse pcsResponse = null; try { string page = ""; pcsResponse = pcsRequest.GetResponse() as HttpWebResponse; if (pcsResponse.ContentLength > -1) { XmlDocument xmlReader = new XmlDocument(); xmlReader.Load(pcsResponse.GetResponseStream()); var node = xmlReader.SelectSingleNode("/Amon"); if (node == null || node.Attributes["Ver"].InnerText != "1") { return page; } node = node.SelectSingleNode("Page"); if (node == null) { return page; } page = node.Attributes["Default"].InnerText; } return page; } catch (Exception) { return ""; } finally { if (pcsResponse != null) { pcsResponse.Close(); } } }
/// <summary> /// 加载网志 /// </summary> /// <returns></returns> private bool LoadObj(HttpContext context, PcsClient client, string file, string type) { var response = context.Response; response.ContentType = type; var pcsRequest = client.Download(ROOT + file); HttpWebResponse pcsResponse = null; StreamReader pcsReader = null; try { pcsResponse = pcsRequest.GetResponse() as HttpWebResponse; long size = pcsResponse.ContentLength; if (size > -1) { pcsReader = new StreamReader(pcsResponse.GetResponseStream()); int cnt; char[] buf = new char[10240]; cnt = pcsReader.Read(buf, 0, buf.Length); while (cnt > 0) { response.Write(buf, 0, cnt); cnt = pcsReader.Read(buf, 0, buf.Length); } } return true; } catch (Exception) { //response.Write(exp.Message); return false; } finally { if (pcsReader != null) { pcsReader.Close(); } if (pcsResponse != null) { pcsResponse.Close(); } } }
private bool LoadImg(HttpContext context, PcsClient client, string file, string ext) { var webResponse = context.Response; webResponse.ContentType = "image/" + ext; var pcsRequest = client.Download(ROOT + file); HttpWebResponse pcsResponse = null; Stream pcsStream = null; Stream webStream = null; try { pcsResponse = pcsRequest.GetResponse() as HttpWebResponse; long size = pcsResponse.ContentLength; if (size > -1) { if (size > 2097152) { webResponse.Write("您要查看的文件过大!"); return true; } webStream = webResponse.OutputStream; pcsStream = pcsResponse.GetResponseStream(); byte[] buf = new byte[4096]; int len = pcsStream.Read(buf, 0, buf.Length); while (len > 0) { webStream.Write(buf, 0, len); len = pcsStream.Read(buf, 0, buf.Length); } } return true; } catch (Exception) { //response.Write(exp.Message); return false; } finally { if (webStream != null) { webStream.Close(); } if (pcsStream != null) { pcsStream.Close(); } if (pcsResponse != null) { pcsResponse.Close(); } } }