Exemplo n.º 1
0
 public void UploadStarted(UploadStatus status)
 {
     using (IDbConnection connection = new SqlConnection(this._connectionString))
     {
         using (IDbCommand command = connection.CreateCommand())
         {
             command.CommandText = string.Concat(new string[]
             {
                 "INSERT INTO ",
                 this._tablename,
                 "(",
                 this._statusfield,
                 ",",
                 this._keyfieldname,
                 ") VALUES (@UploadStatus,@uploadId)"
             });
             IDbDataParameter parameter = command.CreateParameter();
             parameter.DbType        = DbType.String;
             parameter.ParameterName = "@uploadId";
             parameter.Value         = status.UploadId;
             command.Parameters.Add(parameter);
             IDbDataParameter parameter2 = command.CreateParameter();
             parameter2.DbType        = DbType.String;
             parameter2.ParameterName = "@UploadStatus";
             parameter2.Value         = status.GetSerializeUploadedObjects();
             command.Parameters.Add(parameter2);
             connection.Open();
             command.ExecuteNonQuery();
         }
     }
     UploadLog.Log("SqlStatus: inserted uploadId=" + status.UploadId);
 }
Exemplo n.º 2
0
 public void RemoveStatus(string uploadId)
 {
     using (IDbConnection connection = new SqlConnection(this._connectionString))
     {
         using (IDbCommand command = connection.CreateCommand())
         {
             command.CommandText = string.Concat(new string[]
             {
                 "DELETE FROM ",
                 this._tablename,
                 " WHERE ",
                 this._keyfieldname,
                 "=@uploadId"
             });
             IDbDataParameter parameter = command.CreateParameter();
             parameter.DbType        = DbType.String;
             parameter.ParameterName = "@uploadId";
             parameter.Value         = uploadId;
             command.Parameters.Add(parameter);
             connection.Open();
             command.ExecuteNonQuery();
         }
     }
     UploadLog.Log("SqlStatus: removed uploadId=" + uploadId);
 }
Exemplo n.º 3
0
 public void StatusChanged(UploadStatus status)
 {
     using (IDbConnection connection = new SqlConnection(this._connectionString))
     {
         using (IDbCommand command = connection.CreateCommand())
         {
             command.CommandText = string.Concat(new string[]
             {
                 "UPDATE ",
                 this._tablename,
                 " SET ",
                 this._statusfield,
                 "=@UploadStatus, ",
                 this._lastUpdatedField,
                 "=GETDATE() WHERE ",
                 this._keyfieldname,
                 "=@uploadId"
             });
             IDbDataParameter parameter = command.CreateParameter();
             parameter.DbType        = DbType.String;
             parameter.ParameterName = "@uploadId";
             parameter.Value         = status.UploadId;
             command.Parameters.Add(parameter);
             IDbDataParameter parameter2 = command.CreateParameter();
             parameter2.DbType        = DbType.String;
             parameter2.ParameterName = "@UploadStatus";
             parameter2.Value         = status.GetSerializeUploadedObjects();
             command.Parameters.Add(parameter2);
             connection.Open();
             command.ExecuteNonQuery();
         }
     }
     UploadLog.Log("SqlStatus: updated uploadId=" + status.UploadId);
 }
Exemplo n.º 4
0
        public void BeginPart(NameValueCollection headers)
        {
            UploadedFile file = this.GetUploadFile(headers);
            bool         flag = file != null;

            if (flag)
            {
                UploadLog.Log("Starting file part", this._uploadStatus.UploadId);
                UploadLog.Log(file, this._uploadStatus.UploadId);
                bool flag2 = HttpUploadModule.UploadFileFilter != null && !HttpUploadModule.UploadFileFilter.ShouldHandleFile(file);
                if (flag2)
                {
                    throw new UploadException(UploadTerminationReason.FileFilter);
                }
                this._outputStream = this._UploadStreamProvider.GetOutputStream(file);
                this._length       = 0L;
                this._uploadStatus.UploadedFiles.Add(file);
                this._uploadStatus.SetCurrentFileName(file.ClientName);
            }
            else
            {
                UploadLog.Log("Starting non-file part", this._uploadStatus.UploadId);
                this._textParts.Append(this.encoding.GetString(this._boundary) + "\r\n");
                for (int i = 0; i < headers.Count; i++)
                {
                    this._textParts.Append(headers.Keys[i] + ": " + headers[i] + "\r\n");
                }
                this._textParts.Append("\r\n");
            }
        }
Exemplo n.º 5
0
 public SqlClientStatusManager(NameValueConfigurationSection configuration)
 {
     this._connectionString = configuration["connectionString"];
     this._tablename        = configuration["table"];
     this._keyfieldname     = configuration["keyField"];
     this._statusfield      = configuration["statusField"];
     this._lastUpdatedField = configuration["lastUpdatedField"];
     UploadLog.Log("Using SqlClientStatusManager. Settings:");
     UploadLog.Log("connectionString: " + this._connectionString);
     UploadLog.Log("table: " + this._tablename);
     UploadLog.Log("keyField: " + this._keyfieldname);
     UploadLog.Log("statusField: " + this._statusfield);
     UploadLog.Log("lastUpdatedField: " + this._lastUpdatedField);
     UploadLog.Log("updateInterval: " + UtoUploadConfiguration.StatusManager.UpdateInterval.ToString());
 }
