public override void action() { if (relpath == "") { throw new Exception("classActionType_clientPull.action():relpath cannot be \"\""); } /*** * split it into chunks and copy file to server */ try { int bytesRead; int bufferSize = 4096; byte[] buffer = new byte[bufferSize]; string filePath = myFolder.localFolder + relpath; using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read)) { int i = 0; while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0) { string postFileName = Path.GetFileName(filePath) + "." + i++.ToString().PadLeft(10, '0'); if (bytesRead < bufferSize) { postFileName = Path.GetFileName(filePath) + ".terminus"; } HTTPPoster mypost = new HTTPPoster(); mypost.add(buffer); mypost.setBytes(bytesRead); mypost.setDomain(this.myDomain); mypost.uploadedName(postFileName); queue.Enqueue(mypost); Debug.WriteLine(" nof: HTTPPoster.action() loop counter " + i + ""); } } do { HTTPPoster Post = (HTTPPoster)queue.Dequeue(); Post.Run(); } while (queue.Count != 0); } catch (Exception ex) { Debug.WriteLine(" nof: HTTPPoster.action() failed\r\n" + ex.Message + "\r\n" + ex.StackTrace); } }
public override void action() { if (relpath == "") { throw new Exception("classActionType_clientPull.action():relpath cannot be \"\""); } /*** * split it into chunks and copy file to server */ try { using (FileStream fileStream = File.OpenRead(myFolder.localFolder + relpath)) { MemoryStream ms = new MemoryStream(); ms.SetLength(fileStream.Length); fileStream.Read(ms.GetBuffer(), 0, (int)fileStream.Length); int i = 0; while (ms.Length > 0) { var b = new byte[4096]; ms.Read(b, 0, 4096); //now b contains your chunk, just transmit it! Debug.WriteLine(" nof: HTTPPoster.action() loop counter " + i + "\r\n" + System.Text.Encoding.UTF8.GetString(b)); string filename; HTTPPoster mypost = new HTTPPoster(); mypost.add(b); if (ms.Length == 0) { //need comparison here - to know when last loop is happening to use different name filename = relpath.Substring(relpath.LastIndexOf("\\")) + ".terminus"; } else { filename = relpath.Substring(relpath.LastIndexOf("\\")) + "." + i.ToString().PadLeft(11, '0'); } mypost.setdomain(myDomain); mypost.uploadedName(filename); queue.Enqueue(mypost); i++; //V//////////THIS//BIT//BREAKS////// if ((ms.Position + 4096) > ms.Length) { ms.Seek((ms.Position + (ms.Length - ms.Position), SeekOrigin.Current); } else { ms.Seek(ms.Position + 4096, SeekOrigin.Current); } //^//////////ONCE/IT/HITS/LAST/LOOP////// } } do { HTTPPoster Post = (HTTPPoster)queue.Dequeue(); Post.Run(); } while (queue.Count != 0); } catch (Exception ex) { Debug.WriteLine(" nof: HTTPPoster.action() failed\r\n" + ex.Message + "\r\n" + ex.StackTrace); } }