コード例 #1
0
ファイル: UploadFile.aspx.cs プロジェクト: sebbalex/PITre
        public static object GetUploadStatus()
        {
            object       retval = null;
            UploadDetail info   = HttpContext.Current.Session["UploadDetail"] as UploadDetail;

            if (info != null && info.IsReady)
            {
                int    soFar           = info.UploadedLength;
                int    total           = info.ContentLength;
                int    percentComplete = (int)Math.Ceiling((double)soFar / (double)total * 100);
                string message         = Utils.Languages.GetLabelFromCode("FileUploadSending", UIManager.UserManager.GetUserLanguage());
                string fileName        = string.Format("{0}", info.FileName);
                string downloadBytes   = string.Format(Utils.Languages.GetLabelFromCode("FileUploadStartDownloadBytes2", UIManager.UserManager.GetUserLanguage()), soFar / 1024, total / 1024);

                return(new
                {
                    percentComplete = percentComplete,
                    message = message,
                    fileName = fileName,
                    downloadBytes = downloadBytes
                });
            }

            return(retval);
        }
コード例 #2
0
        public void TestCreateAndPopulate()
        {
            UploadContext context = new UploadContext();

            UploadHeader header = new UploadHeader();

            header.Begin = DateTime.Now;

            context.UploadHeaders.Add(header);

            DateTime       dt      = DateTime.Now;
            int            minutes = 0;
            IList <String> tables  = new List <String>()
            {
                "IN_GUEST", "IN_TRN", "IN_MSG", "IN_RES"
            };

            foreach (String table in tables.OrderBy(s => s))
            {
                minutes++;
                UploadDetail dtl = new UploadDetail()
                {
                    TableName = table, Begin = dt.AddMinutes(minutes++), End = dt.AddMinutes(minutes++), UploadHeader = header
                };
                context.UploadDetails.Add(dtl);
            }
            context.SaveChanges();
            TestContext.WriteLine("Done - {0}", minutes);
        }
コード例 #3
0
ファイル: UploadFile.aspx.cs プロジェクト: sebbalex/PITre
 private void InitSessionObject()
 {
     Session["UploadDetail"] = new UploadDetail {
         IsReady = false
     };
     Session["fileDoc"] = new NttDataWA.DocsPaWR.FileDocumento();
 }
コード例 #4
0
        // GET: Download/Delete/5
        public ActionResult Delete(int id)
        {
            UploadDetail   detail = uploadDetailLogic.GetUploadDetailById(id);
            User           user   = userLogic.GetUserById(detail.UserId);
            DownloadModels model  = new DownloadModels(detail.UploadId, detail.UserId, user.Username,
                                                       detail.StartTimeUpload.ToString(), detail.FileName, Convert.ToInt32(detail.FileSize));

            return(View(model));
        }
コード例 #5
0
 public void HandleTableProcessorBegin(object sender, TableProcessorBeginEventArgs args)
 {
     Detail = new UploadDetail()
     {
         TableName = args.TableName, ClassName = args.ClassName, Begin = DateTime.Now, UploadHeader = Header
     };
     Context.UploadDetails.Add(Detail);
     Context.SaveChanges();
 }
コード例 #6
0
 public UploadItem(UploadDetail uploadDetail, UploadInfoComps comps)
 {
     this.uploadDetail           = uploadDetail;
     this.uploadingItemContainer = uploadDetail.getUploadingItemContainer();
     this.comps = comps;
     InitializeComponent();
     init();
     addItems(comps.vo);
     this.uploadingItemContainer.Controls.Add(this);
 }
