Пример #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);

            try
            {
                var response = client.FindCharacters(new Marvel.Api.Filters.CharacterRequestFilter()
                {
                    Offset = offset,
                    Limit  = 20
                });
                List <Character> Characters = ConvertIntoCharacters(response);

                ListView lstSuperHero = FindViewById <ListView>(Resource.Id.lstSuperHeroes);
                _adapter             = new SuperHeroAdapter(this, Characters);
                lstSuperHero.Adapter = _adapter;

                lstSuperHero.Scroll += async(o, e) =>
                {
                    if (e.FirstVisibleItem + e.VisibleItemCount == e.TotalItemCount && !endReached && e.TotalItemCount > 0)
                    {
                        int loaderPosition = _adapter.Count;
                        Characters.Add(null);
                        _adapter.NotifyDataSetChanged();
                        endReached = true;
                        offset    += 20;
                        await Task.Delay(100);

                        response = client.FindCharacters(new Marvel.Api.Filters.CharacterRequestFilter()
                        {
                            Offset = offset,
                            Limit  = 20
                        });
                        List <Character> charactersToAdd = ConvertIntoCharacters(response);

                        if (Characters.Count >= loaderPosition && Characters[loaderPosition] == null)
                        {
                            Characters.RemoveAt(loaderPosition);
                            _adapter.NotifyDataSetChanged();
                        }
                        if (charactersToAdd.Count > 0)
                        {
                            Characters.AddRange(charactersToAdd);
                            _adapter.NotifyDataSetChanged();
                            endReached = false;
                        }
                    }
                };
            }
            catch (Exception ex)
            {
            }
        }
        private static List <Personagem> BaixarPersonagens(MarvelRestClient client)
        {
            int offset      = 0;
            int limit       = 100;
            int total       = int.MaxValue;
            var personagens = new List <Personagem>();

            while (offset < total)
            {
                var filtro = new CharacterRequestFilter()
                {
                    Limit  = limit,
                    Offset = offset
                };

                var response = client.FindCharacters(filtro);

                total   = Convert.ToInt32(response.Data.Total);
                offset += limit;

                foreach (var character in response.Data.Results)
                {
                    var personagem = new Personagem()
                    {
                        IdPersonagem    = character.Id,
                        Nome            = character.Name,
                        QuantQuadrinhos = character.Comics.Items.Count
                    };

                    personagens.Add(personagem);
                }
            }

            return(personagens);
        }
Пример #3
0
        public ActionResult Index()
        {
            ViewBag.Title = "Home Page";
            System.Diagnostics.Trace.WriteLine("In Home Controller");

            // accessing developer.marvel.com

            //HTTP GET
            // http://gateway.marvel.com/v1/public/comics?ts=1&apikey=1234&hash=ffd275c5130566a2916217b101f26150


            // randomize which of the 50 retrieved characters will be displayed
            int characterIndex = new Random().Next(0, 99);


            var marvelClient = new MarvelRestClient(pb_key, pr_key);
            var filter       = new CharacterRequestFilter
            {
                Limit = 100
            };

            var response = marvelClient.FindCharacters(filter);
            var imageUrl = response.Data.Results[characterIndex].Thumbnail.Path + "." +
                           response.Data.Results[characterIndex].Thumbnail.Extension;

            if (imageUrl.Contains("image_not_available"))
            {
                imageUrl = "https://www.writeups.org/wp-content/uploads/Spider-Man-Marvel-Comics-Peter-Parker-Profile.jpg";
            }
            ViewBag.imageUrl = imageUrl;


            return(View());
        }
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);

            try
            {
                MarvelRestClient client     = new MarvelRestClient(publicKey, privateKey);
                var response                = client.FindCharacters();
                List <Character> Characters = new List <Character>();
                foreach (var character in response.Data.Results)
                {
                    Characters.Add(new Character()
                    {
                        Name     = character.Name,
                        ImageUrl = string.Format("{0}.{1}", character.Thumbnail.Path, character.Thumbnail.Extension)
                    });
                }

                ListView lstSuperHero = FindViewById <ListView>(Resource.Id.lstSuperHeroes);
                _adapter             = new SuperHeroAdapter(this, Characters);
                lstSuperHero.Adapter = _adapter;
            }
            catch (Exception ex)
            {
            }
        }
