Esempio n. 1
0
        public void Insert()
        {
            UploadFileHistory history = new UploadFileHistory();

            history.Operator         = null;
            history.OriginalFileName = UuidHelper.NewUuidString() + ".txt";

            history.ApplicationName = "App";
            history.ProgramName     = "Prog";
            history.StatusText      = "一切正常";
            history.Status          = UploadFileHistoryStatus.Success;
            history.Operator        = (IUser)OguObjectSettings.GetConfig().Objects["requestor"].Object;

            using (Stream stream = PrepareFileStream(history.OriginalFileName, history.OriginalFileName))
            {
                UploadFileHistoryAdapter.Instance.Insert(history, stream);
            }

            using (Stream stream = history.GetMaterialContentStream())
            {
                using (StreamReader sr = new StreamReader(history.GetMaterialContentStream()))
                {
                    string content = sr.ReadToEnd();

                    Assert.AreEqual(history.OriginalFileName, content);
                }
            }
        }
        public void Insert()
        {
            UploadFileHistory history = new UploadFileHistory();

            history.Operator = null;
            history.OriginalFileName = UuidHelper.NewUuidString() + ".txt";

            history.ApplicationName = "App";
            history.ProgramName = "Prog";
            history.StatusText = "一切正常";
            history.Status = UploadFileHistoryStatus.Success;
            history.Operator = (IUser)OguObjectSettings.GetConfig().Objects["requestor"].Object;

            using (Stream stream = PrepareFileStream(history.OriginalFileName, history.OriginalFileName))
            {
                UploadFileHistoryAdapter.Instance.Insert(history, stream);
            }

            using (Stream stream = history.GetMaterialContentStream())
            {
                using (StreamReader sr = new StreamReader(history.GetMaterialContentStream()))
                {
                    string content = sr.ReadToEnd();

                    Assert.AreEqual(history.OriginalFileName, content);
                }
            }
        }
Esempio n. 3
0
        public void ProcessRequest(HttpContext context)
        {
            HttpResponse Response = context.Response;

            try
            {
                int id;
                if (int.TryParse(context.Request.Params["id"], out id))
                {
                    UploadFileHistory uploadFilelog = UploadFileHistoryAdapter.Instance.Load(id);
                    if (uploadFilelog != null)
                    {
                        Response.Clear();
                        Response.ClearHeaders();
                        using (Stream stream = uploadFilelog.GetMaterialContentStream())
                        {
                            stream.CopyTo(Response.OutputStream);
                        }

                        Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
                        Response.AppendHeader("CONTENT-DISPOSITION",
                                              string.Format("{0};filename={1}", "inline", HttpUtility.UrlEncode(uploadFilelog.CurrentFileName)));
                    }
                }
            }
            catch (Exception ex)
            {
                Response.Write("下载出错 : " + ex.Message);
            }
            finally
            {
                Response.End();
            }
        }