fixing #6 and #3 · 58611739ae - SVN.BY: Go Git Service
Tiernan OToole 8 gadi atpakaļ
vecāks
revīzija
58611739ae
1 mainītis faili ar 22 papildinājumiem un 2 dzēšanām
  1. 22 2
      B2Uploader/Program.cs

+ 22 - 2
B2Uploader/Program.cs

23
 
23
 
24
         [Option('d', "directory", HelpText = "Directory you want to upload", Required = true)]
24
         [Option('d', "directory", HelpText = "Directory you want to upload", Required = true)]
25
         public string Directory { get; set; }
25
         public string Directory { get; set; }
26
+
27
+        [Option('m', "multithreads", HelpText = "Number of uploads you want to use at a time. Default is 2", Required = false)]
28
+        public int Threads { get; set; }
29
+
30
+        [Option('r', "recursive", HelpText = "Uploads the directory in Recursive mode. Any sub folders will also be uploaded", Required = false)]
31
+        public bool recursive { get; set; }
26
         
32
         
27
         [Option('v', "verbose", HelpText="Verbose Output")]
33
         [Option('v', "verbose", HelpText="Verbose Output")]
28
         public bool Verbose{get;set;}
34
         public bool Verbose{get;set;}
46
 
52
 
47
                 var bucket = buckets.buckets.First();
53
                 var bucket = buckets.buckets.First();
48
 
54
 
49
-                string[] FilesToProcess = Directory.GetFiles(options.Directory);
50
-                Parallel.ForEach(FilesToProcess, new ParallelOptions() { MaxDegreeOfParallelism = 32 }, s =>
55
+                SearchOption so = SearchOption.TopDirectoryOnly;
56
+                if (options.recursive)
57
+                {
58
+                    so = SearchOption.AllDirectories;
59
+                }
60
+
61
+                string[] FilesToProcess = Directory.GetFiles(options.Directory, "*", so);
62
+
63
+                int maxParallel = 2;
64
+
65
+                if(options.Threads > 2)
66
+                {
67
+                    maxParallel = options.Threads;
68
+                }
69
+
70
+                Parallel.ForEach(FilesToProcess, new ParallelOptions() { MaxDegreeOfParallelism = maxParallel }, s =>
51
                 {
71
                 {
52
                     //check if file already exists
72
                     //check if file already exists
53
 
73