Example #1
0
        public void EndPart(bool isLast, bool isComplete)
        {
            //SimpleLogger.Log("Part complete", _uploadStatus.UploadId);

            if (_currentStream != null)
            {
                UploadSession session = SlickUploadContext.SessionStorageProvider.GetSession(_request.UploadSessionId);

                if (session != null && session.State == UploadState.Uploading && (session.FailedRequests == null || Array.IndexOf <string>(session.FailedRequests, _request.UploadRequestId) == -1))
                {
                    _currentFile.ContentLength = _fileLength;

                    _request.UploadStreamProvider.CloseWriteStream(_currentFile, _currentStream, isComplete);

                    _currentStream = null;
                    _currentFile   = null;
                }
                else
                {
                    CancelParse();

                    if (session != null && session.ErrorType == UploadErrorType.Cancelled)
                    {
                        throw new UploadCancelledException();
                    }
                    else
                    {
                        throw new UploadDisconnectedException();
                    }
                }
            }
            else
            {
                _textParts.Append("\r\n");

                if (_request.Data.Count == 0)
                {
                    string data = _httpRequest.Form["kw_uploadData"];

                    if (string.IsNullOrEmpty(data))
                    {
                        data = _httpRequest.Form["X-SlickUpload-Data"];
                    }

                    if (!string.IsNullOrEmpty(data))
                    {
                        MimeHelper.ParseQueryStringToDictionary(data, _request.Data);
                    }
                }
            }

            if (isLast)
            {
                if (_textParts.Length > 0)
                {
                    // Write out the boundary end
                    _textParts.Append(_httpRequest.ContentEncoding.GetString(_boundary) + "--\r\n\r\n");
                }
            }
        }
Example #2
0
        public void ProcessRequest()
        {
            _textParts = new StringBuilder();

            PushReaderBase reader;

            if (string.Equals(_httpRequest.ContentType, "application/octet-stream", StringComparison.InvariantCultureIgnoreCase))
            {
                reader = new SingleFilePushReader(_requestStream, this);
            }
            else
            {
                reader = new MimePushReader(_requestStream, this, _boundary, _httpRequest.ContentEncoding);
            }

            // TODO: detect if ASP.NET has already read the request and throw an exception

            string data = _httpRequest.Headers["X-SlickUpload-Data"];

            if (!string.IsNullOrEmpty(data))
            {
                MimeHelper.ParseQueryStringToDictionary(data, _request.Data);
            }

            //try
            //{
            reader.Parse();

            /*}
             * catch (DisconnectedException)
             * {
             *  if (_currentStream != null)
             *      _currentStream.Close();
             *
             *  throw;
             * }*/

            _httpRequest.InjectTextParts(_textParts.ToString());
        }