Пример #5
0
        public List <Character> GetCharacters(int?offset = 0)
        {
            List <Character> heroes = new List <Character>();

            Marvel.Api.Filters.CharacterRequestFilter f = new Marvel.Api.Filters.CharacterRequestFilter();
            f.OrderBy(OrderResult.NameAscending);
            f.Offset = offset;
            CharacterResult r = client.FindCharacters(f);
            int             i = 1;

            foreach (Character c in r.Data.Results)
            {
                if (c.Name == "" || c.Description == "" || c.Thumbnail == null && i > 10)
                {
                    continue;
                }
                heroes.Add(c);
                i++;
            }
            return(heroes);
        }
Пример #6
0
        public static List <Character> FindByName(string name)
        {
            var creds  = new Credentials();
            var client = new MarvelRestClient(creds.PublicKey, creds.PrivateKey);

            var filter = new CharacterRequestFilter();

            filter.NameStartsWith = name;

            var response = client.FindCharacters(filter);

            return(ResultsToList(response));
        }
Пример #7
0
        public static void Main()
        {
            // Initialize the API client
            //
            var client = new MarvelRestClient(publicKey, privateKey);

            // First 20 characters
            //
            var response = client.FindCharacters();

            // Iterate through the results and print them out.
            //
            response.Data.Results.ForEach(c => Console.WriteLine($"{c.Name} : {c.Description}"));
            Console.ReadLine();
        }
Пример #8
0
        public override async Task <FunctionResponse> ProcessMessageAsync(FunctionRequest request)
        {
            // Initialize the marvel api client
            var client = new MarvelRestClient(PUBLICKEY, PRIVATEKEY);

            // Initialize an avengers team
            var team = new Types.AvengerTeam();

            // Initialize character request filter
            var characterRequestFilter = new CharacterRequestFilter();

            // Query marvel api for desired avengers
            // TODO: refine this logic to assemble stronger team
            characterRequestFilter.OrderBy(OrderResult.NameAscending);
            characterRequestFilter.Limit = 1;
            var characterResponse = client.FindCharacters(characterRequestFilter);

            foreach (var character in characterResponse.Data.Results)
            {
                // Initialize a comic listing filter to determine power for each avenger
                var comicRequestFilter = new ComicRequestFilter();
                comicRequestFilter.AddCharacter(character.Id);

                // Form avenger object
                var currentAvenger = new Types.Avenger();
                currentAvenger.name  = character.Name;
                currentAvenger.id    = character.Id;
                currentAvenger.power = client.FindCharacterComics(character.Id.ToString(), comicRequestFilter).Data.Total;

                // Add avenger to team
                team.AddAvengerToTeam(currentAvenger);
            }

            var message = GameLogic.Methods.FormatBattlefieldId(request.RoundNumber, DateTime.UtcNow.ToString(), "AVENGERS", "DEFEND");

            await Methods.PostBattlefield(new Types.Item
            {
                Id    = message,
                Value = JsonConvert.SerializeObject(team.avengerTeam)
            });

            return(new FunctionResponse());
        }
