private IChromelyResponse GetMovies(IChromelyRequest request) { var movieInfos = new List <MovieInfo>(); var assemblyName = typeof(MovieInfo).Assembly.GetName().Name; movieInfos.Add(new MovieInfo(id: 1, title: "The Shawshank Redemption", year: 1994, votes: 678790, rating: 9.2, assembly: assemblyName)); movieInfos.Add(new MovieInfo(id: 2, title: "The Godfather", year: 1972, votes: 511495, rating: 9.2, assembly: assemblyName)); movieInfos.Add(new MovieInfo(id: 3, title: "The Godfather: Part II", year: 1974, votes: 319352, rating: 9.0, assembly: assemblyName)); movieInfos.Add(new MovieInfo(id: 4, title: "The Good, the Bad and the Ugly", year: 1966, votes: 213030, rating: 8.9, assembly: assemblyName)); movieInfos.Add(new MovieInfo(id: 5, title: "My Fair Lady", year: 1964, votes: 533848, rating: 8.9, assembly: assemblyName)); movieInfos.Add(new MovieInfo(id: 6, title: "12 Angry Men", year: 1957, votes: 164558, rating: 8.9, assembly: assemblyName)); return(new ChromelyResponse(request.Id) { Data = movieInfos }); }
/// <inheritdoc/> public virtual IChromelyResponse HandleError(IChromelyRequest request, IChromelyResponse response, Exception?exception = null) { if (exception is not null) { Logger.Instance.Log.LogError(exception); } var localResponse = new ChromelyResponse { ReadyState = (int)ReadyState.ResponseIsReady, Status = (int)System.Net.HttpStatusCode.BadRequest, StatusText = "An error has occurred" }; localResponse.RequestId = (request is not null && string.IsNullOrWhiteSpace(request.Id)) ? request.Id : localResponse.RequestId; return(localResponse); }
public IChromelyResponse GetTodoItems(IChromelyRequest request) { var parameters = request.Parameters as IDictionary <string, string>; var name = string.Empty; var id = string.Empty; var todo = string.Empty; var completed = string.Empty; if (parameters != null && parameters.Any()) { if (parameters.ContainsKey("name")) { name = parameters["name"] ?? string.Empty; } if (parameters.ContainsKey("id")) { id = parameters["id"] ?? string.Empty; } if (parameters.ContainsKey("todo")) { todo = parameters["todo"] ?? string.Empty; } if (parameters.ContainsKey("completed")) { completed = parameters["completed"] ?? string.Empty; } } if (string.IsNullOrWhiteSpace(name)) { return(new ChromelyResponse() { RequestId = request.Id, Data = new List <Result>() }); } int identifier = 0; int.TryParse(id, out identifier); int intCompleted = 0; int.TryParse(completed, out intCompleted); intCompleted = intCompleted == 1 ? 1 : 0; TodoItem todoItem = new TodoItem(identifier, todo, intCompleted); var todoItems = new List <TodoItem>(); switch (name.ToLower()) { case "add": todoItems = GetOrUpdateList(RequestType.Add, todoItem); break; case "delete": todoItems = GetOrUpdateList(RequestType.Delete, todoItem); break; case "all": todoItems = GetOrUpdateList(RequestType.All, todoItem); break; case "allactive": todoItems = GetOrUpdateList(RequestType.AllActive, todoItem); break; case "allcompleted": todoItems = GetOrUpdateList(RequestType.AllCompleted, todoItem); break; case "clearcompleted": todoItems = GetOrUpdateList(RequestType.ClearCompleted, todoItem); break; case "toggleall": todoItems = GetOrUpdateList(RequestType.ToggleAll, todoItem); break; } return(new ChromelyResponse() { RequestId = request.Id, Data = todoItems });; }
public IChromelyResponse GetMovies(IChromelyRequest request) { var parameters = request.Parameters as IDictionary <string, string>; var name = string.Empty; var query = string.Empty; if (parameters != null && parameters.Any()) { if (parameters.ContainsKey("name")) { name = parameters["name"] ?? string.Empty; } if (parameters.ContainsKey("query")) { query = parameters["query"] ?? string.Empty; } } if (string.IsNullOrWhiteSpace(name)) { return(new ChromelyResponse() { RequestId = request.Id, Data = new List <Result>() }); } if (name.Equals("search") && string.IsNullOrWhiteSpace(query)) { return(new ChromelyResponse() { RequestId = request.Id, Data = new List <Result>() }); } var paramUrl = string.Empty; switch (name.ToLower()) { case "latest": paramUrl = TmdbLatestUrl(); break; case "popular": paramUrl = TmdbPopularUrl(); break; case "toprated": paramUrl = TmdbTopRatedUrl(); break; case "nowplaying": paramUrl = TmdbNowPlayingUrl(); break; case "upcoming": paramUrl = TmdbUpcomingUrl(); break; case "search": paramUrl = TmdbSearchUrl(query); break; } var tmdbMoviesTask = Task.Run(() => { return(GetTmdbMovieListAsync(paramUrl)); }); tmdbMoviesTask.Wait(); List <Result> movies = new List <Result>(); var tmdMovieInfo = tmdbMoviesTask.Result; if (tmdbMoviesTask.Result != null) { movies = tmdbMoviesTask.Result.results; } return(new ChromelyResponse() { RequestId = request.Id, Data = movies }); }
public Task <IChromelyResponse> InvokeAsync(IChromelyRequest request) { return(ActionAsync.Invoke(request)); }
public IChromelyResponse Invoke(IChromelyRequest request) { return(Action.Invoke(request)); }