public void EnqueueObjects(string containerName, List <SwiftObjectModel> objects, string path) { if (objects != null && objects.Count > 0) { for (var i = 0; i < objects.Count; i++) { var obj = objects[i]; var objectName = obj.Object + ""; var filePath = Path.Combine(path, PathEscaper.Escape(objectName)); var skipFile = File.Exists(filePath) && File.OpenRead(filePath).Length == obj.Bytes; if (skipFile) { continue; } downloadBag.Add(new DownloadObject { Object = obj, Container = containerName, FilePath = filePath }); } } }
public void PutObjects() { var dirs = Directory.GetDirectories(rootPath); foreach (var dir in dirs) { var files = Directory.GetFiles(dir); foreach (var file in files) { uploadBag.Add(new UploadObject { Container = new DirectoryInfo(dir).Name, Object = PathEscaper.Unescape(Path.GetFileName(file)), Path = file }); } } if (uploadBag.Any()) { Console.Write("Importing... "); var objCount = uploadBag.Count; var progress = new ProgressBar(); Parallel.For(0, objCount - 1, new ParallelOptions { MaxDegreeOfParallelism = 10 }, i => { var uploadObj = uploadBag.ElementAt(i); try { var response = ImportObject(uploadObj).Result; Interlocked.Increment(ref counter); if (!response.IsSuccess) { ManageFailed(new FailedObject { Container = uploadObj.Container, Message = response.Message, Object = uploadObj }); } } catch (Exception ex) { ManageFailed(new FailedObject { Container = uploadObj.Container, Message = ex.Message, Object = uploadObj }); } progress.Report((double)counter / objCount); }); progress.Report(1); progress.Dispose(); Console.WriteLine(" Done."); } }