public IActionResult About()
        {
            ApodController webHandler = new ApodController();
            Apod           apod       = webHandler.GetApod();

            return(View(apod));
        }
Beispiel #2
0
        /// <summary>
        /// Method to receive data from API end point as a collection of objects
        ///
        /// JsonConvert parses the JSON string into classes
        /// </summary>
        /// <returns></returns>
        public Apod GetApod()
        {
            string APOD_API_PATH = BASE_URL + "/apod?api_key=" + API_KEY;
            string ApodData      = "";

            Apod apod = null;

            httpClient.BaseAddress = new Uri(APOD_API_PATH);

            // It can take a few requests to get back a prompt response, if the API has not received
            //  calls in the recent past and the server has put the service on hibernation
            try
            {
                HttpResponseMessage response = httpClient.GetAsync(APOD_API_PATH).GetAwaiter().GetResult();
                if (response.IsSuccessStatusCode)
                {
                    ApodData = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();
                }

                if (!ApodData.Equals(""))
                {
                    // JsonConvert is part of the NewtonSoft.Json Nuget package
                    apod = JsonConvert.DeserializeObject <Apod>(ApodData);
                }
            }
            catch (Exception e)
            {
                // This is a useful place to insert a breakpoint and observe the error message
                Console.WriteLine(e.Message);
            }

            return(apod);
        }
Beispiel #3
0
        private async Task ReplyApodAsync(Apod apod)
        {
            var embed = new EmbedBuilder()
                        .WithTitle(apod.Title)
                        .WithDescription(apod.Explanation)
                        .WithImageUrl(apod.ImageUrl)
                        .WithTimestamp(apod.Date);

            await ReplyEmbedAsync(embed);
        }
Beispiel #4
0
 private void Apod_GridView_ItemClick(object sender, ItemClickEventArgs e)
 {
     SelectedItem = (Apod)e.ClickedItem;
     if (SelectedItem != null)
     {
         Frame.Navigate(typeof(ContentPage), SelectedItem, new SlideNavigationTransitionInfo()
         {
             Effect = SlideNavigationTransitionEffect.FromRight
         });
         Apod_GridView.ScrollIntoView(SelectedItem, ScrollIntoViewAlignment.Default);
     }
 }
Beispiel #5
0
        public async Task GreetingIntent(IDialogContext context, LuisResult result)
        {
            var            replyMessage = context.MakeMessage();
            ApodAttributes apod         = await Apod.GetDetails();

            Attachment attachment = await GetProfileHeroCardAsync(apod.url);

            replyMessage.Attachments = new List <Attachment> {
                attachment
            };
            await context.PostAsync(replyMessage);
        }
Beispiel #6
0
 protected override void OnNavigatedTo(NavigationEventArgs e)
 {
     base.OnNavigatedTo(e);
     SelectedItem = (Apod)e.Parameter;
     if (Settings.Instance.IsOriginalAspectRatio)
     {
         ContentPage_ImageViewer.Stretch = Stretch.Uniform;
     }
     if (Settings.Instance.SwitchToCompactPanel)
     {
         InfoPanel.Visibility = Visibility.Collapsed;
         ImageViewer_Flyout_ShowPanel.IsChecked = false;
     }
 }
Beispiel #7
0
        public async Task <Attachment> GetProfileHeroCardAsync(string url)
        {
            ApodAttributes apod = await Apod.GetDetails();

            var heroCard = new HeroCard
            {
                Title    = string.Format(apod.title),
                Subtitle = string.Format(apod.Explanation),
                Tap      = new CardAction(ActionTypes.OpenUrl, "Learn More", value: "http://antwrp.gsfc.nasa.gov/apod/astropix.html"),
                Images   = new List <CardImage> {
                    new CardImage(apod.url)
                },
            };

            return(heroCard.ToAttachment());
        }
Beispiel #8
0
        /// <summary>
        /// Initialize using api_key
        /// </summary>
        /// <param name="apiKey"></param>
        public NasaOpenApi(string apiKey)
        {
            //8 = DEMO_KEY
            if (string.IsNullOrWhiteSpace(apiKey) || apiKey.Length < 8)
            {
                throw new ArgumentException("Provided api_key is invalid, genere new key using https://api.nasa.gov/");
            }

            Apod        = new Apod(apiKey, _nasaOpenApiState);
            NeoFeed     = new NeoFeed(apiKey, _nasaOpenApiState);
            NeoLookup   = new NeoLookup(apiKey, _nasaOpenApiState);
            NeoToday    = new NeoToday(apiKey, _nasaOpenApiState);
            NeoSentry   = new NeoSentry(apiKey, _nasaOpenApiState);
            NeoBrowse   = new NeoBrowse(apiKey, _nasaOpenApiState);
            NeoStats    = new NeoStats(apiKey, _nasaOpenApiState);
            MarsPhotos  = new MarsPhotos(apiKey, _nasaOpenApiState);
            EarthImage  = new EarthImage(apiKey, _nasaOpenApiState);
            EarthAssets = new EarthAssets(apiKey, _nasaOpenApiState);
            //MarsWeather = new MarsWeather(apiKey, _nasaOpenApiState);
            Tle = new Tle(_nasaOpenApiState);
        }