示例#1
0
        public IActionResult Home(HomeModel homeModel)
        {
            ElementRepository elementRepository = new ElementRepository();

            homeModel.ElementModels = elementRepository.SelectElements().Select(m => (ElementModel.ToElementModel(m))).ToList();

            OutputStreams.WriteLine($"[HttpPost] Home: {String.Join(", ", homeModel.Symbols)}");

            if (ModelState.IsValid == true)
            {
                List <Element>      elements      = homeModel.Symbols.Select(m => (Element.FromString(m))).ToList();
                List <WebService>   webServices   = new List <WebService>(new WebService[] { new AFlowWebService(), new MaterialsProjectWebService() });
                List <SearchResult> searchResults = new List <SearchResult>();

                OutputStreams.WriteLine($"Elements: {String.Join(", ", elements)}");

                foreach (WebService webService in webServices)
                {
                    try
                    {
                        OutputStreams.WriteLine($"Searching {webService.BaseUrl}...");
                        List <SearchResult> webServiceSearchResults = webService.Search(elements);
                        OutputStreams.WriteLine($"{webServiceSearchResults.Count} search results");

                        if (webServiceSearchResults.Count > 0)
                        {
                            searchResults.AddRange(webServiceSearchResults);
                        }
                    }
                    catch (Exception exception)
                    {
                        OutputStreams.WriteLine();
                        OutputStreams.WriteLine(exception.Message);
                    }
                }

                homeModel.SearchResults = searchResults.OrderBy(m => (m.Compound)).ThenByDescending(m => (m.BandGap)).ToList();
            }

            return(View(homeModel));
        }
示例#2
0
        public IActionResult Home()
        {
            ElementRepository elementRepository = new ElementRepository();

            return(View(new HomeModel(elementRepository.SelectElements().Select(m => (ElementModel.ToElementModel(m))).ToList())));
        }