コード例 #7
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack)
            {
                UploadDetail Upload = (UploadDetail)this.Session["UploadDetail"];
                //Let the webservie know that we are not yet ready
                Upload.IsReady = false;
                if (this.fileUpload.PostedFile != null && this.fileUpload.PostedFile.ContentLength > 0)
                {
                    //build the local path where upload all the files
                    string path     = this.Server.MapPath(@"Uploads");
                    string fileName = Path.GetFileName(this.fileUpload.PostedFile.FileName);

                    //Build the strucutre and stuff it into session
                    Upload.ContentLength  = this.fileUpload.PostedFile.ContentLength;
                    Upload.FileName       = fileName;
                    Upload.UploadedLength = 0;
                    //Let the polling process know that we are done initializing ...
                    Upload.IsReady = true;

                    //set the buffer size to something larger.
                    //the smaller the buffer the longer it will take to download,
                    //but the more precise your progress bar will be.
                    int    bufferSize = 1;
                    byte[] buffer     = new byte[bufferSize];

                    //Writing the byte to disk
                    using (FileStream fs = new FileStream(Path.Combine(path, fileName), FileMode.Create))
                    {
                        //Aslong was we haven't written everything ...
                        while (Upload.UploadedLength < Upload.ContentLength)
                        {
                            //Fill the buffer from the input stream
                            int bytes = this.fileUpload.PostedFile.InputStream.Read(buffer, 0, bufferSize);
                            //Writing the bytes to the file stream
                            fs.Write(buffer, 0, bytes);
                            //Update the number the webservice is polling on to the session
                            Upload.UploadedLength += bytes;
                        }
                    }
                    //Call parent page know we have processed the uplaod
                    const string js = "window.parent.onComplete(1,'File uploaded successfully.','{0}','{1} of {2} Bytes');";
                    ScriptManager.RegisterStartupScript(this, typeof(FileUploadEngine), "progress", string.Format(js, fileName, Upload.UploadedLength, Upload.ContentLength), true);
                }
                else
                {
                    //Call parent page know we have processed the uplaod
                    const string js = "window.parent.onComplete(4, 'There was a problem with the file.','','0 of 0 Bytes');";
                    ScriptManager.RegisterStartupScript(this, typeof(FileUploadEngine), "progress", js, true);
                }
                //Let webservie know that we are not yet ready
                Upload.IsReady = false;
            }
        }
コード例 #8
0
 public UploadItem(UploadDetail uploadDetail, UploadInfoComps comps, UploadHelper uploadHelper, FloatWin floatWin)
 {
     this.uploadDetail           = uploadDetail;
     this.uploadingItemContainer = uploadDetail.getUploadingItemContainer();
     this.comps        = comps;
     this.floatWin     = floatWin;
     this.uploadHelper = uploadHelper;
     InitializeComponent();
     init();
     addItems(comps.vo);
     this.uploadingItemContainer.Controls.Add(this);
 }
コード例 #9
0
        public UploadedItem(UploadDetail uploadDetail, UploadItemVO obj)
        {
            this.uploadDetail          = uploadDetail;
            this.uploadedItemContainer = uploadDetail.getUploadedItemContainer();
            InitializeComponent();

            comps    = new UploadInfoComps();
            comps.vo = obj;
            init();
            addItems(obj);
            this.uploadedItemContainer.Controls.Add(this);
        }
コード例 #10
0
ファイル: Default.aspx.cs プロジェクト: wyx9413/WebYunPrint
    private List <file> getFilesList(string sourcePath)
    {
        List <file>  fileList      = new List <file>();
        UploadDetail upDetail      = Session["UploadDetail"] as UploadDetail;
        DataTable    OrdreTypeList = Session["OrdreTypeList"] as DataTable;

        if ((Directory.Exists(sourcePath)))
        {
            DirectoryInfo dir = new DirectoryInfo(sourcePath);
            foreach (FileInfo files in dir.GetFiles("*.*"))
            {
                string str        = files.Name;
                string orderUmber = str.Substring(0, str.IndexOf(" "));

                if (orderUmber == upDetail.OrderUmber.ToString())     //根据订单号找对应文件
                {
                    file theFile = new file();
                    theFile.orderID        = upDetail.OrderUmber;
                    theFile.fileName       = files.Name;
                    theFile.filepath       = sourcePath;
                    theFile.printTypeTable = OrdreTypeList;
                    theFile.onePagePrice   = float.Parse(OrdreTypeList.Rows[0]["SinglePagePrice"].ToString()); //默认黑白打印的价格
                    theFile.count          = 1;                                                                //默认打印一份
                    //(str.Substring(0, str.LastIndexOf("."))
                    //  string db = str.Trim();
                    string suffixName = str.Substring(str.LastIndexOf(".") + 1);
                    if (suffixName == "doc" || suffixName == "docx")

                    {
                        string path = sourcePath + @"\" + files.Name;

                        theFile.numberOfPages = GetPageCount(path);     // 加这个方法时报错
                        theFile.price         = (theFile.numberOfPages) * (theFile.onePagePrice) * (theFile.count);
                        fileList.Add(theFile);
                    }
                    else if (suffixName == "pdf")
                    {
                        string path = sourcePath + @"\" + files.Name;
                        theFile.numberOfPages = GetPDFPageCountByDll(path);
                        theFile.price         = (theFile.numberOfPages) * (theFile.onePagePrice) * (theFile.count);
                        fileList.Add(theFile);
                    }
                }
            }

            return(fileList);
        }
        else
        {
            return(null);
        }
    }
