public XDocument PostToUsenet(FileSystemInfo toPost, String title, String rarPassword, Boolean saveNzb = true) { using (nntpMessagePoster poster = new nntpMessagePoster(configuration, folderConfiguration)) { poster.PartPosted += poster_PartPosted; DirectoryInfo processedFiles = null; try { DateTime StartTime = DateTime.Now; processedFiles = MakeProcessingFolder(toPost.NameWithoutExtension()); MakeRarAndParFiles(toPost, toPost.NameWithoutExtension(), processedFiles, rarPassword); List<FileToPost> filesToPost = processedFiles.GetFiles() .OrderBy(f => f.Name) .Select(f => new FileToPost(configuration, folderConfiguration, f)).ToList(); List<PostedFileInfo> postedFiles = new List<PostedFileInfo>(); TotalPartCount = filesToPost.Sum(f => f.TotalParts); UploadedPartCount = 0; TotalUploadedBytes = 0; UploadStartTime = DateTime.Now; Int32 fileCount = 1; foreach (var fileToPost in filesToPost) { DateTime filestartTime = DateTime.Now; String comment1 = String.Format("{0} [{1}/{2}]", title, fileCount++, filesToPost.Count); PostedFileInfo postInfo = fileToPost.PostYEncFile(poster, comment1, ""); if (log.IsInfoEnabled) { TimeSpan fileTimeElapsed = DateTime.Now - filestartTime; Double fileSpeed = (Double)fileToPost.File.Length / fileTimeElapsed.TotalSeconds; log.InfoFormat("Posted file {0} with a speed of {1}", fileToPost.File.Name, UploadSpeedReport.GetHumanReadableSpeed(fileSpeed)); } postedFiles.Add(postInfo); } poster.WaitTillCompletion(); if (log.IsInfoEnabled) { TimeSpan totalTimeElapsed = DateTime.Now - StartTime; TimeSpan uploadTimeElapsed = DateTime.Now - UploadStartTime; Double speed = TotalUploadedBytes / totalTimeElapsed.TotalSeconds; Double ulSpeed = TotalUploadedBytes / uploadTimeElapsed.TotalSeconds; log.InfoFormat("Upload of [{0}] has completed at {1} with an upload speed of {2}", title, UploadSpeedReport.GetHumanReadableSpeed(speed), UploadSpeedReport.GetHumanReadableSpeed(ulSpeed)); } Console.WriteLine(); XDocument nzbDoc = GenerateNzbFromPostInfo(toPost.Name, postedFiles, rarPassword); if (saveNzb && configuration.NzbOutputFolder != null) nzbDoc.Save(Path.Combine(configuration.NzbOutputFolder.FullName, toPost.NameWithoutExtension() + ".nzb")); return nzbDoc; } finally { if (processedFiles != null && processedFiles.Exists) { log.Info("Deleting processed folder"); processedFiles.Delete(true); } } } }
public XDocument PostToUsenet(FileSystemInfo toPost, String title, String rarPassword, Boolean saveNzb = true) { using (nntpMessagePoster poster = new nntpMessagePoster(configuration, folderConfiguration)) { poster.PartPosted += poster_PartPosted; DirectoryInfo processedFiles = null; try { DateTime StartTime = DateTime.Now; processedFiles = MakeProcessingFolder(toPost.NameWithoutExtension()); MakeRarAndParFiles(toPost, toPost.NameWithoutExtension(), processedFiles, rarPassword); List <FileToPost> filesToPost = processedFiles.GetFiles() .OrderBy(f => f.Name) .Select(f => new FileToPost(configuration, folderConfiguration, f)).ToList(); List <PostedFileInfo> postedFiles = new List <PostedFileInfo>(); TotalPartCount = filesToPost.Sum(f => f.TotalParts); UploadedPartCount = 0; TotalUploadedBytes = 0; UploadStartTime = DateTime.Now; Int32 fileCount = 1; foreach (var fileToPost in filesToPost) { DateTime filestartTime = DateTime.Now; String comment1 = String.Format("{0} [{1}/{2}]", title, fileCount++, filesToPost.Count); PostedFileInfo postInfo = fileToPost.PostYEncFile(poster, comment1, ""); if (log.IsInfoEnabled) { TimeSpan fileTimeElapsed = DateTime.Now - filestartTime; Double fileSpeed = (Double)fileToPost.File.Length / fileTimeElapsed.TotalSeconds; log.InfoFormat("Posted file {0} with a speed of {1}", fileToPost.File.Name, UploadSpeedReport.GetHumanReadableSpeed(fileSpeed)); } postedFiles.Add(postInfo); } poster.WaitTillCompletion(); if (log.IsInfoEnabled) { TimeSpan totalTimeElapsed = DateTime.Now - StartTime; TimeSpan uploadTimeElapsed = DateTime.Now - UploadStartTime; Double speed = TotalUploadedBytes / totalTimeElapsed.TotalSeconds; Double ulSpeed = TotalUploadedBytes / uploadTimeElapsed.TotalSeconds; log.InfoFormat("Upload of [{0}] has completed at {1} with an upload speed of {2}", title, UploadSpeedReport.GetHumanReadableSpeed(speed), UploadSpeedReport.GetHumanReadableSpeed(ulSpeed)); } Console.WriteLine(); XDocument nzbDoc = GenerateNzbFromPostInfo(toPost.Name, postedFiles, rarPassword); if (saveNzb && configuration.NzbOutputFolder != null) { nzbDoc.Save(Path.Combine(configuration.NzbOutputFolder.FullName, toPost.NameWithoutExtension() + ".nzb")); } return(nzbDoc); } finally { if (processedFiles != null && processedFiles.Exists) { log.Info("Deleting processed folder"); processedFiles.Delete(true); } } } }