Exemplo n.º 1
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");
            }
        }
Exemplo n.º 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");
            }
        }