Permalink
Browse files

transfers: transfer objects in new thread whilst chunking+encrypting

  • Loading branch information...
1 parent 462f479 commit 7a791ad07e77cd4205e80a58a664c8384c033c8e @hbons committed Jul 31, 2011
Showing with 36 additions and 14 deletions.
  1. +8 −6 Main.cs
  2. +28 −8 TransferManager.cs
View
@@ -44,20 +44,22 @@ public static void Main (string [] args)
List<string> chunk_paths = new List<string> ();
List<string> hashes = new List<string> ();
+ TransferManager transfer_manager = new TransferManager (LocalPath + "/", "/Users/hbons/rsync-test");
+
chunker.ChunkCreated += delegate (string chunk_file_path, int chunk_size, string chunk_hash) {
// Console.WriteLine ("Created: " + chunk_file_path + " (" + chunk_size + " bytes)");
chunk_paths.Add (chunk_file_path);
hashes.Add (chunk_hash);
- // Upload files
+
+
+ transfer_manager.QueueUpload ();
};
- chunker.FileToChunks ("/Users/hbons/Thunderbird.dmg");
+ chunker.FileToChunks ("/Users/hbons/hp2.avi");
- Blobs blobs = new Blobs ("Users/hbons/SparkleShare/Rainbows/.sparkleshare");
- blobs.Store ("hp.avi", hashes.ToArray ());
+ // Blobs blobs = new Blobs ("Users/hbons/SparkleShare/Rainbows/.sparkleshare");
+ //blobs.Store ("hp.avi", hashes.ToArray ());
- TransferManager transfer_manager = new TransferManager (LocalPath + "/", "/Users/hbons/rsync-test");
- transfer_manager.UploadObjects ();
s.Stop ();
Console.WriteLine ("Total time: " + (int) s.Elapsed.TotalSeconds + " seconds");
View
@@ -17,25 +17,26 @@
using System;
using System.Diagnostics;
+using System.Threading;
namespace Rainbows {
public class TransferManager {
- Process rsync_process = new Process ();
+ private bool queued_upload = false;
+ private bool busy = false;
+ private Process rsync_process = new Process ();
public TransferManager (string path, string remote_path)
{
this.rsync_process.StartInfo.FileName = "rsync";
- this.rsync_process.StartInfo.Arguments = "--ignore-existing " +
- "--recursive " +
- "--whole-file " + // Don't do delta sync
- "--progress " +
- path + " " + remote_path;
+ this.rsync_process.StartInfo.Arguments = "--ignore-existing --bwlimit=500 " +
+ "--recursive --whole-file --progress " + path + " " + remote_path;
- this.rsync_process.EnableRaisingEvents = true;
+ Console.WriteLine (this.rsync_process.StartInfo.Arguments);
+ this.rsync_process.EnableRaisingEvents = true;
this.rsync_process.StartInfo.RedirectStandardOutput = false;
this.rsync_process.StartInfo.UseShellExecute = false;
this.rsync_process.StartInfo.WorkingDirectory = path;
@@ -44,9 +45,28 @@ public TransferManager (string path, string remote_path)
public void UploadObjects ()
{
- Console.WriteLine (this.rsync_process.StartInfo.Arguments);
+ this.busy = true;
+
this.rsync_process.Start ();
this.rsync_process.WaitForExit ();
+
+ this.busy = false;
+ }
+
+
+ public void QueueUpload ()
+ {
+ if (!this.busy) {
+ Thread thread = new Thread (
+ new ThreadStart (
+ delegate {
+ UploadObjects ();
+ }
+ )
+ );
+
+ thread.Start ();
+ }
}

0 comments on commit 7a791ad

Please sign in to comment.