コード例 #11
0
        public static UploadDetail Test()
        {
            UploadDetail info = (UploadDetail)HttpContext.Current.Session["UploadDetail"];

            if (info != null && info.IsReady)
            {
                return(info);
            }
            else
            {
                return(null);
            }
        }
コード例 #12
0
    public static object GetUploadStatus()
    {
        UploadDetail info = (UploadDetail)HttpContext.Current.Session["UploadDetail"];

        if (info != null && info.IsReady)
        {
            int soFar           = info.UploadedLength;
            int total           = info.ContentLength;
            int percentComplete = (int)Math.Ceiling((double)soFar / (double)total * 100);
            return(new
            {
                percentComplete = percentComplete,
            });
        }
        return(null);
    }
コード例 #13
0
        public static UploadStatus GetUploadStatus()
        {
            //Get the length of the file on disk and divide that by the length of the stream
            UploadDetail info = (UploadDetail)HttpContext.Current.Session["UploadDetail"];

            if (info != null && info.IsReady)
            {
                int    soFar           = info.UploadedLength;
                int    total           = info.ContentLength;
                int    percentComplete = (int)Math.Ceiling((double)soFar / (double)total * 100);
                string message         = "Uploading...";
                string fileName        = string.Format("{0}", info.FileName);
                string downloadBytes   = string.Format("{0} of {1} Bytes", soFar, total);
                return(new UploadStatus(percentComplete, message, fileName, downloadBytes));
            }
            //Not ready yet
            return(null);
        }
コード例 #14
0
ファイル: Default.aspx.cs プロジェクト: wyx9413/WebYunPrint
    protected void UpLoadBut_OnClick(object sender, EventArgs e)
    {
        EnOrder      order    = new EnOrder();
        UploadDetail upDetail = Session["UploadDetail"] as UploadDetail;

        order.orderNumber    = upDetail.OrderUmber.ToString();
        order.orderStatusID  = 1;
        order.placeOrderTime = DateTime.Now;
        int   CTCount = NewfilesInfo.Controls.Count;
        Label toPrice = (Label)NewfilesInfo.Controls[CTCount - 1].FindControl("totalPrice");

        order.toalPrice = decimal.Parse(toPrice.Text);
        order.docs      = new List <EnDoc>();
        for (int i = 0; i < NewfilesInfo.Items.Count; i++)
        {
            Label        fn  = (Label)NewfilesInfo.Items[i].FindControl("fileName");
            Label        ph  = (Label)NewfilesInfo.Items[i].FindControl("filepath");
            DropDownList pt  = (DropDownList)NewfilesInfo.Items[i].FindControl("PrintTypes");
            Label        pc  = (Label)NewfilesInfo.Items[i].FindControl("PageCount");
            TextBox      num = (TextBox)NewfilesInfo.Items[i].FindControl("CopiesTextBox");


            order.docs.Add(new EnDoc
            {
                orderNumber = order.orderNumber,
                docName     = fn.Text,
                docPath     = ph.Text,
                printTypeID = long.Parse(pt.SelectedItem.Value.Trim()),
                totalPages  = int.Parse(pc.Text.Trim()) * int.Parse(num.Text.Trim())
            });
        }
        CnOrders  cn = new CnOrders();
        DataTable dt = cn.getOrderTabel(order);
        int       k  = DataBase.update("Orders", "OrderNumber", dt);

        Session["OrderInfo"] = new EnOrder();

        Session["OrderInfo"] = order;
        Session.Remove("UploadDetail");
        Session.Remove("OrdreTypeList");

        Response.Redirect("Order.aspx");
    }
