Beispiel #1
0
        private void MakeRarAndParFiles(FileSystemInfo toPost, String nameWithoutExtension,
                                        DirectoryInfo processedFolder, String password)
        {
            Int64 size = toPost.Size();
            var   humanReadableSize = UploadSpeedReport.GetHumanReadableSize(size);

            log.DebugFormat("ToPost size: {0}({1})", size, humanReadableSize);
            var rarSizeRecommendation = configuration.RarNParSettings
                                        .Where(rr => rr.FromSizeBytes < size)
                                        .OrderByDescending(rr => rr.FromSize)
                                        .First();

            log.DebugFormat("Rar and par settings found: [{0},{1},{2}]", rarSizeRecommendation.FromSize, rarSizeRecommendation.RarSize, rarSizeRecommendation.Par2Percentage);
            var      rarWrapper   = new RarWrapper(configuration.InactiveProcessTimeout, configuration.RarLocation);
            DateTime rarStartTime = DateTime.Now;

            rarWrapper.Compress(
                toPost,
                processedFolder,
                nameWithoutExtension,
                Settings.DetermineOptimalRarSize(rarSizeRecommendation.RarSize,
                                                 configuration.YEncLineSize, configuration.YEncLinesPerMessage),
                password,
                configuration.RarExtraParameters);
            if (log.IsInfoEnabled)
            {
                TimeSpan rarTimeElapsed = DateTime.Now - rarStartTime;
                Double   rarSpeed       = (Double)size / rarTimeElapsed.TotalSeconds;
                log.InfoFormat("Rarred {0} of file(s) with a speed of {1}", humanReadableSize, UploadSpeedReport.GetHumanReadableSpeed(rarSpeed));
            }

            var      parWrapper    = new ParWrapper(configuration.InactiveProcessTimeout, configuration.ParLocation, configuration.ParCommandFormat);
            var      processedSize = processedFolder.Size();
            Int32    partSize      = parWrapper.CalculatePartSize(processedSize, configuration.YEncPartSize);
            DateTime parStartTime  = DateTime.Now;
            Boolean  makePar       = true;

            while (makePar && partSize / configuration.YEncPartSize < 10)   //Max 10 loops.
            {
                try
                {
                    parWrapper.CreateParFilesInDirectory(
                        processedFolder, nameWithoutExtension, partSize, rarSizeRecommendation.Par2Percentage, configuration.ParExtraParameters);
                    makePar = false;
                }
                catch (Par2BlockSizeTooSmallException)
                {
                    partSize += configuration.YEncPartSize;
                }
            }
            if (log.IsInfoEnabled)
            {
                TimeSpan parTimeElapsed = DateTime.Now - parStartTime;
                Double   parSpeed       = (Double)size / parTimeElapsed.TotalSeconds;
                log.InfoFormat("Parred {0} of file(s) with a speed of {1}", UploadSpeedReport.GetHumanReadableSize(size), UploadSpeedReport.GetHumanReadableSpeed(parSpeed));
            }
        }
Beispiel #2
0
        protected virtual void OnNewUploadSpeedReport(UploadSpeedReport e)
        {
            Console.Write("\r" + e.ToString() + "   ");

            EventHandler <UploadSpeedReport> handler = newUploadSpeedReport;

            if (handler != null)
            {
                handler(this, e);
            }
        }
Beispiel #3
0
        protected virtual void OnNewUploadSpeedReport(UploadSpeedReport e)
        {
            Console.Write("\r" + e.ToString() + "   ");

            EventHandler<UploadSpeedReport> handler = newUploadSpeedReport;
            if (handler != null) handler(this, e);
        }
Beispiel #4
0
        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);
                    }
                }
            }
        }
Beispiel #5
0
        protected virtual void OnNewUploadSpeedReport(UploadSpeedReport e)
        {
            Console.Write("\r" + e.ToString() + "   ");

            NewUploadSpeedReport?.Invoke(this, e);
        }
Beispiel #6
0
 static void poster_newUploadSpeedReport(object sender, UploadSpeedReport e)
 {
     Console.Write("\r" + e.ToString() + "          ");
 }
Beispiel #7
0
 static void poster_newUploadSpeedReport(object sender, UploadSpeedReport e)
 {
     Console.Write("\r" + e.ToString() + "          ");
 }