/// <summary> /// Retrieve the images from the Satellite API. /// </summary> /// <param name="ImageDate"></param> private static void GetImages(string ImageDate) { try { NasaPhotos.Models.NasaMarsPhotos NasaPhotos = (NasaPhotos.Models.NasaMarsPhotos)PhotoUtility.ExecuteService(PhotoUtility.configuration.GetSection("NasaUrl:url").Value, String.Format("&earth_date={0}", ImageDate), typeof(NasaPhotos.Models.NasaMarsPhotos)); // if there was an exception if (NasaPhotos != null) { foreach (var photo in NasaPhotos.Photos) { var fileName = photo.Img_Src.Substring(photo.Img_Src.LastIndexOf('/') + 1); Console.WriteLine(photo.Img_Src); if (!PhotoUtility.SaveImage(photo.Img_Src, String.Format(@"{0}\{1}_{2}", PhotoUtility.configuration.GetSection("SaveLocation:path").Value, ImageDate, fileName))) { Console.WriteLine(String.Format(" Unable to save the image : {0}_{1}", ImageDate, fileName)); } else { Console.WriteLine(String.Format("Successfully saved file : {0}_{1}", ImageDate, fileName)); } } } }catch (Exception) { throw; } }
public void SaveImages() { var imageDate = "2017-02-27"; NasaPhotos.Models.NasaMarsPhotos NasaPhotos = (NasaPhotos.Models.NasaMarsPhotos)PhotoUtility.ExecuteService("https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos?sol=1000&camera=fhaz&api_key=DEMO_KEY&", String.Format("&earth_date={0}", "2017-02-27"), typeof(NasaPhotos.Models.NasaMarsPhotos)); var fileName = ""; var fileLocation = "D:\\SaveImages"; foreach (var photo in NasaPhotos.Photos) { fileName = photo.Img_Src.Substring(photo.Img_Src.LastIndexOf('/') + 1); Console.WriteLine(photo.Img_Src); if (!PhotoUtility.SaveImage(photo.Img_Src, String.Format(@"{0}\{1}_{2}", fileLocation, imageDate, fileName))) { Console.WriteLine(String.Format("Unable to save the image : {0}_{1}", imageDate, fileName)); } else { Console.WriteLine(String.Format("Successfully saved file : {0}_{1}", imageDate, fileName)); } } var lastCreatedFile = String.Format(@"{0}\{1}_{2}", fileLocation, imageDate, fileName); Assert.IsTrue(System.IO.File.Exists(lastCreatedFile)); }
public void GetImageByDate() { NasaPhotos.Models.NasaMarsPhotos NasaPhotos = (NasaPhotos.Models.NasaMarsPhotos)PhotoUtility.ExecuteService("https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos?sol=1000&camera=fhaz&api_key=DEMO_KEY&", String.Format("&earth_date={0}", "2017-02-27"), typeof(NasaPhotos.Models.NasaMarsPhotos)); Assert.IsNotNull(NasaPhotos); }