📄 powupload.cs
字号:
namespace ElementIT.PowUpload
{
using System;
using System.Collections.Specialized;
using System.Web;
public class PowUpload
{
private string _id;
private ProcessProgress _uploadProgress;
public PowUpload()
{
this._id = null;
this._uploadProgress = null;
if (UploadModule.colProcessProgress == null)
{
throw new Exception("PowUpload module not found! You may be forgot to add the <httpModules> section in the Web.config file.");
}
this._id = System.Web.HttpContext.Current.GetHashCode().ToString() + System.Web.HttpContext.Current.Timestamp.Ticks.ToString();
this.RefreshProcess(true);
UploadModule.AddDebugInfo("PowUpload with id=" + this._id + " created.");
}
public PowUpload(string id)
{
this._id = null;
this._uploadProgress = null;
if ((id == null) || (id == ""))
{
throw new ArgumentException("The id parameter cannot be empty.");
}
if (UploadModule.colProcessProgress == null)
{
throw new Exception("PowUpload module not found! You may be forgot to add the <httpModules> section in the Web.config file.");
}
this._id = id;
this.RefreshProcess(true);
UploadModule.AddDebugInfo("PowUpload with id=" + this._id + " created.");
}
public void CancelUpload(bool closeConnection)
{
this.CancelUpload(closeConnection, false);
}
public void CancelUpload(bool closeConnection, bool deleteFiles)
{
if ((this._uploadProgress != null) && (this._uploadProgress._ProcessUpload != null))
{
this._uploadProgress._ProcessUpload.CancelUpload(closeConnection, deleteFiles);
}
}
public void Dispose()
{
if (this._uploadProgress != null)
{
UploadModule.AddDebugInfo("PowUpload.Dispose() id=" + this.id + " . Stack trace for current level: " + Environment.StackTrace);
try
{
this._uploadProgress._Files.Dispose();
}
catch
{
}
}
}
private void RefreshProcess(bool absoluteReset)
{
if ((absoluteReset || (!absoluteReset && (this._uploadProgress == null))) && (this._id != null))
{
if (UploadModule.colProcessProgress[this._id] != null)
{
this._uploadProgress = (ProcessProgress) UploadModule.colProcessProgress[this._id];
}
else
{
this._uploadProgress = null;
}
}
}
public long BandwidthLimit
{
get
{
if (this._uploadProgress == null)
{
return (long) (-1);
}
return this._uploadProgress._bwc.SpeedLimit;
}
set
{
if ((this._uploadProgress != null) && (this._uploadProgress._bwc != null))
{
this._uploadProgress._bwc.SpeedLimit = value;
}
}
}
public double BytesPerSecondAverage
{
get
{
if ((this._uploadProgress != null) && (this._uploadProgress._SecondsDone != 0))
{
return (((double) this._uploadProgress._UploadedBytes) / this._uploadProgress._SecondsDone);
}
return 0;
}
}
public double BytesPerSecondCurrent
{
get
{
if ((this._uploadProgress != null) && (this._uploadProgress._TimeSinseLastTime.TotalMilliseconds > 0))
{
return ((((double) this._uploadProgress._ReadSinseLastTime) / this._uploadProgress._TimeSinseLastTime.TotalMilliseconds) * 1000);
}
return 0;
}
}
public string CurrentFileName
{
get
{
if (this._uploadProgress == null)
{
return "";
}
return this._uploadProgress._CurrentFileName;
}
}
public long CurrentFileUploadedBytes
{
get
{
if (this._uploadProgress == null)
{
return (long) 0;
}
return this._uploadProgress._CurrentFileUploadedBytes;
}
}
public object CustomData
{
get
{
if (this._uploadProgress == null)
{
return null;
}
return this._uploadProgress._CustomData;
}
set
{
if (this._uploadProgress != null)
{
this._uploadProgress._CustomData = value;
}
}
}
public UploadedFileCollection Files
{
get
{
if (this._uploadProgress == null)
{
return null;
}
return this._uploadProgress._Files;
}
}
public NameValueCollection FormFields
{
get
{
if (this._uploadProgress == null)
{
return null;
}
return this._uploadProgress._FormFields;
}
}
public System.Web.HttpContext HttpContext
{
get
{
if (this._uploadProgress == null)
{
return null;
}
return this._uploadProgress._HttpContext;
}
}
public System.Web.HttpWorkerRequest HttpWorkerRequest
{
get
{
if (this._uploadProgress == null)
{
return null;
}
return this._uploadProgress._WorkerRequest;
}
}
public string id
{
get
{
return this._id;
}
set
{
if ((value == null) || (value == ""))
{
throw new ArgumentException("The value cannot be empty");
}
this._id = value;
this.RefreshProcess(true);
}
}
public Exception LastError
{
get
{
if (this._uploadProgress == null)
{
return null;
}
return this._uploadProgress._lastError;
}
}
public double PercentDone
{
get
{
if ((this._uploadProgress != null) && (this._uploadProgress._TotalBytes != 0))
{
return ((this._uploadProgress._UploadedBytes * 100) / ((double) this._uploadProgress._TotalBytes));
}
return 0;
}
}
public double SecondsDone
{
get
{
if (this._uploadProgress == null)
{
return 0;
}
return this._uploadProgress._SecondsDone;
}
}
public double SecondsLeftAverage
{
get
{
if ((this._uploadProgress != null) && (this.BytesPerSecondAverage != 0))
{
return ((this._uploadProgress._TotalBytes - this._uploadProgress._UploadedBytes) / this.BytesPerSecondAverage);
}
return 0;
}
}
public double SecondsLeftCurrent
{
get
{
if ((this._uploadProgress != null) && (this.BytesPerSecondCurrent != 0))
{
return ((this._uploadProgress._TotalBytes - this._uploadProgress._UploadedBytes) / this.BytesPerSecondCurrent);
}
return 0;
}
}
public long TotalBytes
{
get
{
if (this._uploadProgress == null)
{
return (long) 0;
}
return this._uploadProgress._TotalBytes;
}
}
public bool UploadComplete
{
get
{
if (this._uploadProgress == null)
{
return false;
}
return this._uploadProgress._UploadComplete;
}
}
public long UploadedBytes
{
get
{
if (this._uploadProgress == null)
{
return (long) 0;
}
return this._uploadProgress._UploadedBytes;
}
}
public int UploadedFilesCount
{
get
{
if (this._uploadProgress == null)
{
return 0;
}
return this._uploadProgress._UploadedFilesCount;
}
}
public UploadState UploadStatus
{
get
{
if (this._uploadProgress == null)
{
return UploadState.Waiting;
}
return this._uploadProgress._Status;
}
}
public string UploadStatusString
{
get
{
if (this._uploadProgress != null)
{
switch (this._uploadProgress._Status)
{
case UploadState.Waiting:
return "Waiting for upload";
case UploadState.Uploading:
return "Uploading files";
case UploadState.Complete:
return "Upload completed";
case UploadState.Error:
return "An error was occured";
case UploadState.Cancelled:
return "Upload canceled";
case UploadState.Rejected:
return "Upload rejected";
case UploadState.ConnectionClosed:
return "Connection closed";
}
}
return "Waiting for upload";
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -