public void GetNzbGetTabDownloads()
        {
            var mockNzbGet = new Mock <ISettingsService <NzbGetSettingsDto> >();
            var mockSab    = new Mock <ISettingsService <SabNzbdSettingsDto> >();
            var logger     = new Mock <ILogger>();

            var nzbGetSettings = F.Build <NzbGetSettingsDto>().With(x => x.Enabled).Create();
            var nzbList        = F.Create <NzbGetList>();
            var status         = F.Create <NzbGetStatus>();

            mockNzbGet.Setup(x => x.GetSettings()).Returns(nzbGetSettings).Verifiable();
            ThirdPartyApi.Setup(x => x.GetNzbGetList(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(nzbList).Verifiable();
            ThirdPartyApi.Setup(x => x.GetNzbGetStatus(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).Returns(status).Verifiable();

            _controller = new DashboardController(HardwareServiceMock.Object, ThirdPartyApi.Object, logger.Object, mockNzbGet.Object, mockSab.Object, NzbDashSettings.Object);

            var result = (PartialViewResult)_controller.GetTabDownloads();
            var model  = (TabDownloadViewModel)result.Model;

            Assert.That(model.Application, Is.EqualTo("NzbGet"));
            Assert.That(model.DownloadSpeed, Is.EqualTo(MemorySizeConverter.SizeSuffix(status.Result.DownloadRate / 1024)));
            Assert.That(model.Downloads.Count, Is.EqualTo(nzbList.result.Count));
            Assert.That(model.Downloads[0].DownloadName, Is.EqualTo(nzbList.result[0].NZBName));
            Assert.That(model.Downloads[0].DownloadPercentage, Is.Not.Null);
            Assert.That(model.Downloads[0].Status, Is.Not.Null);
            Assert.That(model.Downloads[0].ProgressBarClass, Is.Not.Null);
        }
Exemple #2
0
        public ActionResult GetNzbGetDownloadInformation()
        {
            if (!Settings.HasSettings)
            {
                ViewBag.Error = Resources.Resources.Settings_Missing_NzbGet;
                return(PartialView("DashletError"));
            }

            Logger.Trace("Getting Config");
            var formattedUri = UrlHelper.ReturnUri(Settings.IpAddress, Settings.Port).ToString();

            try
            {
                Logger.Trace("Getting NzbGetStatus");
                var statusInfo = Api.GetNzbGetStatus(formattedUri, Settings.Username, Settings.Password);

                Logger.Trace("Getting Current NZBGetlist");
                var downloadInfo = Api.GetNzbGetList(formattedUri, Settings.Username, Settings.Password);

                var downloadSpeed = statusInfo.Result.DownloadRate / 1024;

                var model = new DownloaderViewModel
                {
                    Application   = Applications.NzbGet,
                    DownloadSpeed = MemorySizeConverter.SizeSuffix(downloadSpeed),
                    DownloadItem  = new List <DownloadItem>()
                };

                var results = downloadInfo.result;
                Logger.Trace(string.Format("Results count : {0}", results.Count));
                foreach (var result in results)
                {
                    Logger.Trace(string.Format("Going through result {0}", result.NZBName));
                    var percentage = (result.DownloadedSizeMB / (result.RemainingSizeMB + (double)result.DownloadedSizeMB) * 100);
                    Logger.Trace(string.Format("Percentage : {0}", percentage));

                    var status = EnumHelper <DownloadStatus> .Parse(result.Status);

                    var progressBar = "progress-bar-danger";
                    if (status == DownloadStatus.PAUSED || status == DownloadStatus.QUEUED)
                    {
                        progressBar = "progress-bar-warning";
                    }
                    if (status == DownloadStatus.DOWNLOADING)
                    {
                        progressBar = "progress-bar-success";
                    }

                    model.DownloadItem.Add(
                        new DownloadItem
                    {
                        FontAwesomeIcon    = IconHelper.ChooseIcon(status),
                        DownloadPercentage = Math.Ceiling(percentage).ToString(CultureInfo.CurrentUICulture),
                        DownloadingName    = result.NZBName,
                        Status             = status,
                        NzbId            = result.NZBID,
                        ProgressBarClass = progressBar
                    });
                }

                return(PartialView("_Download", model));
            }
            catch (Exception e)
            {
                Logger.Error(e.Message, e);
                ViewBag.Error = e.Message;
                return(PartialView("DashletError"));
            }
        }
        public void SizeSuffixLong(long input, string expected)
        {
            var result = MemorySizeConverter.SizeSuffix(input);

            Assert.That(result, Is.EqualTo(expected));
        }
Exemple #4
0
        public ActionResult GetSabNzbdDownloadInformation()
        {
            if (!Settings.HasSettings)
            {
                ViewBag.Error = Resources.Resources.Settings_Missing_SabNzb;
                return(PartialView("DashletError"));
            }

            Logger.Trace("Getting Config");
            var formattedUri = UrlHelper.ReturnUri(Settings.IpAddress, Settings.Port).ToString();

            try
            {
                Logger.Trace("Getting GetSabNzbdQueue");
                var statusInfo = Api.GetSabNzbdQueue(formattedUri, Settings.ApiKey);

                var downloadSpeed = statusInfo.kbpersec;

                var model = new DownloaderViewModel
                {
                    Application   = Applications.SabNZBD,
                    DownloadSpeed = MemorySizeConverter.SizeSuffix((long)downloadSpeed),
                    DownloadItem  = new List <DownloadItem>()
                };

                var results = statusInfo.jobs;
                Logger.Trace(string.Format("Results count : {0}", results.Count));
                foreach (var result in results)
                {
                    Logger.Trace(string.Format("Going through result {0}", result.id));
                    var percentage = (result.mbleft / result.mb * 100);
                    Logger.Trace(string.Format("Percentage : {0}", percentage));

                    var status = EnumHelper <DownloadStatus> .Parse(statusInfo.paused? "PAUSED" : "DOWNLOADING");

                    var progressBar = Bootstrap.ProgressBarDanger;
                    if (status == DownloadStatus.PAUSED || status == DownloadStatus.QUEUED)
                    {
                        progressBar = Bootstrap.ProgressBarWarning;
                    }
                    if (status == DownloadStatus.DOWNLOADING)
                    {
                        progressBar = Bootstrap.ProgressBarSuccess;
                    }

                    int nzbId;
                    int.TryParse(result.id, out nzbId);

                    model.DownloadItem.Add(new DownloadItem
                    {
                        FontAwesomeIcon    = IconHelper.ChooseIcon(status),
                        DownloadPercentage = Math.Ceiling(percentage).ToString(CultureInfo.CurrentUICulture),
                        DownloadingName    = result.filename,
                        Status             = status,
                        NzbId            = nzbId,
                        ProgressBarClass = progressBar
                    });
                }

                return(PartialView("_Download", model));
            }
            catch (Exception e)
            {
                Logger.Error(e.Message, e);
                ViewBag.Error = e.Message;
                return(PartialView("DashletError"));
            }
        }
Exemple #5
0
        public ActionResult GetTabDownloads()
        {
            var model = new TabDownloadViewModel();
            var sab   = Sab.GetSettings();
            var nzb   = NzbGet.GetSettings();

            if (sab != null)
            {
                if (sab.HasSettings && sab.Enabled)
                {
                    var formattedUri = UrlHelper.ReturnUri(sab.IpAddress, sab.Port).ToString();
                    var items        = Api.GetSabNzbdQueue(formattedUri, sab.ApiKey);

                    model.DownloadSpeed = MemorySizeConverter.SizeSuffix((long)items.kbpersec);
                    model.Application   = "Sabnzbd";
                    foreach (var dl in items.jobs)
                    {
                        var percentage = (dl.mbleft / dl.mb * 100);
                        Logger.Trace(string.Format("Percentage : {0}", percentage));

                        var status = EnumHelper <DownloadStatus> .Parse(items.paused? "PAUSED" : "DOWNLOADING");

                        var progressBar = Bootstrap.ProgressBarDanger;
                        if (status == DownloadStatus.PAUSED || status == DownloadStatus.QUEUED)
                        {
                            progressBar = Bootstrap.ProgressBarWarning;
                        }
                        if (status == DownloadStatus.DOWNLOADING)
                        {
                            progressBar = Bootstrap.ProgressBarSuccess;
                        }
                        model.Downloads.Add(
                            new TabDownloadItems
                        {
                            DownloadName       = dl.filename,
                            Status             = status.ToString(),
                            DownloadPercentage = percentage,
                            ProgressBarClass   = progressBar
                        });
                    }
                }
            }
            if (nzb != null)
            {
                if (nzb.HasSettings && nzb.Enabled)
                {
                    var formattedUri = UrlHelper.ReturnUri(nzb.IpAddress, nzb.Port).ToString();
                    var statusInfo   = Api.GetNzbGetStatus(formattedUri, nzb.Username, nzb.Password);
                    var nzbItem      = Api.GetNzbGetList(formattedUri, nzb.Username, nzb.Password);

                    model.DownloadSpeed = MemorySizeConverter.SizeSuffix(statusInfo.Result.DownloadRate / 1024);
                    model.Application   = "NzbGet";

                    foreach (var dl in nzbItem.result)
                    {
                        var percentage = (dl.DownloadedSizeMB / (dl.RemainingSizeMB + (double)dl.DownloadedSizeMB) * 100);
                        Logger.Trace(string.Format("Percentage : {0}", percentage));

                        var status = EnumHelper <DownloadStatus> .Parse(dl.Status);

                        var progressBar = "progress-bar-danger";
                        if (status == DownloadStatus.PAUSED || status == DownloadStatus.QUEUED)
                        {
                            progressBar = "progress-bar-warning";
                        }
                        if (status == DownloadStatus.DOWNLOADING)
                        {
                            progressBar = "progress-bar-success";
                        }
                        model.Downloads.Add(
                            new TabDownloadItems
                        {
                            DownloadName       = dl.NZBName,
                            Status             = status.ToString(),
                            DownloadPercentage = percentage,
                            ProgressBarClass   = progressBar
                        });
                    }
                }
            }
            else
            {
                Logger.Trace("No settings found. Cannot display downloads on the Dashboard");
            }
            return(PartialView("NavbarDownloads", model));
        }