public XDocument PostToUsenet(FileSystemInfo toPost, String rarPassword, Boolean saveNzb = true) { return PostToUsenet(toPost, toPost.NameWithoutExtension(), rarPassword, saveNzb); }
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); } } } }
private void PostRelease(UploadEntry nextUpload, FileSystemInfo toUpload, Boolean isDirectory) { nextUpload.CleanedName = CleanName(toUpload.NameWithoutExtension()) + configuration.PostTag; if (configuration.UseObfuscation) { nextUpload.ObscuredName = Guid.NewGuid().ToString("N"); nextUpload.NotifiedIndexerAt = null; DBHandler.Instance.UpdateUploadEntry(nextUpload); //This ensures we already notify the indexer of our obfuscated post before we start posting. } FileSystemInfo toPost = null; try { if (isDirectory) { toPost = PrepareDirectoryForPosting(nextUpload, (DirectoryInfo)toUpload); } else { toPost = PrepareFileForPosting(nextUpload, (FileInfo)toUpload); } var nzbFile = poster.PostToUsenet(toPost, false); if (!String.IsNullOrWhiteSpace(posterConfiguration.NzbOutputFolder)) nzbFile.Save(Path.Combine(posterConfiguration.NzbOutputFolder, nextUpload.CleanedName + ".nzb")); nextUpload.UploadedAt = DateTime.UtcNow; DBHandler.Instance.UpdateUploadEntry(nextUpload); } finally { if(toPost != null) { toPost.Refresh(); if(toPost.Exists) { FileAttributes attributes = File.GetAttributes(toPost.FullName); if (attributes.HasFlag(FileAttributes.Directory)) { Directory.Delete(toPost.FullName, true); } else { File.Delete(toPost.FullName); } } } } }