Esempio n. 1
0
        public RipperModule(RipperService service, Persister <RipperSettings> persister)
            : base("ripper")
        {
            Get["/"]        = x => View["index.cshtml", GetRipperViewModel(service)];
            Post["/Cancel"] = x =>
            {
                service.CancelRipping();
                if (Context.IsAjaxRequest())
                {
                    return("ok");
                }
                return(new RedirectResponse(ModulePath));
            };
            Post["/selectAlbum"] = x =>
            {
                service.SelectAlbum(Request.Form.albumId);

                if (Context.IsAjaxRequest())
                {
                    return("ok");
                }
                return(new RedirectResponse(ModulePath));
            };
            Get["/settings"]  = x => View["settings.cshtml", new RipperSettingsViewModel {
                                              Title = "Ripper Settings", Settings = persister.Get()
                                          }];
            Post["/settings"] = x =>
            {
                if (Request.Form.Reset)
                {
                    persister.Save(new RipperSettings());
                }
                else
                {
                    var currentSettings = persister.Get();
                    this.BindToAndValidate(currentSettings);
                    if (this.ModelValidationResult.IsValid)
                    {
                        persister.Save(currentSettings);
                    }
                    else
                    {
                        return(View["settings.cshtml", new RipperSettingsViewModel {
                                        Title = "Ripper Settings", Settings = currentSettings
                                    }]);
                    }
                }
                return(new RedirectResponse("settings"));
            };
        }
Esempio n. 2
0
        private async Task RipTrack(ICdDrive cdDrive, Track track, TrackIdentification trackIdentification, CancellationToken token)
        {
            var currentTrackNumber = track.TrackNumber;

            using (var reader = new TrackReader(cdDrive))
            {
                var settings = _settings.Get();
                using (var lame = new LameMp3Encoder(new EncoderSettings
                {
                    Track = trackIdentification,
                    Mp3Settings = new Mp3Settings
                    {
                        Bitrate = settings.BitRate,
                        Type = settings.BitRateType
                    },
                    Output = new OutputLocationBuilder(settings.MusicCollectionRoot, settings.FileNameMask)
                }))
                {
                    reader.Progress += (read, bytes) =>
                    {
                        var percentageComplete = Math.Round(((double)read / (double)bytes) * 100d, 0);
                        _tracker.RippingProgress(currentTrackNumber, percentageComplete);
                    };
                    await reader.ReadTrack(track, lame.Write, token);
                }
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Получает страницы из хранилища, фильтрует перед выдачей и формирует шаблон в случае пустой страницы
        /// </summary>
        /// <param name="usage">Варинат использования</param>
        /// <param name="codes"></param>
        /// <returns></returns>
        public IEnumerable <WikiPage> Get(string usage, params string[] codes)
        {
            CheckPersister();
            var dict = codes.ToDictionary(_ => _, _ => new WikiPage {
                Code = _
            });

            foreach (var page in Persister.Get(codes))
            {
                page.Existed    = true;
                dict[page.Code] = page;
            }
            foreach (var wikiPage in dict.Values)
            {
                if (!wikiPage.Existed)
                {
                    if (null != WikiEmptyFilters && 0 != WikiEmptyFilters.Length)
                    {
                        foreach (var emptyFilter in WikiEmptyFilters)
                        {
                            emptyFilter.Execute(this, wikiPage);
                        }
                    }
                }
                if (null != WikiGetFilters && 0 != WikiGetFilters.Length)
                {
                    foreach (var getFilter in WikiGetFilters)
                    {
                        getFilter.Execute(this, wikiPage, usage);
                    }
                }
                yield return(wikiPage);
            }
        }