Exemplo n.º 6
0
        public void EndPart(bool isLast)
        {
            UploadLog.Log("Part complete", this._uploadStatus.UploadId);
            bool flag = this._outputStream != null;

            if (flag)
            {
                this._uploadStatus.UploadedFiles[this._uploadStatus.UploadedFiles.Count - 1].SetContentLength(this._length);
                this._outputStream.Dispose();
                this._outputStream = null;
            }
            else
            {
                this._textParts.Append("\r\n");
            }
            bool flag2 = isLast && this._textParts.Length > 0;

            if (flag2)
            {
                this._textParts.Append(this.encoding.GetString(this._boundary) + "--\r\n\r\n");
            }
        }
Exemplo n.º 7
0
        public UploadStatus GetUploadStatus(string uploadId)
        {
            UploadStatus result;

            using (IDbConnection connection = new SqlConnection(this._connectionString))
            {
                using (IDbCommand command = connection.CreateCommand())
                {
                    command.CommandText = string.Concat(new string[]
                    {
                        "SELECT ",
                        this._statusfield,
                        " FROM ",
                        this._tablename,
                        " WHERE ",
                        this._keyfieldname,
                        "=@uploadId"
                    });
                    IDbDataParameter parameter = command.CreateParameter();
                    parameter.DbType        = DbType.String;
                    parameter.ParameterName = "@uploadId";
                    parameter.Value         = uploadId;
                    command.Parameters.Add(parameter);
                    connection.Open();
                    string text = command.ExecuteScalar() as string;
                    UploadLog.Log("SqlStatus: returned uploadId=" + uploadId);
                    bool flag = !string.IsNullOrEmpty(text);
                    if (flag)
                    {
                        result = UploadStatus.GetUploadStatus(text);
                        return(result);
                    }
                }
            }
            result = null;
            return(result);
        }
Exemplo n.º 8
0
        private void context_BeginRequest(object sender, EventArgs e)
        {
            HttpApplication application = sender as HttpApplication;
            bool            flag        = this.IsUploadRequest(application.Request) && UtoUploadConfiguration.HandleRequests;

            if (flag)
            {
                this.ProofreadTime();
                HttpWorkerRequest worker          = this.GetWorkerRequest(application.Context);
                Encoding          contentEncoding = application.Context.Request.ContentEncoding;
                UploadLog.Log("Received upload request");
                bool flag2 = worker != null;
                if (flag2)
                {
                    long   num      = long.Parse(worker.GetKnownRequestHeader(11));
                    byte[] boundary = this.ExtractBoundary(application.Request.ContentType, contentEncoding);
                    string str      = application.Request.QueryString["UploadId"];
                    bool   flag3    = string.IsNullOrEmpty(str);
                    if (flag3)
                    {
                        str = Guid.NewGuid().ToString();
                    }
                    UploadStatus uploadStatus = HttpUploadModule.StatusManager.GetUploadStatus(str);
                    bool         flag4        = uploadStatus == null;
                    if (flag4)
                    {
                        uploadStatus = new UploadStatus(str);
                        HttpUploadModule.StatusManager.UploadStarted(uploadStatus);
                    }
                    uploadStatus.x98532580ab8a33a1(num);
                    bool flag5 = this.IsOversizedRequest(application.Request, num);
                    if (flag5)
                    {
                        UploadLog.Log("Request too big... aborting");
                        application.CompleteRequest();
                        uploadStatus.SetState(UploadState.Terminated, UploadTerminationReason.MaxRequestLengthExceeded);
                        this.RegisterIn(application.Context, uploadStatus);
                    }
                    else
                    {
                        UploadLog.Log("Starting upload", str);
                        UploadLog.Log(worker, str);
                        uploadStatus.SetState(UploadState.ReceivingData);
                        this.RegisterIn(application.Context, uploadStatus);
                        MimeUploadHandler UploadHandler = null;
                        try
                        {
                            UploadHandler = new MimeUploadHandler(new RequestStream(worker), boundary, uploadStatus, contentEncoding, HttpUploadModule.UploadStreamProvider);
                            UploadHandler.Parse();
                            byte[] bytes = contentEncoding.GetBytes(UploadHandler.TextParts);
                            bool   flag6 = worker.GetType().FullName.StartsWith("Mono.");
                            if (flag6)
                            {
                                this.InjectTextParts(application.Context.Request, bytes);
                            }
                            else
                            {
                                bool flag7 = worker.GetType().Name == "IIS7WorkerRequest";
                                if (flag7)
                                {
                                    this.InvokeMember(application.Context.Request, bytes);
                                }
                                else
                                {
                                    this.InjectTextParts(worker, bytes);
                                }
                            }
                            uploadStatus.SetState(UploadState.Complete);
                            UploadLog.Log("Upload request complete", str);
                        }
                        catch (UploadException exception)
                        {
                            UploadLog.Log("Upload canceled or disconnected", str);
                            bool flag8 = uploadStatus != null;
                            if (flag8)
                            {
                                bool flag9 = UploadHandler != null;
                                if (flag9)
                                {
                                    UploadHandler.CancelParse();
                                }
                                this.ClearUploadStatus(uploadStatus);
                            }
                            UploadStatus status2 = HttpUploadModule.StatusManager.GetUploadStatus(str);
                            bool         flag10  = status2 != null && status2.State != UploadState.Terminated;
                            if (flag10)
                            {
                                status2.SetState(UploadState.Terminated, exception.Reason, exception.Message);
                            }
                            application.CompleteRequest();
                        }
                    }
                }
            }
        }