Exemplo n.º 1
0
        private void NextFile()
        {
            if (_currFileId >= 0)
            {
                _uploadStream.Dispose();
            }

            _currFileId++;
            if (_currFileId >= _files.Count)
            {
                return;
            }

            _bytesWrote = 0;
            var currFile = _files[_currFileId];

            _uploadStream = new UploadStream(currFile.FullPath, _cloud, currFile.OriginalSize)
            {
                CheckHashes = _checkHash
            };
        }
Exemplo n.º 2
0
        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);
            if (!disposing)
            {
                return;
            }

            _uploadStream?.Dispose();

            if (_performAsSplitted)
            {
                var header = new HeaderFileContent
                {
                    CreationDate = DateTime.Now,
                    Name         = _origfile.Name,
                    Size         = _origfile.Size,
                    PublicKey    = _cryptInfo?.PublicKey
                };
                _cloud.UploadFileJson(_origfile.FullPath, header, true);
            }

            OnFileUploaded(_files);
        }
Exemplo n.º 3
0
 internal void SendOutTo(Stream stream)
 {
     try
     {
         BinaryWriter binaryWriter = new BinaryWriter(stream);
         string       text         = $"{MethodNames[(uint)MethodType]} {((!HasProxy || !Proxy.SendWholeUri) ? CurrentUri.PathAndQuery : CurrentUri.OriginalString)} HTTP/1.1";
         if (HTTPManager.Logger.Level <= Loglevels.Information)
         {
             HTTPManager.Logger.Information("HTTPRequest", $"Sending request: {text}");
         }
         binaryWriter.Write(text.GetASCIIBytes());
         binaryWriter.Write(EOL);
         SendHeaders(binaryWriter);
         binaryWriter.Write(EOL);
         binaryWriter.Flush();
         byte[] array = RawData;
         if (array == null && FormImpl != null)
         {
             array = FormImpl.GetData();
         }
         if (array != null || UploadStream != null)
         {
             Stream stream2 = UploadStream;
             if (stream2 == null)
             {
                 stream2      = new MemoryStream(array, 0, array.Length);
                 UploadLength = array.Length;
             }
             else
             {
                 UploadLength = ((!UseUploadStreamLength) ? (-1) : UploadStreamLength);
             }
             Uploaded = 0L;
             byte[] array2 = new byte[UploadChunkSize];
             int    num    = 0;
             while ((num = stream2.Read(array2, 0, array2.Length)) > 0)
             {
                 if (!UseUploadStreamLength)
                 {
                     binaryWriter.Write(num.ToString("X").GetASCIIBytes());
                     binaryWriter.Write(EOL);
                 }
                 binaryWriter.Write(array2, 0, num);
                 if (!UseUploadStreamLength)
                 {
                     binaryWriter.Write(EOL);
                 }
                 binaryWriter.Flush();
                 Uploaded += num;
                 UploadProgressChanged = true;
             }
             if (!UseUploadStreamLength)
             {
                 binaryWriter.Write("0".GetASCIIBytes());
                 binaryWriter.Write(EOL);
                 binaryWriter.Write(EOL);
             }
             binaryWriter.Flush();
             if (UploadStream == null)
             {
                 stream2?.Dispose();
             }
         }
     }
     catch (Exception ex)
     {
         HTTPManager.Logger.Exception("HTTPRequest", "SendOutTo", ex);
         throw ex;
         IL_0232 :;
     }
     finally
     {
         if (UploadStream != null && DisposeUploadStream)
         {
             UploadStream.Dispose();
         }
     }
 }
Exemplo n.º 4
0
        internal bool SendOutTo(Stream stream)
        {
            bool success = false;

            try
            {
                var outStream = new BinaryWriter(stream);

                outStream.Write(string.Format("{0} {1} HTTP/1.1",
                                              MethodType.ToString().ToUpper(),  // Method names are always uppercase.
                                              HasProxy && Proxy.SendWholeUri ? CurrentUri.OriginalString : CurrentUri.PathAndQuery
                                              ).GetASCIIBytes());
                outStream.Write(EOL);

                SendHeaders(outStream);
                outStream.Write(EOL);

                // Send headers to the wire
                outStream.Flush();

                byte[] data = RawData;

                // We are sending forms? Then convert the form to a byte array
                if (data == null && FormImpl != null)
                {
                    data = FormImpl.GetData();
                }

                if (data != null || UploadStream != null)
                {
                    // Make a new reference, as we will check the UploadStream property in the HTTPManager
                    Stream uploadStream = UploadStream;

                    if (uploadStream == null)
                    {
                        // Make stream from the data
                        uploadStream = new MemoryStream(data, 0, data.Length);

                        // Initialise progress report variable
                        UploadLength = data.Length;
                    }
                    else
                    {
                        UploadLength = UseUploadStreamLength ? UploadStreamLength : -1;
                    }

                    // Initialise the progress report variables
                    Uploaded = 0;

                    // Upload buffer. Frist we will read the data into this buffer from the UploadStream, then write this buffer to our outStream
                    byte[] buffer = new byte[UploadChunkSize];

                    // How many bytes was read from the UploadStream
                    int count = 0;
                    while ((count = uploadStream.Read(buffer, 0, buffer.Length)) > 0)
                    {
                        // If we don't know the size, send as chunked
                        if (!UseUploadStreamLength)
                        {
                            outStream.Write(count.ToString("X").GetASCIIBytes());
                            outStream.Write(EOL);
                        }

                        // write out the buffer to the wire
                        outStream.Write(buffer, 0, count);

                        // chunk trailing EOL
                        if (!UseUploadStreamLength)
                        {
                            outStream.Write(EOL);
                        }

                        // Make sure that the system sends the buffer
                        outStream.Flush();

                        // update how many bytes are uploaded
                        Uploaded += count;

                        // let the callback fire
                        UploadProgressChanged = true;
                    }

                    // All data from the stream are sent, write the 'end' chunk if necessary
                    if (!UseUploadStreamLength)
                    {
                        outStream.Write("0".GetASCIIBytes());
                        outStream.Write(EOL);
                        outStream.Write(EOL);
                    }

                    // Make sure all remaining data will be on the wire
                    outStream.Flush();

                    // Dispose the MemoryStream
                    if (UploadStream == null && uploadStream != null)
                    {
                        uploadStream.Dispose();
                    }
                }

                // The request sent out successfully
                success = true;
            }
            catch (Exception ex)
            {
                HTTPManager.Logger.Exception("HTTPRequest", "SendOutTo", ex);
            }
            finally
            {
                if (UploadStream != null && DisposeUploadStream)
                {
                    UploadStream.Dispose();
                }
            }

            return(success);
        }