コード例 #1
0
        public ActionResult GetNzbGetStatus()
        {
            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);

                var nzbModel = new NzbGetViewModel {
                    Status = statusInfo.Result.ServerPaused ? "Paused" : "Running",
                };

                Logger.Trace("Returning Model");
                return(Json(nzbModel, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                Logger.Error(e.Message, e);
                return(Json("Error", JsonRequestBehavior.AllowGet));
            }
        }
コード例 #2
0
ファイル: SabNzbdController.cs プロジェクト: radtek/NZBDash
        public ActionResult GetSabNzbStatus()
        {
            if (!Settings.HasSettings)
            {
                return(new EmptyResult());
            }

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

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

                var sabNzbdModel = new SabNzbdStatusViewModel
                {
                    Status = queueInfo.paused ? "Paused" : "Running",
                };

                Logger.Trace("Returning Model");
                return(Json(sabNzbdModel, JsonRequestBehavior.AllowGet));
            }
            catch (Exception e)
            {
                Logger.Error(e.Message, e);
                return(Json("Error", JsonRequestBehavior.AllowGet));
            }
        }
コード例 #3
0
        private IQueryable <NzbGetHistoryViewModel> GetHistory()
        {
            try
            {
                var formattedUri = UrlHelper.ReturnUri(Settings.IpAddress, Settings.Port).ToString();
                var history      = Api.GetNzbGetHistory(formattedUri, Settings.Username, Settings.Password);

                var items = new List <NzbGetHistoryViewModel>();
                foreach (var result in history.result)
                {
                    var singleItem   = new NzbGetHistoryViewModel();
                    var mappedResult = (NzbGetHistoryViewModel)singleItem.InjectFrom(new NzbGetHistoryMapper(), result);
                    if (!string.IsNullOrEmpty(mappedResult.FileSize))
                    {
                        long newFileSize;
                        long.TryParse(mappedResult.FileSize, out newFileSize);
                        mappedResult.FileSize = MemorySizeConverter.SizeSuffixMb(newFileSize);
                    }
                    items.Add(mappedResult);
                }

                return(items.AsQueryable());
            }
            catch (Exception e)
            {
                Logger.Error(e.Message, e);
                return(new List <NzbGetHistoryViewModel>().AsQueryable());
            }
        }
コード例 #4
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));
        }
コード例 #5
0
        public ActionResult Logs()
        {
            if (!Settings.HasSettings)
            {
                ViewBag.Error = Resources.Resources.Settings_Missing_NzbGet;
                return(PartialView("DashletError"));
            }

            var formattedUri = UrlHelper.ReturnUri(Settings.IpAddress, Settings.Port).ToString();
            var logs         = Api.GetNzbGetLogs(formattedUri, Settings.Username, Settings.Password);

            if (logs.result != null)
            {
                var orderdLogs = logs.result.OrderByDescending(x => x.ID).ToList();

                var model = orderdLogs.Select(log => (NzbGetLogViewModel) new NzbGetLogViewModel().InjectFrom(new NzbGetLogMapper(), log)).Take(50).ToList();

                return(PartialView("Partial/Logs", model));
            }

            return(PartialView("Partial/Logs", new List <NzbGetLogViewModel>()));
        }
コード例 #6
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"));
            }
        }
コード例 #7
0
ファイル: SabNzbdController.cs プロジェクト: radtek/NZBDash
        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"));
            }
        }
コード例 #8
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));
        }