コード例 #15
0
 private void Upload_Click(object sender, EventArgs e)
 {
     if (SiteMaster.VerifyRequest(HttpContext.Current.Session))
     {
         try
         {
             User user = Session[SKeys.User] as User;
             if (fileUpload.HasFile)
             {
                 if (fileUpload.PostedFile.ContentLength >= MaxFileSize)
                 {
                     Session[SKeys.UploadResponse] = ApiResponse.JSONError(ResponseType.ErrorUploadFileTooLarge);
                     return;
                 }
                 if (!(SiteFileSystem.IsExtensionAllowed(fileUpload.FileName) && SiteFileSystem.IsContentTypeAllowed(fileUpload.PostedFile.ContentType)))
                 {
                     Session[SKeys.UploadResponse] = ApiResponse.JSONError(ResponseType.ErrorUploadFileFormatNotSupported);
                     return;
                 }
                 string token = Crypt.EncryptStreamToTempFile(user, fileUpload.FileContent);
                 if (string.IsNullOrWhiteSpace(token))
                 {
                     Session[SKeys.UploadResponse] = ApiResponse.JSONError(ResponseType.ErrorUploadUnknown);
                     return;
                 }
                 else
                 {
                     UploadDetail detail = new UploadDetail()
                     {
                         Extension = Path.GetExtension(fileUpload.FileName), Token = token
                     };
                     Session[SKeys.UploadResponse] = ApiResponse.JSONSuccess(detail);
                 }
             }
         }
         catch
         {
             Session[SKeys.UploadResponse] = ApiResponse.JSONError(ResponseType.ErrorUploadUnknown);
         }
     }
 }
コード例 #16
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (this.IsPostBack)
        {
            UploadDetail upload = (UploadDetail)this.Session["UploadDetail"];
            const string js     = "window.parent.onComplete();";
            upload.IsReady = false;

            if (this.fileUpload.PostedFile != null && this.fileUpload.PostedFile.ContentLength > 0 && upload.DestinationPath != null)
            {
                string path     = upload.DestinationPath.ToString();
                string fileName = Path.GetFileName(this.fileUpload.PostedFile.FileName);

                upload.ContentLength  = this.fileUpload.PostedFile.ContentLength;
                upload.FileName       = fileName;
                upload.UploadedLength = 0;
                upload.IsReady        = true;

                int    bufferSize = 1;
                byte[] buffer     = new byte[bufferSize];

                using (FileStream fs = new FileStream(Path.Combine(path, fileName), FileMode.Create))
                {
                    while (upload.UploadedLength < upload.ContentLength)
                    {
                        int bytes = this.fileUpload.PostedFile.InputStream.Read(buffer, 0, bufferSize);
                        fs.Write(buffer, 0, bytes);
                        upload.UploadedLength += bytes;
                    }
                }
                ScriptManager.RegisterStartupScript(this, typeof(UploadControl), "progress", js, true);
            }
            else
            {
                ScriptManager.RegisterStartupScript(this, typeof(UploadControl), "progress", js, true);
            }
            upload.IsReady = false;
        }
    }
コード例 #17
0
        public List <UploadDetail> UploadDetailList()
        {
            List <UploadDetail> uploads = new List <UploadDetail>();

            try
            {
                using (SqlConnection connection = Database.GetConnectionString())
                {
                    connection.Open();
                    SqlCommand addUploadDetails = new SqlCommand("SELECT * FROM [UploadDetail]", connection);
                    addUploadDetails.ExecuteNonQuery();
                    using (SqlDataReader reader = addUploadDetails.ExecuteReader())
                    {
                        DataTable dataTable = new DataTable();
                        dataTable.Load(reader);
                        foreach (DataRow dataRow in dataTable.Rows)
                        {
                            UploadDetail detail = new UploadDetail(
                                Convert.ToInt32((dataRow["UploadId"] != DBNull.Value) ? dataRow["UploadId"] : 0),
                                Convert.ToInt32((dataRow["UserId"] != DBNull.Value) ? dataRow["Userid"] : 0),
                                Convert.ToDateTime((dataRow["StartTimeUpload"] != DBNull.Value)
                                    ? dataRow["StartTimeUpload"]
                                    : DateTime.Now),
                                (dataRow["FileName"].ToString() != "") ? dataRow["FileName"].ToString() : "-",
                                (dataRow["FileSize"].ToString() != "") ? dataRow["FileSize"].ToString() : "-");
                            uploads.Add(detail);
                        }
                    }
                }

                return(uploads);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                throw;
            }
        }
