using Microsoft.Extensions.Logging; using Roadie.Library; using Roadie.Library.Caching; using Roadie.Library.Configuration; using Roadie.Library.Encoding; using Roadie.Library.Models; using Roadie.Library.Utility; using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Threading.Tasks; using data = Roadie.Library.Data; namespace Roadie.Api.Services { /// /// Returns lookups (or dictionaries) of various allowable values for a given Type /// public class LookupService : ServiceBase, ILookupService { public LookupService(IRoadieSettings configuration, IHttpEncoder httpEncoder, IHttpContext httpContext, data.IRoadieDbContext dbContext, ICacheManager cacheManager, ILogger logger) : base(configuration, httpEncoder, dbContext, cacheManager, logger, httpContext) { } public Task>> ArtistTypes() { var sw = Stopwatch.StartNew(); return Task.FromResult(new OperationResult> { Data = this.EnumToDataTokens(typeof(Roadie.Library.Enums.ArtistType)), IsSuccess = true, OperationTime = sw.ElapsedMilliseconds }); } public Task>> BandStatus() { var sw = Stopwatch.StartNew(); return Task.FromResult(new OperationResult> { Data = this.EnumToDataTokens(typeof(Roadie.Library.Enums.BandStatus)), IsSuccess = true, OperationTime = sw.ElapsedMilliseconds }); } public Task>> BookmarkTypes() { var sw = Stopwatch.StartNew(); return Task.FromResult(new OperationResult> { Data = this.EnumToDataTokens(typeof(Roadie.Library.Enums.BookmarkType)), IsSuccess = true, OperationTime = sw.ElapsedMilliseconds }); } public Task>> CollectionTypes() { var sw = Stopwatch.StartNew(); return Task.FromResult(new OperationResult> { Data = this.EnumToDataTokens(typeof(Roadie.Library.Enums.CollectionType)), IsSuccess = true, OperationTime = sw.ElapsedMilliseconds }); } public Task>> LibraryStatus() { var sw = Stopwatch.StartNew(); return Task.FromResult(new OperationResult> { Data = this.EnumToDataTokens(typeof(Roadie.Library.Enums.LibraryStatus)), IsSuccess = true, OperationTime = sw.ElapsedMilliseconds }); } public Task>> ReleaseTypes() { var sw = Stopwatch.StartNew(); return Task.FromResult(new OperationResult> { Data = this.EnumToDataTokens(typeof(Roadie.Library.Enums.ReleaseType)), IsSuccess = true, OperationTime = sw.ElapsedMilliseconds }); } public Task>> RequestStatus() { var sw = Stopwatch.StartNew(); return Task.FromResult(new OperationResult> { Data = this.EnumToDataTokens(typeof(Roadie.Library.Enums.RequestStatus)), IsSuccess = true, OperationTime = sw.ElapsedMilliseconds }); } public Task>> Status() { var sw = Stopwatch.StartNew(); return Task.FromResult(new OperationResult> { Data = this.EnumToDataTokens(typeof(Roadie.Library.Enums.Statuses)), IsSuccess = true, OperationTime = sw.ElapsedMilliseconds }); } public Task>> QueMessageTypes() { var sw = Stopwatch.StartNew(); return Task.FromResult(new OperationResult> { Data = this.EnumToDataTokens(typeof(Roadie.Library.Enums.QueMessageType)), IsSuccess = true, OperationTime = sw.ElapsedMilliseconds }); } private IEnumerable EnumToDataTokens(Type ee) { var result = new List(); foreach (var ls in Enum.GetValues(ee)) { result.Add(new DataToken { Text = ls.ToString(), Value = ((short)ls).ToString() }); } return result.OrderBy(x => x.Text); } } }