Esempio n. 1
0
        public void Then_monthly_report_should_have_latest_day_on_top()
        {
            var bandwidths = new List<MonthlyBandwidth>() { new MonthlyBandwidth(2011, 1, 0, 0), new MonthlyBandwidth(2011, 12, 0, 0), new MonthlyBandwidth(2011, 6, 0, 0) };
            var bandwidthReport = new BandwidthReport(bandwidths, Enumerable.Empty<DailyBandwidth>());

            var settings = new DownloaderSettings() { ReportFileName = @"./report.txt", Separator = ";", ReportType = BandwidthDownloader.ReportType.Monthly };

            var report = new UnitTestableCsvReport();
            report.Save(bandwidthReport, settings);

            var firstLine = report.ReportContent.ToList()[0];
            var date = firstLine.Split(';')[0];
            Assert.AreEqual("12.2011", date);
        }
Esempio n. 2
0
        /// <summary>
        /// Saves the report.
        /// </summary>
        /// <param name="report">
        /// The report.
        /// </param>
        /// <param name="settings">
        /// The settings.
        /// </param>
        public void Save(BandwidthReport report, DownloaderSettings settings)
        {
            this.FileName = Path.GetFullPath(settings.ReportFileName);
            this.Separator = settings.Separator;
            this.Append = settings.Append;
            this.BandwidthUnit = settings.BandwidthUnit;

            if (ReportType.Daily == settings.ReportType)
            {
                this.SaveDailyReport(report.Daily);
                return;
            }

            this.SaveMonthlyReport(report.Monthly);
        }
Esempio n. 3
0
        private static void UpdateSettingsFromCommandLine(string[] args, DownloaderSettings downloaderSettings)
        {
            var commandLine = CommandLine.Parse(args);

            if (commandLine.FileNameSpecified)
            {
                downloaderSettings.ReportFileName = commandLine.FileName;
            }

            if (commandLine.ReportType.HasValue)
            {
                downloaderSettings.ReportType = commandLine.ReportType.Value;
            }

            if (commandLine.Unit.HasValue)
            {
                downloaderSettings.BandwidthUnit = commandLine.Unit.Value;
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Starts the program.
        /// </summary>
        /// <param name="textWriter">
        /// The text Writer.
        /// </param>
        /// <param name="args">
        /// Command line parameters.
        /// </param>
        public void Run(TextWriter textWriter, string[] args)
        {
            var downloaderSettings = new DownloaderSettings(this.LoadApplicationSettings());

            UpdateSettingsFromCommandLine(args, downloaderSettings);

            var reportDownloader = this.CreateReportDownloader();
            reportDownloader.Address = downloaderSettings.Address;
            reportDownloader.UserName = downloaderSettings.UserName;
            reportDownloader.Password = downloaderSettings.Password;
            reportDownloader.Timeout = downloaderSettings.Timeout;

            textWriter.WriteLine("Downloading report from {0}", downloaderSettings.Address);

            reportDownloader.BeginDownload();
            var result = reportDownloader.EndDownload();
            reportDownloader.Dispose();

            textWriter.WriteLine("Saving report into {0}", Path.GetFullPath(downloaderSettings.ReportFileName));
            var report = this.CreateReportWriter();
            report.Save(result, downloaderSettings);

            textWriter.WriteLine("Done");
        }