コード例 #18
0
        public UploadDetail GetUploadDetailById(int id)
        {
            try
            {
                using (SqlConnection connection = Database.GetConnectionString())
                {
                    connection.Open();
                    SqlCommand addUploadDetailById = new SqlCommand("SELECT * FROM [UploadDetail] WHERE (UploadId) = (@UploadId)", connection);
                    addUploadDetailById.Parameters.AddWithValue("UploadId", id);
                    addUploadDetailById.ExecuteNonQuery();
                    using (SqlDataReader reader = addUploadDetailById.ExecuteReader())
                    {
                        DataTable dataTable = new DataTable();
                        dataTable.Load(reader);
                        foreach (DataRow dataRow in dataTable.Rows)
                        {
                            UploadDetail detail = new UploadDetail(
                                Convert.ToInt32((dataRow["UploadId"] != DBNull.Value) ? dataRow["UploadId"] : 0),
                                Convert.ToInt32((dataRow["UserId"] != DBNull.Value) ? dataRow["Userid"] : 0),
                                Convert.ToDateTime((dataRow["StartTimeUpload"] != DBNull.Value)
                                    ? dataRow["StartTimeUpload"]
                                    : DateTime.Now),
                                (dataRow["FileName"].ToString() != "") ? dataRow["FileName"].ToString() : "-",
                                (dataRow["FileSize"].ToString() != "") ? dataRow["FileSize"].ToString() : "-");
                            return(detail);
                        }
                    }
                }

                return(null);
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception);
                throw;
            }
        }
コード例 #19
0
 public void UploadDetails(UploadDetail detail)
 {
     try
     {
         using (SqlConnection connection = Database.GetConnectionString())
         {
             connection.Open();
             SqlCommand addUploadDetails = new SqlCommand(
                 "INSERT INTO [UploadDetail] (UploadId, StartTimeUpload, Filename, Filesize, UserId) VALUES (@UploadId, @StartTimeUpload, @Filename, @Filesize, @UserId)",
                 connection);
             addUploadDetails.Parameters.AddWithValue("UploadId", detail.UploadId);
             addUploadDetails.Parameters.AddWithValue("StartTimeUpload", detail.StartTimeUpload);
             addUploadDetails.Parameters.AddWithValue("Filename", detail.FileName);
             addUploadDetails.Parameters.AddWithValue("Filesize", detail.FileSize);
             addUploadDetails.Parameters.AddWithValue("UserId", 1);
             addUploadDetails.ExecuteNonQuery();
         }
     }
     catch (Exception exception)
     {
         Console.WriteLine(exception);
         throw;
     }
 }
コード例 #20
0
 public void UploadDetails(UploadDetail detail, string path)
 {
     _Repo.UploadDetails(GetUploadDetails(path));
 }
コード例 #21
0
 public void UploadDetails(UploadDetail detail)
 {
     uploadDetailContext.UploadDetails(detail);
 }
