Beispiel #1
0
        private void button_export_Click(object sender, System.EventArgs e)
        {
            if (this.Stream == null)
            {
                MessageBox.Show(this, "尚未装载任何内容");
                return;
            }

            // 询问文件全路径
            SaveFileDialog dlg = new SaveFileDialog();

            dlg.CreatePrompt = false;
            dlg.FileName     = this.LocalPath;
            // dlg.FileName = "outer_projects.xml";
            // dlg.InitialDirectory = Environment.CurrentDirectory;
            dlg.Filter           = "All files (*.*)|*.*";
            dlg.RestoreDirectory = true;

            if (dlg.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            using (Stream s = File.Create(dlg.FileName))
            {
                this.Stream.Seek(0, SeekOrigin.Begin);
                StreamUtil.DumpStream(this.Stream, s);
            }
        }
Beispiel #2
0
    // return:
    //      -1  出错
    //      0   成功
    //      1   暂时不能访问
    int DumpFile(string strFilename,
                 string strContentType,
                 out string strError)
    {
        strError = "";

        if (string.IsNullOrEmpty(strFilename))
        {
            strError = "DumpFile() strFilename 参数不应为空";
            return(-1);
        }
#if NO
        // 不让浏览器缓存页面
        this.Response.AddHeader("Pragma", "no-cache");
        this.Response.AddHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
        this.Response.AddHeader("Expires", "0");
#endif
        this.Response.ContentType = strContentType;

        FileInfo fi           = new FileInfo(strFilename);
        DateTime lastmodified = fi.LastWriteTimeUtc;

        this.Response.AddHeader("Last-Modified", DateTimeUtil.Rfc1123DateTimeString(lastmodified)); // .ToUniversalTime()

        try
        {
            using (Stream stream = File.Open(strFilename,
                                             FileMode.Open,
                                             FileAccess.Read,
                                             FileShare.ReadWrite)) // 2015/1/12
            {
                this.Response.AddHeader("Content-Length", stream.Length.ToString());

                FlushOutput flushdelegate = new FlushOutput(MyFlushOutput);
                stream.Seek(0, SeekOrigin.Begin);
                StreamUtil.DumpStream(stream, this.Response.OutputStream,
                                      flushdelegate);
            }
        }
        catch (FileNotFoundException)
        {
            strError = "文件 '" + strFilename + "' 不存在";
            return(0);
        }
        catch (DirectoryNotFoundException)
        {
            strError = "文件 '" + strFilename + "' 路径中某一级目录不存在";
            return(0);
        }
        catch (Exception ex)
        {
            strError = ExceptionUtil.GetAutoText(ex);
            return(-1);
        }

        return(1);
    }
Beispiel #3
0
    // return:
    //      -1  出错
    //      0   成功
    //      1   暂时不能访问
    int DumpRssFile(string strRssFile,
                    out string strError)
    {
        strError = "";

        // 不让浏览器缓存页面
        this.Response.AddHeader("Pragma", "no-cache");
        this.Response.AddHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
        this.Response.AddHeader("Expires", "0");

        this.Response.ContentType = "application/rss+xml";

        try
        {
            // http://stackoverflow.com/questions/904952/whats-causing-session-state-has-created-a-session-id-but-cannot-save-it-becau
            string sessionId = Session.SessionID;

            app.ResultsetLocks.LockForRead(strRssFile, 500);

            try
            {
                using (Stream stream = File.Open(strRssFile,
                                                 FileMode.Open,
                                                 FileAccess.ReadWrite,
                                                 FileShare.ReadWrite))
                {
                    this.Response.AddHeader("Content-Length", stream.Length.ToString());

                    FlushOutput flushdelegate = new FlushOutput(MyFlushOutput);

                    stream.Seek(0, SeekOrigin.Begin);

                    StreamUtil.DumpStream(stream, this.Response.OutputStream,
                                          flushdelegate);
                }
            }
            finally
            {
                app.ResultsetLocks.UnlockForRead(strRssFile);
            }
        }
        catch (System.ApplicationException /*ex*/)
        {
            this.Response.ContentType       = "text/plain";
            this.Response.StatusCode        = 503;
            this.Response.StatusDescription = "相关的XML缓存正在被创建,请稍后重新访问";
            return(1);
        }

        return(0);
    }
Beispiel #4
0
        //写子文件数据	注.外部保证把位置移好
        //source: 二进制流
        //strID: 记录ID
        //target: 目标流
        //lFileLengthTotal: 文件总长度
        //0: 正常得到文件内容 -1:文件名为空
        public static int WriteFile(Stream source,
                                    string strID,
                                    Stream target,
                                    ref long lFileLengthTotal)
        {
            long lTotalLength = 0;  //总长度

            //长度字节数组
            byte[] bufferLength = new byte[8];

            //记住写总长度的位置
            long lPosition = target.Position;

            //1.开头空出8字节,最后写总长度*****************
            target.Write(bufferLength, 0, 8);

            //2.先写名称字符串的长度;
            //将字符串转换成字符数组
            byte[] bufferID = System.Text.Encoding.UTF8.GetBytes(strID);
            bufferLength = System.BitConverter.GetBytes((long)bufferID.Length);
            target.Write(bufferLength, 0, 8);
            lTotalLength += 8;

            //3.写名称字符串
            target.Write(bufferID,
                         0,
                         bufferID.Length);
            lTotalLength += bufferID.Length;

            //4.写二进制文件
            bufferLength = System.BitConverter.GetBytes(source.Length);
            //二进制文件的长度;
            target.Write(bufferLength, 0, 8);
            lTotalLength += 8;
            //写二进制文件内容
            source.Seek(0, SeekOrigin.Begin);
            StreamUtil.DumpStream(source,
                                  target);
            lTotalLength += source.Length;


            //5.返回开头写总长度
            bufferLength = System.BitConverter.GetBytes(lTotalLength);
            target.Seek(lPosition, SeekOrigin.Begin);
            target.Write(bufferLength, 0, 8);

            //将指针移到最后
            target.Seek(0, SeekOrigin.End);
            lFileLengthTotal += (lTotalLength + 8);
            return(0);
        }
Beispiel #5
0
    // return:
    //      -1  出错
    //      0   成功
    //      1   暂时不能访问
    int DumpFile(string strFilename,
                 string strContentType,
                 out string strError)
    {
        strError = "";

        // 不让浏览器缓存页面
        this.Response.AddHeader("Pragma", "no-cache");
        this.Response.AddHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
        this.Response.AddHeader("Expires", "0");

        this.Response.ContentType = strContentType;

        try
        {
            using (Stream stream = File.Open(strFilename,
                                             FileMode.Open,
                                             FileAccess.ReadWrite,
                                             FileShare.ReadWrite))
            {
                this.Response.AddHeader("Content-Length", stream.Length.ToString());

                FlushOutput flushdelegate = new FlushOutput(MyFlushOutput);

                stream.Seek(0, SeekOrigin.Begin);

                StreamUtil.DumpStream(stream, this.Response.OutputStream,
                                      flushdelegate);
            }
        }
        catch (FileNotFoundException)
        {
            strError = "文件 '" + strFilename + "' 不存在";
            return(0);
        }
        catch (DirectoryNotFoundException)
        {
            strError = "文件 '" + strFilename + "' 路径中某一级目录不存在";
            return(0);
        }
        catch (Exception ex)
        {
            strError = ExceptionUtil.GetAutoText(ex);
            return(-1);
        }

        return(1);
    }
        // 将片断流(sourceStream)中全部内容根据contentrange字符串定义的位置
        // 还原复制到目标文件(strOriginFileName)中
        // 也就是说,contentrange字符串实际上定义的是从目标文件抽取到片断的规则
        // 当strContentRange的值为""时,表示复制整个文件
        // paramter:
        //		streamFragment:    片断流
        //		strContentRange:   片断流在文件中存在的位置
        //		strOriginFileName: 目标文件
        //		strError:          out 参数,return error info
        // return:
        //		-1  出错
        //		>=  实际复制的总尺寸
        public static long RestoreFragment(
            Stream streamFragment,
            string strContentRange,
            string strOriginFileName,
            out string strErrorInfo)
        {
            long lTotalBytes = 0;

            strErrorInfo = "";

            if (streamFragment.Length == 0)
            {
                return(0);
            }

            // 表示范围的字符串为空,恰恰表示要包含全部范围
            if (strContentRange == "")
            {
                strContentRange = "0-" + Convert.ToString(streamFragment.Length - 1);
            }

            // 创建RangeList,便于理解范围字符串
            RangeList rl = new RangeList(strContentRange);

            FileStream fileOrigin = File.Open(
                strOriginFileName,
                FileMode.OpenOrCreate,                 // 原来是Open,后来修改为OpenOrCreate。这样对临时文件被系统管理员手动意外删除(但是xml文件中仍然记载了任务)的情况能够适应。否则会抛出FileNotFoundException异常
                FileAccess.Write,
                FileShare.ReadWrite);


            // 循环,复制每个连续片断
            for (int i = 0; i < rl.Count; i++)
            {
                RangeItem ri = (RangeItem)rl[i];

                fileOrigin.Seek(ri.lStart, SeekOrigin.Begin);
                StreamUtil.DumpStream(streamFragment, fileOrigin, ri.lLength);

                lTotalBytes += ri.lLength;
            }

            fileOrigin.Close();
            return(lTotalBytes);
        }
Beispiel #7
0
    void OutputLogo(string strFileName,
                    string strText)
    {
        FileInfo fi           = new FileInfo(strFileName);
        DateTime lastmodified = fi.LastWriteTimeUtc;

        this.Response.AddHeader("Last-Modified", DateTimeUtil.Rfc1123DateTimeString(lastmodified)); // .ToUniversalTime()

        TextInfo info = new TextInfo();

        info.FontFace  = "Microsoft YaHei";
        info.FontSize  = 10;
        info.colorText = Color.Gray;

        // 文字图片
        using (MemoryStream image = ArtText.PaintText(
                   strFileName,
                   strText,
                   info,
                   "center",
                   "100%",
                   "100%",
                   "65%",
                   ImageFormat.Jpeg))
        {
            this.Response.ContentType = "image/jpeg";
            this.Response.AddHeader("Content-Length", image.Length.ToString());

            //this.Response.AddHeader("Pragma", "no-cache");
            //this.Response.AddHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
            //this.Response.AddHeader("Expires", "0");

            FlushOutput flushdelegate = new FlushOutput(MyFlushOutput);
            image.Seek(0, SeekOrigin.Begin);
            StreamUtil.DumpStream(image, Response.OutputStream, flushdelegate);
        }
        // Response.Flush();
        Response.End();
    }
Beispiel #8
0
        public void LoadPhoto(string photo_path)
        {
            if (string.IsNullOrEmpty(photo_path))
            {
                App.Invoke(new Action(() =>
                {
                    this.SetPhoto(null);
                }));
                return;
            }

            // TODO: 照片可以缓存到本地。每次只需要获取 timestamp 即可。如果 timestamp 和缓存的不一致再重新获取一次

            Stream stream = null;

            try
            {
                // 先尝试从缓存获取
                string cacheDir = Path.Combine(WpfClientInfo.UserDir, "photo");
                PathUtil.CreateDirIfNeed(cacheDir);
                string fileName = Path.Combine(cacheDir, GetPath(photo_path));
                if (File.Exists(fileName))
                {
                    try
                    {
                        stream = File.OpenRead(fileName);
                    }
                    catch (Exception ex)
                    {
                        WpfClientInfo.WriteErrorLog($"从读者照片本地缓存文件 {fileName} 读取内容时出现异常:{ExceptionUtil.GetDebugText(ex)}");
                        stream = null;
                    }
                }

                if (stream == null)
                {
                    stream = new MemoryStream();
                    var      channel     = App.CurrentApp.GetChannel();
                    TimeSpan old_timeout = channel.Timeout;
                    channel.Timeout = TimeSpan.FromSeconds(30);
                    try
                    {
                        long lRet = channel.GetRes(
                            null,
                            photo_path,
                            stream,
                            "data,content", // strGetStyle,
                            null,           // byte [] input_timestamp,
                            out string strMetaData,
                            out byte[] baOutputTimeStamp,
                            out string strOutputPath,
                            out string strError);
                        if (lRet == -1)
                        {
                            // SetGlobalError("patron", $"获取读者照片时出错: {strError}");
                            // return;
                            throw new Exception($"获取读者照片(path='{photo_path}')时出错: {strError}");
                        }

                        // 顺便存储到本地
                        {
                            bool suceed = false;
                            stream.Seek(0, SeekOrigin.Begin);
                            try
                            {
                                using (var file = File.OpenWrite(fileName))
                                {
                                    StreamUtil.DumpStream(stream, file);
                                }

                                suceed = true;
                            }
                            catch (Exception ex)
                            {
                                WpfClientInfo.WriteErrorLog($"读者照片写入本地缓存文件 {fileName} 时出现异常:{ExceptionUtil.GetDebugText(ex)}");
                            }
                            finally
                            {
                                if (suceed == false)
                                {
                                    File.Delete(fileName);
                                }
                            }
                        }

                        stream.Seek(0, SeekOrigin.Begin);
                    }
                    finally
                    {
                        channel.Timeout = old_timeout;
                        App.CurrentApp.ReturnChannel(channel);
                    }
                }

                App.Invoke(new Action(() =>
                {
                    this.SetPhoto(stream);
                }));
                stream = null;
            }
            finally
            {
                if (stream != null)
                {
                    stream.Dispose();
                }
            }
        }
Beispiel #9
0
    //OpacApplication app = null;
    //SessionInfo sessioninfo = null;

    protected void Page_Load(object sender, EventArgs e)
    {
        if (WebUtil.PrepareEnvironment(this,
                                       ref app,
                                       ref sessioninfo) == false)
        {
            return;
        }

        string strError = "";
        int    nRet     = 0;

        string strBarcode = Request.QueryString["barcode"];

#if NO
        if (strBarcode.IndexOf("@") != -1)
        {
            if (sessioninfo.UserID == strBarcode &&
                string.IsNullOrEmpty(sessioninfo.PhotoUrl) == false)
            {
                this.Response.Redirect(this.sessioninfo.PhotoUrl, true);
                return;
            }
        }
#endif

        string strAction = Request.QueryString["action"];

        // 获得一般 QR 图像
        // getphoto.aspx?action=qri&barcode=????????&width=???&height=??? 其中 width 和 height 参数可以缺省
        // 获得读者证号 QR 图像
        // getphoto.aspx?action=pqri&barcode=????????&width=???&height=??? 其中 barcode 参数是读者证条码号。要求当前账户具有 getpatrontempid 的权限,而且读者身份只能获取自己的 tempid
        if (strAction == "qri" ||
            strAction == "pqri")
        {
            string strCharset    = Request.QueryString["charset"];
            string strWidth      = Request.QueryString["width"];
            string strHeight     = Request.QueryString["height"];
            string strDisableECI = Request.QueryString["disableECI"];

            bool bDisableECI = false;
            if (string.IsNullOrEmpty(strDisableECI) == false &&
                (strDisableECI.ToLower() == "true" ||
                 strDisableECI.ToLower() == "yes" ||
                 strDisableECI.ToLower() == "on"))
            {
                bDisableECI = true;
            }

            int nWidth = 0;

            if (string.IsNullOrEmpty(strWidth) == false)
            {
                if (Int32.TryParse(strWidth, out nWidth) == false)
                {
                    strError = "width 参数 '" + strWidth + "' 格式不合法";
                    goto ERROR1;
                }
            }
            int nHeight = 0;
            if (string.IsNullOrEmpty(strHeight) == false)
            {
                if (Int32.TryParse(strHeight, out nHeight) == false)
                {
                    strError = "height 参数 '" + strHeight + "' 格式不合法";
                    goto ERROR1;
                }
            }

            if (strAction == "qri")
            {
                nRet = app.OutputQrImage(
                    this.Page,
                    strBarcode,
                    strCharset,
                    nWidth,
                    nHeight,
                    bDisableECI,
                    false,
                    out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }
            }
            else if (strAction == "pqri")
            {
                // 读者证号二维码
                string strCode = "";
                // 获得读者证号二维码字符串
                nRet = app.GetPatronTempId(
                    // sessioninfo,
                    strBarcode,
                    out strCode,
                    out strError);
                if (nRet == -1)
                {
                    goto ERROR1;    // 把出错信息作为图像返回
                }
                nRet = app.OutputQrImage(
                    this.Page,
                    strCode,
                    strCharset,
                    nWidth,
                    nHeight,
                    bDisableECI,
                    false,
                    out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }
            }
            this.Response.End();
            return;
        }


        string strDisplayName   = Request.QueryString["displayName"];
        string strEncyptBarcode = Request.QueryString["encrypt_barcode"];

        // 2012/5/22
        // 较新的用法 userid=xxxx 或者 userid=encrypt:xxxx
        string strUserID = Request.QueryString["userid"];
        if (string.IsNullOrEmpty(strUserID) == false)
        {
            if (StringUtil.HasHead(strUserID, "encrypt:") == true)
            {
                strEncyptBarcode = strUserID.Substring("encrypt:".Length);
            }
            else
            {
                strBarcode = strUserID;
            }
        }

        string strPhotoPath = "";
        // 根据读者证条码号找到头像资源路径
        // return:
        //      -1  出错
        //      0   没有找到。包括读者记录不存在,或者读者记录里面没有头像对象
        //      1   找到
        nRet = app.GetReaderPhotoPath(
            // sessioninfo,
            strBarcode,
            strEncyptBarcode,
            strDisplayName,
            out strPhotoPath,
            out strError);
        if (nRet == -1)
        {
            goto ERROR1;
        }

        if (nRet == 0)
        {
            this.Response.Redirect(MyWebPage.GetStylePath(app, "nonephoto.png"), true);
            return;
        }

        // TODO: HEAD / if-modify-since等精细处理

        // FlushOutput flushdelegate = new FlushOutput(MyFlushOutput);

        nRet = app.DownloadObject(
            this,
            null,
            strPhotoPath,
            false,
            "",
            out strError);
        if (nRet == -1)
        {
            goto ERROR1;
        }

        Response.End();
        return;

#if NO
ERROR1:
        Response.Write(strError);
        Response.End();
        return;
#endif
ERROR1:
        {
            // 文字图片
            using (MemoryStream image = WebUtil.TextImage(
                       ImageFormat.Gif,
                       strError,
                       Color.Black,
                       Color.Yellow,
                       10,
                       300))
            {
                Page.Response.ContentType = "image/gif";
                this.Response.AddHeader("Content-Length", image.Length.ToString());

                this.Response.AddHeader("Pragma", "no-cache");
                this.Response.AddHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
                this.Response.AddHeader("Expires", "0");

                FlushOutput flushdelegate = new FlushOutput(MyFlushOutput);

                image.Seek(0, SeekOrigin.Begin);
                StreamUtil.DumpStream(image, Response.OutputStream, flushdelegate);
            }
            Response.Flush();
            Response.End();
        }
    }
Beispiel #10
0
    // return:
    //      -1  出错
    //      0   成功
    int DumpImageFile(
        string strImageFile,
        out string strError)
    {
        strError = "";

        FileInfo fi = new FileInfo(strImageFile);

        Page page = this;

        DateTime lastmodified = fi.LastWriteTimeUtc;
        string   strIfHeader  = page.Request.Headers["If-Modified-Since"];

        if (String.IsNullOrEmpty(strIfHeader) == false)
        {
            DateTime isModifiedSince = DateTimeUtil.FromRfc1123DateTimeString(strIfHeader); // .ToLocalTime();

            if (DateTimeUtil.CompareHeaderTime(isModifiedSince, lastmodified) != 0)
            {
                // 修改过
            }
            else
            {
                // 没有修改过
                page.Response.StatusCode      = 304;
                page.Response.SuppressContent = true;
                return(0);
            }
        }

        page.Response.AddHeader("Last-Modified", DateTimeUtil.Rfc1123DateTimeString(lastmodified)); // .ToUniversalTime()

        // string strContentType = API.MimeTypeFrom(ReadFirst256Bytes(strImageFile), "");
        string strContentType = PathUtil.MimeTypeFrom(strImageFile);

        page.Response.ContentType = strContentType;

        try
        {
            using (Stream stream = File.Open(strImageFile,
                                             FileMode.Open,
                                             FileAccess.ReadWrite,
                                             FileShare.ReadWrite))
            {
                page.Response.AddHeader("Content-Length", stream.Length.ToString());

                FlushOutput flushdelegate = new FlushOutput(MyFlushOutput);

                stream.Seek(0, SeekOrigin.Begin);

                StreamUtil.DumpStream(stream, page.Response.OutputStream,
                                      flushdelegate);
            }
        }
        catch (Exception ex)
        {
            page.Response.ContentType       = "text/plain";
            page.Response.StatusCode        = 503;
            page.Response.StatusDescription = ex.Message;
            return(-1);
        }

        return(0);
    }
Beispiel #11
0
    void GetReportFile(string strUrl, string strFormat)
    {
        string strError = "";

        if (string.IsNullOrEmpty(app.ReportDir) == true)
        {
            strError = "dp2OPAC 尚未配置报表目录";
            goto ERROR1;
        }

        {
            // 检查路径的第一级
            string strFirstLevel = GetFirstLevel(strUrl);

            // 观察当前用户是否具有管辖这个分馆的权限
            if (
                string.IsNullOrEmpty(strFirstLevel) == false &&
                // sessioninfo.Channel != null &&
                (
                    sessioninfo.GlobalUser == true ||
                    StringUtil.IsInList(strFirstLevel, sessioninfo.LibraryCodeList) == true)
                )
            {
            }
            else
            {
                strError = "当前用户不具备查看分馆 '" + strFirstLevel + "' 的报表的权限";
                goto ERROR1;
            }
        }

#if NO
        string strLibraryCode = this.TitleBarControl1.SelectedLibraryCode;
        strLibraryCode = GetDisplayLibraryCode(strLibraryCode);

        string strReportDir = Path.Combine(app.ReportDir, strLibraryCode);
#endif
        string strReportDir = app.ReportDir;

        string strFileName = Path.Combine(strReportDir, CutLinkHead(strUrl));

        if (strFormat == "excel" ||
            strFormat == "xslx" ||
            strFormat == ".xslx")
        {
            strFileName = Path.Combine(Path.GetDirectoryName(strFileName),
                                       Path.GetFileNameWithoutExtension(strFileName) + ".xlsx");
        }

        string strOriginFileName = "";
        string strRequestExt     = "";

        // 探测文件是否存在
        // patameters:
        //      strRequestFileName  请求的文件名
        //      strOriginFileName   返回 原始文件名
        //      strRequestExt       返回 请求的文件扩展名 例如 .html
        // return:
        //      -1  出错
        //      1   成功
        int nRet = DetectFileName(strFileName,
                                  out strOriginFileName,
                                  out strRequestExt,
                                  out strError);
        if (nRet == -1)
        {
            this.Response.Write(GetErrorString(strError));
            this.Response.End();
            return;
        }

        // 不让浏览器缓存页面
        this.Response.AddHeader("Pragma", "no-cache");
        this.Response.AddHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
        this.Response.AddHeader("Expires", "0");

        string strMime = "";
        // string strExt = Path.GetExtension(strFileName);
        if (string.Compare(strRequestExt, ".rml", true) == 0)
        {
            strMime = "text/xml";
        }
        else
        {
            PathUtil.GetWindowsMimeType(strRequestExt, out strMime);
        }

        if (string.IsNullOrEmpty(strMime) == true)
        {
            this.Response.ContentType = "text/html";
        }
        else
        {
            this.Response.ContentType = strMime;
        }

        this.Response.AddHeader("Content-Disposition", "inline;filename=" + HttpUtility.UrlEncode(Path.GetFileName(strFileName)));

        string strTempFileName = "";

        if (strFileName != strOriginFileName)
        {
            string strTempDir = Path.Combine(app.DataDir, "temp");
            PathUtil.TryCreateDir(strTempDir);
            strTempFileName = Path.Combine(strTempDir, "~temp_" + Guid.NewGuid().ToString());
            string strCssTemplate = @"BODY {
	FONT-FAMILY: Microsoft YaHei, Verdana, 宋体;
	FONT-SIZE: 10pt;
}

DIV.tabletitle
{
	font-size: 14pt;
	font-weight: bold;
	text-align: center;
	margin: 16pt;

	color: #444444;
}

DIV.titlecomment
{
	text-align: center;
	color: #777777;
}

DIV.createtime
{
	text-align: center;
	color: #777777;

	padding: 4pt;
}

TABLE.table
{
        font-size: 10pt;
        /*width: 100%;*/
	margin: auto;
	border-color: #efefef;
	border-width: 16px; 
	border-style: solid;
	border-collapse:collapse;
	background-color: #eeeeee;
}

TABLE.table TR
{

	border-color: #999999;
	border-width: 0px; 
	border-bottom-width: 1px;
	border-style: solid;
} 

TABLE.table THEAD TH 
{
	font-weight: bold;
	white-space:nowrap;
}

TABLE.table TD, TABLE.table TH 
{
	padding: 4pt;
	padding-left: 10pt;
	padding-right: 10pt;
	text-align: left;

}

%columns%

DIV.createtime
{
	text-align: center;
	font-size: 0.8em;
}";

            if (string.Compare(strRequestExt, ".html", true) == 0)
            {
                nRet = DigitalPlatform.dp2.Statis.Report.RmlToHtml(strOriginFileName,
                                                                   strTempFileName,
                                                                   strCssTemplate,
                                                                   out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }
            }
            else if (string.Compare(strRequestExt, ".xlsx", true) == 0)
            {
                nRet = DigitalPlatform.dp2.Statis.Report.RmlToExcel(strOriginFileName,
                                                                    strTempFileName,
                                                                    out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }
            }

            strFileName = strTempFileName;
        }

        try
        {
            using (Stream stream = File.Open(strFileName,
                                             FileMode.Open,
                                             FileAccess.ReadWrite,
                                             FileShare.ReadWrite))
            {
                this.Response.AddHeader("Content-Length", stream.Length.ToString());

                FlushOutput flushdelegate = new FlushOutput(MyFlushOutput);

                stream.Seek(0, SeekOrigin.Begin);

                StreamUtil.DumpStream(stream, this.Response.OutputStream,
                                      flushdelegate);
            }
        }
        catch (System.Web.HttpException)
        {
            // 2016/1/14
            // 因为 Client 端切断通讯
        }
        finally
        {
            if (string.IsNullOrEmpty(strTempFileName) == false)
            {
                File.Delete(strTempFileName);
            }
        }

        this.Response.OutputStream.Flush();
        this.Response.End();
        return;

ERROR1:
        this.Response.Write(GetErrorString(strError));
        this.Response.End();
    }