Пример #9
0
        public IActionResult Index(/*RestResponse restResponse*//*RestRequest request*//*NameViewModel postdata*/)
        {
            const string apiKey     = "1f8c669bfb6d6b86aa65400c8f3ad03d";
            const string privateKey = "b7e37b0815b570c2f84f0267060b0637698ed06a";

            var client = new MarvelRestClient(apiKey, privateKey);
            //List<ResultViewModel> results = null;
            List <CharactersInResultViewModel> results = null;
            List <CharactersInResultViewModel> resultsCharactersInAStory = null;



            //NameViewModel postdata = "hulk";

            //if (postdata.Type.ToLower() == "character")
            //{
            var filter = new CharacterRequestFilter {
                NameStartsWith = "hulk"
            };

            filter.OrderBy(OrderResult.NameAscending);
            //filter.Limit = 40;
            filter.Limit = 1;


            var response = client.FindCharacters(filter);

            //if (response.Code == "200")
            //{
            //    results =
            //    response.Data.Results.Select(res =>
            //        new CharactersInResultViewModel { Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();
            //}


            results =
                response.Data.Results.Select(res =>
                                             new CharactersInResultViewModel {
                StoryID = /*res.Stories.Items.Equals(*/ "1009351" /*).ToString()*/, /**StoryID = res.Stories. */ Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL
            }).ToList();



            //            else
            //            {

            //                    if (response.Code == "200")
            //            {
            //            results =
            //            response.Data.Results.Select(res =>
            //                new CharactersInResultViewModel { Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL
            //    }).ToList();
            //}


            //results =
            //            response.Data.Results.Select(res =>
            //                new CharactersInResultViewModel { StoryID = /*res.Stories.Items.Equals(*/"1009351"/*).ToString()*/,/**StoryID = res.Stories. */Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();


            List <ResultViewModel> realresults = new List <ResultViewModel>();

            //ResultViewModel realresults;


            realresults =
                response.Data.Results.Select(res =>
                                             new ResultViewModel {
                Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL
            }).ToList();

            realresults.FirstOrDefault();



            //else
            //{

            //if (response.Code == "200")
            //{
            //results =
            //response.Data.Results.Select(res =>
            //    new ResultViewModel { Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();
            //    }


            //results =
            //response.Data.Results.Select(res =>
            //    new CharactersInResultViewModel { StoryID = /*res.Stories.Items.Equals(*/"1009351"/*).ToString()*/,/**StoryID = res.Stories. */Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();


            //}
            //else
            //{

            FindStoryCharacters();

            //ViewBag.Message = (List<CharactersInResultViewModel>)request;

            /*ViewBag.Message =*/ /*(List<CharactersInResultViewModel>)*//*request;*/

            /* ViewBag.Message =*/ /*(List<CharactersInResultViewModel>)*//*restResponse;*/


            //ViewBag.Message = results;



            //var comicFilter = new ComicRequestFilter { TitleStartsWith = "hulk" };
            //comicFilter.OrderBy(OrderResult.NameAscending);
            //comicFilter.Limit = 40;
            ////comicFilter.Limit = 1;

            //var comicFilterresponse = client.FindComics(comicFilter);

            ////if (response.Code == "200")
            ////{
            //results =
            //response.Data.Results.Select(res =>
            //    new CharactersInResultViewModel { /*Characters = Marvel.Api.Model.DomainObjects.Story.*/ Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();
            ////}
            //var firstResultDescription = results.FirstOrDefault();

            //var characterList =

            //var characterList = firstResultDescription.Description.

            //var Filter = new StoryRequestFilter { };
            //Filter.OrderBy(OrderResult.NameAscending);
            //Filter.Limit = 40;
            ////filter.Limit = 1;

            //StoryResult storyFilterresponse = client.FindStory("1009351");  /*client.FindStoryCharacters("1009351");*/

            //resultsCharactersInAStory =
            //storyFilterresponse.Data.Results.Select(res =>
            //    new CharactersInResultViewModel { /*Characters = res.Stories., */Id = res.Id, Description = res.Description/*, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL */}).ToList();
            ////    }



            //storyFilterresponse.Data.Results.

            //resultsCharactersInAStory =
            //storyFilterresponse.Data.Results.Select(res =>
            //    new CharactersInResultViewModel { /*Characters = res.Stories., */Id = res.Id, Description = res.Description/*, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL */}).ToList();
            ////    }

            //if (response.Code == "200")
            //{
            //results =
            //response.Data.Results.Select(res =>
            //    new ResultViewModel { Id = res.Id, Description = res.Description, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();
            ////    }
            ////}

            List <CharactersInResultViewModel> charactersResults = null;

            charactersResults =
                response.Data.Results.Select(res =>
                                             new CharactersInResultViewModel {
                Name = res.Name
            }).ToList();
            //    }
            //}

            var storyFilterresponseCharacterList = charactersResults;

            var baseAddress = new Uri("http://importmarvel.com/");

            using (var httpClient = new HttpClient
            {
                BaseAddress = baseAddress
            })
            {
                using (var allCharactersInAStory = /*await */ httpClient.GetAsync("api/characters"))
                {
                    string allCharactersInAStoryData = allCharactersInAStory.Result.ToString();

                    ViewBag.Message = allCharactersInAStoryData;

                    return(View(allCharactersInAStoryData));
                }

                //ViewBag.Message = allCharactersInAStoryData;

                //ViewBag.Message = realresults;

                //return View(allCharactersInAStoryData);

                //return View(realresults);



                //ViewBag.Message = results;


                //return View(results);



                //ViewBag.Message = resultsCharactersInAStory;


                //return View(resultsCharactersInAStory);



                //return View(storyFilterresponse);


                //ViewBag.Message = storyFilterresponseCharacterList;

                //return Json(storyFilterresponseCharacterList);

                //return View("Index", restResponse);

                //return View(storyFilterresponseCharacterList);

                //return Json(results);



                //[HttpPost]
                //[HttpGet]
                //public IActionResult Index(/*NameViewModel postdata*/)
                //{

                //    const string apiKey = "1f8c669bfb6d6b86aa65400c8f3ad03d";
                //    const string privateKey = "b7e37b0815b570c2f84f0267060b0637698ed06a";

                //    const string characterName = "hulk";

                //    var client = new MarvelRestClient(apiKey, privateKey);
                //    List<ResultViewModel> results = null;

                //    //if (postdata.Type.ToLower() == "character")
                //    //{
                //    var filter = new StoryRequestFilter { /*Characters.Equals == The Hulk*//*NameStartsWith = postdata.Name*/ };
                //    filter.OrderBy(OrderResult.NameAscending);
                //    //filter.Comics.Contains("hulk");
                //    //filter.Comics.Where(res.Id == 30)
                //    //filter.Series.
                //    filter.Limit = 1;

                //    //var response = client.FindCharacters(filter);

                //    var response = client.FindStories(filter);

                //    //if (response.Code == "200")
                //    //    {
                //    //results =
                //    //response.Data.Results./*Where(results.*//*Where(response.Data.Results.).*/Select(res =>
                //    //                //new ResultViewModel { Id = 30/*res.Id*/, Description = res.Description,  Name = "The second volume containing the Hulk\u0027s early adventures with appearances by the Sub-Mariner, the Mandarin, Ka-Zar and Nick Fury" /*res.Title*/, Url = "http://gateway.marvel.com/v1/public/stories/30" /*res.ResourceURI*/ })./*Where(response.Data.Results.Id*//*.Where(res.Id == 30)*//*.*/ToList()/*.Where(Id == 30)*//*.FirstOrDefault*//*(*//*t => t.Type == "detail").URL }).ToList(*//*)*/;
                //    //                new ResultViewModel { Id = 30, Description = res.Description, Name = res.Title, Url = "http://gateway.marvel.com/v1/public/stories/30/" })./*Where(response.Data.Results.Id*//*.Where(res.Id == 30)*//*.*/ToList()/*.Where(Id == 30)*//*.FirstOrDefault*//*(*//*t => t.Type == "detail").URL }).ToList(*//*)*/;

                //    results =
                //            response.Data.Results.Select(res =>
                //                new ResultViewModel { Id = res.Id, Description = res.Description, Name = res.Title, Url = res.ResourceURI.FirstOrDefault().ToString() }).ToList();



                //    //}.

                //    //results.Where()

                //    //else
                //    //{
                //    //    var filter = new ComicRequestFilter { TitleStartsWith = postdata.Name };
                //    //    filter.OrderBy(OrderResult.NameAscending);
                //    //    filter.Limit = 40;

                //    //    var response = client.FindComics(filter);

                //    //    if (response.Code == "200")
                //    //    {
                //    //        results =
                //    //        response.Data.Results.Select(res =>
                //    //            new ResultViewModel { Id = res.Id, Name = res.Title, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();
                //    //    }
                //    //}
                //    return Json(results/*.ToList()*/);
                //    //return View(results);
                //}

                //return View();



                //[HttpPost]
                //public JsonResult SomeActionMethod(NameViewModel postdata)
                //{
                //    const string apiKey = "1f8c669bfb6d6b86aa65400c8f3ad03d";
                //    const string privateKey = "b7e37b0815b570c2f84f0267060b0637698ed06a";


                //    var client = new MarvelRestClient(apiKey, privateKey);
                //    List<ResultViewModel> results = null;

                //    if (postdata.Type.ToLower() == "character")
                //    {
                //        var filter = new CharacterRequestFilter { NameStartsWith = postdata.Name };
                //        filter.OrderBy(OrderResult.NameAscending);
                //        filter.Limit = 40;

                //        var response = client.FindCharacters(filter);

                //        if (response.Code == "200")
                //        {
                //            results =
                //            response.Data.Results.Select(res =>
                //                new ResultViewModel { Id = res.Id, Name = res.Name, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();
                //        }
                //    }
                //    else
                //    {
                //        var filter = new ComicRequestFilter { TitleStartsWith = postdata.Name };
                //        filter.OrderBy(OrderResult.NameAscending);
                //        filter.Limit = 40;

                //        var response = client.FindComics(filter);

                //        if (response.Code == "200")
                //        {
                //            results =
                //            response.Data.Results.Select(res =>
                //                new ResultViewModel { Id = res.Id, Name = res.Title, Url = res.Urls.FirstOrDefault(t => t.Type == "detail").URL }).ToList();
                //        }
                //    }
                //    return Json(results);
                //}

                //public IActionResult Privacy()
                //{
                //    return View();
                //}
            }
        }