コード例 #22
0
        protected void Page_Load(object sender, EventArgs e)
        {
            try {
                if (this.IsPostBack)
                {
                    UploadDetail Upload = Session["UploadDetail"] as UploadDetail;
                    //NttDataWA.DocsPaWR.FileDocumento fileDoc = Session["fileDoc"] as NttDataWA.DocsPaWR.FileDocumento;
                    NttDataWA.DocsPaWR.FileDocumento fileDoc = new NttDataWA.DocsPaWR.FileDocumento();
                    if (Upload != null && fileDoc != null)
                    {
                        Upload.IsReady = false;

                        //using (StreamWriter log = File.AppendText(HttpContext.Current.Server.MapPath("../UserFiles/debug.log")))
                        //{
                        //    log.WriteLine(DateTime.Now.ToString() + ": PostedFile is null=" + (this.fileUpload.PostedFile==null).ToString());
                        //}

                        if (this.fileUpload.PostedFile != null && this.fileUpload.PostedFile.ContentLength > 0 && this.fileUpload.PostedFile.ContentLength <= this.FileAcquisitionSizeMax)
                        {
                            string path     = this.Server.MapPath(@"Uploads");
                            string fileName = Path.GetFileName(this.fileUpload.PostedFile.FileName);
                            string exten    = Path.GetExtension(Path.Combine(path, fileName));

                            Upload.ContentLength  = this.fileUpload.PostedFile.ContentLength;
                            Upload.FileName       = fileName;
                            Upload.UploadedLength = 0;

                            Upload.IsReady = true;

                            //using (StreamWriter log = File.AppendText(HttpContext.Current.Server.MapPath("../UserFiles/debug.log")))
                            //{
                            //    log.WriteLine(DateTime.Now.ToString() + ": Upload.FileName=" + Upload.FileName + ", Upload.ContentLength=" + Upload.ContentLength);
                            //}

                            fileDoc.name        = fileName;// System.IO.Path.GetFileName(file.FileName);
                            fileDoc.fullName    = Path.Combine(path, fileName);
                            fileDoc.contentType = NttDataWA.UIManager.FileManager.GetMimeType(fileName);
                            fileDoc.length      = this.fileUpload.PostedFile.ContentLength;// ContentLength;// .FileSize;
                            fileDoc.content     = new Byte[fileDoc.length];

                            int    bufferSize = 1;
                            byte[] buffer     = new byte[bufferSize];

                            while (Upload.UploadedLength < Upload.ContentLength)
                            {
                                //Fill the buffer from the input stream
                                int bytes = this.fileUpload.PostedFile.InputStream.Read(buffer, 0, bufferSize);
                                fileDoc.content.SetValue(buffer[0], Upload.UploadedLength);

                                Upload.UploadedLength  += bytes;
                                Session["UploadDetail"] = Upload;
                            }

                            Upload.UploadedLength   = fileDoc.length;
                            Session["UploadDetail"] = Upload;
                            Session["fileDoc"]      = fileDoc;

                            const string js = "window.parent.endProgress('{0}','{1}', '{2}');";
                            ScriptManager.RegisterStartupScript(this, this.GetType(), "progress", string.Format(js, fileName.Replace("'", " "), Upload.UploadedLength, Upload.ContentLength), true);
                        }
                        else
                        {
                            string msg = "ErrorFileUpload";
                            if (this.fileUpload.PostedFile.ContentLength > this.FileAcquisitionSizeMax)
                            {
                                msg = "ErrorFileUploadMaxSizeExceeded";
                            }

                            ScriptManager.RegisterStartupScript(this, this.GetType(), "ajaxDialogModal", "if (parent.parent.fra_main) {parent.parent.fra_main.ajaxDialogModal('" + utils.FormatJs(msg) + "', 'error', '');} else {parent.parent.ajaxDialogModal('" + utils.FormatJs(msg) + "', 'error', '');}; parent.reallowOp();", true);
                        }

                        Upload.IsReady = false;
                    }
                }
            }
            catch (System.Exception ex)
            {
                UIManager.AdministrationManager.DiagnosticError(ex);
                return;
            }
        }