Beispiel #12
0
    // ajax请求发送给服务器一个图像文件,要求暂存到Session中,供后面的sendtext请求使用
    // chat.aspx?action=sendimage
    void DoSendImage()
    {
        string strError = "";
        int    nRet     = 0;

        if (this.Request.Files.Count == 0)
        {
            strError = "请求中没有包含图像文件";
            goto ERROR1;
        }

        try
        {
            DeleteTempFile();

            HttpPostedFile file = this.Request.Files[0];

            string strContentType = file.ContentType;
            string strImage       = StringUtil.GetFirstPartPath(ref strContentType);
            if (strImage != "image")
            {
                strError = "只允许上传图像文件";
                goto ERROR1;
            }

            sessioninfo.PostedFileInfo          = new PostedFileInfo();
            sessioninfo.PostedFileInfo.FileName = PathUtil.MergePath(sessioninfo.GetTempDir(), "postedfile" + Path.GetExtension(file.FileName));
            //file.SaveAs(sessioninfo.PostedFileInfo.FileName + ".tmp");

            //bool bWrited = false;
            using (Stream target = File.Create(sessioninfo.PostedFileInfo.FileName))
            {
                // 缩小尺寸
                nRet = GraphicsUtil.ShrinkPic(file.InputStream,
                                              file.ContentType,
                                              app.ChatRooms.PicMaxWidth,
                                              app.ChatRooms.PicMaxHeight,
                                              true,
                                              target,
                                              out strError);
                if (nRet == -1)
                {
                    goto ERROR1;
                }
                if (nRet == 0)  // 没有必要缩放
                {
                    if (file.InputStream.CanSeek == true)
                    {
                        file.InputStream.Seek(0, SeekOrigin.Begin); // 2012/5/20
                    }
                    StreamUtil.DumpStream(file.InputStream, target);
                    // bWrited = false;
                }
            }

            /*
             * if (bWrited == false)
             *  File.Copy(sessioninfo.PostedFileInfo.FileName + ".tmp",
             *      sessioninfo.PostedFileInfo.FileName,
             *      true);
             * */
        }
        catch (Exception ex)
        {
            strError = "ShrinkPic error -" + ex.Message;
            goto ERROR1;
        }

        this.Response.Write("{\"result\":\"OK\"}");
        this.Response.End();
        return;

ERROR1:
        // app.WriteErrorLog("DoSendImage() error :" + strError);

        this.Response.Charset = "utf-8";
        // this.Response.StatusCode = 500;
        // this.Response.StatusDescription = strError;
        SendImageResultInfo result_info = new SendImageResultInfo();

        result_info.error = strError;
        this.Response.Write(GetResultString(result_info));
        this.Response.End();
    }
