Beispiel #1
0
        public ActionResult GetDownloads()
        {
            var model = new DashboardDownloadViewModel();
            var sab   = Sab.GetSettings();
            var nzb   = NzbGet.GetSettings();

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

                    model.DownloadItems = items.jobs.Count;
                    model.Application   = "Sabnzbd";
                }
            }
            else if (nzb != null)
            {
                if (nzb.HasSettings)
                {
                    var formattedUri = UrlHelper.ReturnUri(nzb.IpAddress, nzb.Port).ToString();
                    var nzbItem      = Api.GetNzbGetList(formattedUri, nzb.Username, nzb.Password);

                    model.DownloadItems = nzbItem.result.Count;
                    model.Application   = "NzbGet";
                }
            }
            else
            {
                Logger.Trace("No settings found. Cannot display downloads on the Dashboard");
            }
            return(PartialView("Partial/_Download", model));
        }
Beispiel #2
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));
        }