コード例 #23
0
        public static string CheckUpload(string version, string data)
        {
            if (SiteMaster.VerifyRequest(HttpContext.Current.Session))
            {
                var user    = HttpContext.Current.Session[SKeys.User] as User;
                var session = HttpContext.Current.Session;
                if (session[SKeys.UploadResponse] == null)
                {
                    // No upload response.
                    return(ApiResponse.JSONSuccess());
                }
                var respStr = session[SKeys.UploadResponse] as string;
                if (string.IsNullOrWhiteSpace(respStr))
                {
                    // Key set, but no content.
                    return(ApiResponse.JSONSuccess());
                }
                session.Remove(SKeys.UploadResponse);

                ApiResponse response = JsonConvert.DeserializeObject <ApiResponse>(respStr);
                if (!response.success)
                {
                    // Error happened, so return that.
                    return(respStr);
                }

                // Get upload data.
                UploadDetail up = ((JObject)response.data).ToObject <UploadDetail>();
                if (up == null || string.IsNullOrWhiteSpace(up.Extension) || string.IsNullOrWhiteSpace(up.Token) || !SiteFileSystem.IsExtensionAllowed(up.Extension))
                {
                    // Response data was bad for some reason.
                    return(ApiResponse.JSONSuccess());
                }
                // Check upload data.
                if (Crypt.IsTokenGood(up.Token))
                {
                    string outFile = Path.Combine(SiteFileSystem.GetTempFileDirectory(), Path.GetRandomFileName());
                    string ecFile  = Path.Combine(SiteFileSystem.GetTempFileDirectory(), up.Token.Substring(32));
                    if (Crypt.DecryptTempFileToFile(user, outFile, up.Token))
                    {
                        // Remove old file.
                        File.Delete(ecFile);
                        // Then do verification.
                        ResponseType resp = POAcknowledgeManager.VerifyFile(user, outFile);
                        if (resp == ResponseType.SuccessAPO || resp == ResponseType.WarningAPOUnverifiedAccept)
                        {
                            // Good response, move the file
                            var isTest = (HttpContext.Current.Session[SKeys.IsTest] as bool?) == true;
                            try
                            {
                                var uploadFilePath = SiteFileSystem.GetUploadFileName(user, isTest, "855", up.Extension);
                                File.Move(outFile, uploadFilePath);
                                ProcessQueue.CreateUploadRecord(user, DateTime.Now, "855", Path.GetFileName(uploadFilePath));
                            }
                            catch
                            {
                                return(ApiResponse.JSONError(ResponseType.ErrorAPOUnknown));
                            }
                            if (resp == ResponseType.SuccessAPO)
                            {
                                return(ApiResponse.JSONSuccess(ResponseDescription.Get(resp)));
                            }
                            else
                            {
                                return(ApiResponse.JSONWarning(ResponseDescription.Get(resp)));
                            }
                        }
                        else
                        {
                            // Fail response, delete the file.
                            File.Delete(outFile);
                            return(ApiResponse.JSONError(resp));
                        }
                    }
                    else
                    {
                        return(ApiResponse.JSONError(ResponseType.ErrorAPOUnknown));
                    }
                }
                else
                {
                    // Bad token.
                    return(ApiResponse.JSONError(ResponseType.ErrorAPOUnknown));
                }
            }
            else
            {
                return(ApiResponse.JSONError(ResponseType.ErrorAuth));
            }
        }
コード例 #24
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (this.IsPostBack)
            {
                UploadDetail Upload = (UploadDetail)this.Session["UploadDetail"];
                //Let the webservie know that we are not yet ready
                Upload.IsReady = false;
                if (this.fileUpload.PostedFile != null && this.fileUpload.PostedFile.ContentLength > 0)
                {
                    //START : Saving File in Database
                    SaveFile saveFileInDB = new SaveFile();
                    saveFileInDB.FileName      = this.fileUpload.PostedFile.FileName;
                    saveFileInDB.FileExtension = Path.GetExtension(this.fileUpload.PostedFile.FileName);
                    saveFileInDB.FileContent   = this.fileUpload.FileBytes;
                    Result Result = saveFileInDB.SaveFileInDB();
                    if (Result.IsError == false)
                    {
                        //File Save in Database Successfully!
                    }
                    else
                    {
                        //Error in Saving File in Database!
                        //Error: Result.ErrorMessage
                        //InnerException: Result.InnerException
                        //StackTrace: Result.StackTrace
                    }
                    //END : Saving File in Database



                    //build the local path where upload all the files
                    //  string path = this.Server.MapPath(@"打堆云打印\12月 2015年\28日");
                    string filepath = this.Server.MapPath("打堆云打印\\" + DateTime.Today.ToString(@"MM月 yyyy年\\dd日"));
                    if (!Directory.Exists(filepath))
                    {
                        Directory.CreateDirectory(filepath);
                    }
                    //string path = @"F:\打堆云打印\12月 2015年\28日";
                    string fileName = Upload.OrderUmber.ToString() + " " + Path.GetFileName(this.fileUpload.PostedFile.FileName);

                    //Build the strucutre and stuff it into session
                    Upload.ContentLength  = this.fileUpload.PostedFile.ContentLength;
                    Upload.FileName       = fileName;
                    Upload.UploadedLength = 0;
                    //Let the polling process know that we are done initializing ...
                    Upload.IsReady = true;


                    //set the buffer size to something larger.
                    //the smaller the buffer the longer it will take to download,
                    //but the more precise your progress bar will be.
                    int    bufferSize = 1;
                    byte[] buffer     = new byte[bufferSize];

                    //Writing the byte to disk
                    using (FileStream fs = new FileStream(Path.Combine(filepath, fileName), FileMode.Create))
                    {
                        //Aslong was we haven't written everything ...
                        while (Upload.UploadedLength < Upload.ContentLength)
                        {
                            //Fill the buffer from the input stream
                            int bytes = this.fileUpload.PostedFile.InputStream.Read(buffer, 0, bufferSize);
                            //Writing the bytes to the file stream
                            fs.Write(buffer, 0, bytes);
                            //Update the number the webservice is polling on to the session
                            Upload.UploadedLength += bytes;
                        }
                    }
                    //Call parent page know we have processed the uplaod
                    const string js = "window.parent.onComplete(1,'文件上传成功.','{0}','{1} of {2} Bytes');";
                    ScriptManager.RegisterStartupScript(this, typeof(UploadEngine), "progress", string.Format(js, fileName, Upload.UploadedLength, Upload.ContentLength), true);
                }
                else
                {
                    //Call parent page know we have processed the uplaod
                    const string js = "window.parent.onComplete(4, 'There was a problem with the file.','','0 of 0 Bytes');";
                    ScriptManager.RegisterStartupScript(this, typeof(UploadEngine), "progress", js, true);
                }
                //Let webservie know that we are not yet ready
                Upload.IsReady = false;
            }
        }