Beispiel #13
0
        /*
         *      public static int DaBagFileAdded(string strXmlText,
         *          ArrayList aFileName,
         *          Stream target,
         *          out string strInfo)
         *      {
         *          strInfo = "";
         *
         *          XmlDocument dom = new XmlDocument ();
         *          try
         *          {
         *              dom.LoadXml(strXmlText);
         *          }
         *          catch(Exception ex )
         *          {
         *              strInfo += "不合法的XML\r\n"+ex.Message ;
         *              return -1;
         *          }
         *
         *          XmlNodeList listFile = dom.SelectNodes("//file");
         *
         *
         *          //得到最大的文件号
         *          int nMaxFileNo = 0;
         *          foreach(XmlNode node in listFile)
         *          {
         *              string strFileNo = DomUtil.GetNodeText (node);
         *              int nPosition = strFileNo.IndexOf (".");
         *              if (nPosition > 0)
         *              {
         *                  int nTempNo = Convert.ToInt32 (strFileNo.Substring (0,nPosition));
         *                  if (nTempNo > nMaxFileNo)
         *                      nMaxFileNo = nTempNo;
         *              }
         *          }
         *
         *          //加大一号
         *          nMaxFileNo ++;
         *
         *          //拼出每个文件的ID,并保存到xml里
         *          ArrayList aFileID = new ArrayList ();
         *          for(int i=0;i<aFileName.Count ;i++)
         *          {
         *              string strFileName = (string)aFileName[i];
         *              string strExtention = Path.GetExtension (strFileName);
         *              string strFileID = Convert.ToString (nMaxFileNo++)+strExtention;
         *              //先给xml里设好
         *              XmlNode nodeFile = listFile[i];
         *              DomUtil.SetNodeText (nodeFile,strFileID);
         *              //加到aFileID数组里,在打包时用到
         *              aFileID.Add (strFileID);
         *          }
         *
         *          long lTotalLength = 0;  //内容总长度,不包括开头的8个字节
         *          //长度字节数组
         *          byte[] bufferLength = new byte[8];
         *
         *          //记住写总长度的位置
         *          long lPositon = target.Position ;
         *
         *          //1.开头空出8字节,最后写总长度*****************
         *          target.Write(bufferLength,0,8);
         *
         *          //2.写XMl文件*******************
         *          MemoryStream ms = new MemoryStream ();
         *          dom.Save (ms);
         *
         *          //将字符串转换成字符数组
         *          //byte[] bufferXmlText = System.Text.Encoding.UTF8.GetBytes(strXmlText);
         *
         *          //算出XML文件的字节数
         *          long lXmlLength = ms.Length  ;//(long)bufferXmlText.Length;
         *          bufferLength =	System.BitConverter.GetBytes(lXmlLength);
         *
         *          target.Write(bufferLength,0,8);
         *          lTotalLength += 8;
         *
         *          //target.Write (bufferXmlText,0,lXmlLength);
         *          ms.Seek (0,SeekOrigin.Begin );
         *          StreamUtil.DumpStream (ms,target);
         *          lTotalLength += lXmlLength ;
         *
         *          //3.写文件
         *          long lFileLengthTotal = 0;  //全部文件的长度,也可以继续用lTotalLength,但新申请一个变量出问题的情况更小
         *          for(int i=0;i<aFileName.Count ;i++)
         *          {
         *              FileStream streamFile = File.Open ((string)aFileName[i],FileMode.Open);
         *              WriteFile(streamFile,
         *                  (string)aFileID[i],
         *                  target,
         *                  ref lFileLengthTotal);
         *              streamFile.Close ();
         *          }
         *          lTotalLength += lFileLengthTotal;
         *
         *          //4.写总长度
         *          bufferLength = System.BitConverter.GetBytes(lTotalLength);
         *          target.Seek (lPositon,SeekOrigin.Begin);
         *          target.Write (bufferLength,0,8);
         *
         *          //将指针移到最后
         *          target.Seek (0,SeekOrigin.End);
         *          return 0;
         *      }
         */



        //将一条记录及包含的多个资源文件打包
        //应保证外部把target的位置定好
        //0:成功
        //-1:出错
        public static int DaBag(string strXmlText,
                                ArrayList aFileItem,
                                Stream target,
                                out string strInfo)
        {
            strInfo = "";

            XmlDocument dom = new XmlDocument();

            try
            {
                dom.LoadXml(strXmlText);
            }
            catch (Exception ex)
            {
                strInfo += "不合法的XML\r\n" + ex.Message;
                return(-1);
            }

            long lTotalLength = 0;  //内容总长度,不包括开头的8个字节

            //长度字节数组
            byte[] bufferLength = new byte[8];

            //记住写总长度的位置
            long lPositon = target.Position;

            //1.开头空出8字节,最后写总长度*****************
            target.Write(bufferLength, 0, 8);

            //2.写XMl文件*******************
            using (MemoryStream ms = new MemoryStream())
            {
                dom.Save(ms);

                //将字符串转换成字符数组
                //byte[] bufferXmlText = System.Text.Encoding.UTF8.GetBytes(strXmlText);

                //算出XML文件的字节数
                long lXmlLength = ms.Length;//(long)bufferXmlText.Length;
                bufferLength = System.BitConverter.GetBytes(lXmlLength);

                target.Write(bufferLength, 0, 8);
                lTotalLength += 8;

                //target.Write (bufferXmlText,0,lXmlLength);
                ms.Seek(0, SeekOrigin.Begin);
                StreamUtil.DumpStream(ms, target);
                lTotalLength += lXmlLength;
            }

            //3.写文件
            long lFileLengthTotal = 0;  //全部文件的长度,也可以继续用lTotalLength,但新申请一个变量出问题的情况更小

            FileItem fileItem = null;

            for (int i = 0; i < aFileItem.Count; i++)
            {
                fileItem = (FileItem)aFileItem[i];
                //MessageBox.Show (fileItem.strClientPath + " --- " + fileItem.strItemPath + " --- " + fileItem.strFileNo  );

                using (FileStream streamFile = File.Open(fileItem.strClientPath, FileMode.Open))
                {
                    WriteFile(streamFile,
                              fileItem.strFileNo,
                              target,
                              ref lFileLengthTotal);
                }
            }

            lTotalLength += lFileLengthTotal;

            //4.写总长度
            bufferLength = System.BitConverter.GetBytes(lTotalLength);
            target.Seek(lPositon, SeekOrigin.Begin);
            target.Write(bufferLength, 0, 8);

            //将指针移到最后
            target.Seek(0, SeekOrigin.End);
            return(0);
        }
