Пример #1
0
 /// <summary>
 /// Writes the stream to the server as chunks.
 /// </summary>
 /// <remarks>
 /// Remember to call "save" on this file after writing the bytes to the server.
 /// </remarks>
 /// <param name="stream"></param>
 /// <param name="server"></param>
 public void WriteToServer(Stream stream, bool overwrite)
 {
     this.length = stream.Length;
     var chunks = this.ParentCollection.GetChildCollection<GridFileChunk>("chunks");
     int read = 0;
     this.length = 0;
     int i = -1;
     byte[] buffer = new byte[this.chunkSize.Value];
     do
     {
         GridFileChunk chunk = new GridFileChunk();
         chunk.file_id = this._id;
         chunk.n = i;
         read = stream.Read(buffer, 0, this.chunkSize.Value);
         chunk.data = buffer;
         this.length += read;
         if (read > 0)
         {
             i++;
             chunks.Insert(chunk);
         }
     } while (read > 0);
 }
Пример #2
0
        /// <summary>
        /// Writes the stream to the server as chunks.
        /// </summary>
        /// <param name="stream">
        /// File stream
        /// </param>
        /// <param name="overwrite">
        /// if set to <c>true</c> [overwrite].
        /// </param>
        /// <remarks>
        /// Remember to call "save" on this file after writing the bytes to the server.
        /// </remarks>
        public void WriteToServer(Stream stream, bool overwrite)
        {
            length = stream.Length;
            var chunks = ParentCollection.GetChildCollection<GridFileChunk>("chunks");
            var read = 0;
            length = 0;
            var i = -1;
            var buffer = new byte[chunkSize.Value];
            do
            {
                var chunk = new GridFileChunk {file_id = _id, n = i};
                read = stream.Read(buffer, 0, chunkSize.Value);
                chunk.data = buffer;
                length += read;

                if (read <= 0)
                {
                    continue;
                }

                i++;
                chunks.Insert(chunk);
            }
            while (read > 0);
        }