コード例 #25
0
        protected override string Upload(HttpPostedFile file, string fileName)
        {
            string       result = String.Empty;
            MemoryStream _ms    = null;

            try
            {
                string path = this._context.Server.MapPath(@"Uploads");
                NttDataWA.DocsPaWR.FileDocumento fileDoc = new NttDataWA.DocsPaWR.FileDocumento();
                fileDoc.name        = fileName;
                fileDoc.fullName    = Path.Combine(path, fileName);
                fileDoc.contentType = NttDataWA.UIManager.FileManager.GetMimeType(fileName);
                fileDoc.length      = file.ContentLength;

                byte[] buffer = new byte[16 * 1024];
                _ms = new MemoryStream();

                int read;
                while ((read = file.InputStream.Read(buffer, 0, buffer.Length)) > 0)
                {
                    _ms.Write(buffer, 0, read);
                }
                fileDoc.content = _ms.ToArray();

                System.Web.HttpContext.Current.Session["fileDoc"] = fileDoc;

                SchedaDocumento doc = DocumentManager.getSelectedRecord();
                if (doc != null && String.IsNullOrWhiteSpace(doc.docNumber))
                {
                    UploadDetail Upload = new UploadDetail {
                        IsReady = false
                    };
                    HttpContext.Current.Session["UploadDetail"] = Upload;
                    Upload.FileName = fileName;

                    Upload.IsReady = true;

                    Upload.UploadedLength = fileDoc.length;
                    System.Web.HttpContext.Current.Session["UploadDetail"] = Upload;
                }

                bool _pdf   = "1".Equals((string)System.Web.HttpContext.Current.Session["UploadMassivoConversionePDF"]);
                bool _paper = "1".Equals((string)System.Web.HttpContext.Current.Session["UploadMassivoCartaceo"]);
                bool _pdfConversionSynchronousLC = false;
                if (HttpContext.Current.Session["PdfConversionSynchronousLC"] != null)
                {
                    _pdfConversionSynchronousLC = (bool)HttpContext.Current.Session["PdfConversionSynchronousLC"];
                }

                result = FileManager.uploadFile(null, fileDoc, _paper, _pdf, _pdfConversionSynchronousLC);


                //SchedaDocumento _schedaDocumento = DocumentManager.getSelectedRecord();
                //FileManager.uploadFileFromSchedaDocumento(null, file, _schedaDocumento);
            }
            catch (Exception ex)
            {
                result = ex.Message;
                _logger.Error(ex.Message, ex);
            }
            return(result);
        }
コード例 #26
0
    protected void dvDestination_TextChanged(object sender, EventArgs e)
    {
        UploadDetail info = (UploadDetail)HttpContext.Current.Session["UploadDetail"];

        info.DestinationPath = dvDestination != null ? dvDestination.Text: "";
    }