Beispiel #14
0
        // 新增模板
        int NewTemplate(string strName,
                        Stream stream,
                        out string strError)
        {
            strError = "";

            if (String.IsNullOrEmpty(strName) == true)
            {
                strError = "模板名不能为空";
                return(-1);
            }

            // 查重
            ListViewItem dup = ListViewUtil.FindItem(this.listView_templates, strName, 0);

            if (dup != null)
            {
                strError = "模板名 '" + strName + "' 在列表中已经存在,不能重复加入";
                return(-1);
            }

            string strFilePath = "";
            int    nRedoCount  = 0;
            string strDir      = PathUtil.MergePath(this.DataDir, // 老用法
                                                    "print_templates");

            PathUtil.TryCreateDir(strDir);  // 确保目录存在
            // 找到一个可用的文件名
            for (int i = 0; ; i++)
            {
                strFilePath = PathUtil.MergePath(strDir, "template_" + (i + 1).ToString());
                if (File.Exists(strFilePath) == false)
                {
                    try
                    {
                        // File.Create(strFilePath).Close();
                        using (Stream target = File.Create(strFilePath))
                        {
                            stream.Seek(0, SeekOrigin.Begin);
                            StreamUtil.DumpStream(stream, target);
                        }
                    }
                    catch (Exception /* ex*/)
                    {
                        if (nRedoCount > 10)
                        {
                            strError = "创建文件 '" + strFilePath + "' 失败...";
                            return(-1);
                        }
                        nRedoCount++;
                        continue;
                    }
                    break;
                }
            }

            // 清除原来已有的选择
            this.listView_templates.SelectedItems.Clear();

            ListViewItem item = new ListViewItem();

            item.Text = strName;
            item.SubItems.Add(strFilePath);
            this.listView_templates.Items.Add(item);
            item.Selected            = true; // 选上新增的事项
            this.m_bTempaltesChanged = true;

            item.EnsureVisible();   // 滚入视野

            this.m_newCreateTemplateFiles.Add(strFilePath);
            return(0);
        }