private DownloadedFile DownloadFile(string uri) { DownloadedFile File = new DownloadedFile(); byte[] data; using (WebClient Client = new WebClient()) { data = Client.DownloadData(uri); File.ContentType = Client.ResponseHeaders[HttpResponseHeader.ContentType]; int size = 0; if (int.TryParse(Client.ResponseHeaders[HttpResponseHeader.ContentLength], out size)) { File.Size = size; } File.Base64 = Convert.ToBase64String(data); File.Downloaded = DateTime.Now; File.FileExtension = GetDefaultExtension(File.ContentType); } return(File); }
public BingMaps GetMapImageByLocation() { /* need to: * pushpin co-ordinates * pushpint label * map type - aerialwithlabels, etc * image format - jpeg, png, * map layer * */ BingMapsHelper Bing = new BingMapsHelper(ServiceConfiguration["BingMapsKey"].ToString()); DownloadedFile file = Bing.GetMapImageByLocation(this.Query, this.ImageZoom, this.MapStyle, this.ImageWidth, this.ImageHeight, "", this.ImageFormat, false); //BingResult res = Bing.GetMapImageMetadata(decimal.Parse(this.Lat).ToString(_decimalFormat), decimal.Parse(this.Lon).ToString(_decimalFormat), this.ImageZoom, this.MapStyle, this.ImageWidth, this.ImageHeight, "", null, this.ImageFormat, false); //BingResult res = Bing.SearchByLocation(this.Query, 1); //if (res == null) //{ // this.ResultStatus = "Error"; // this.ResultMessage = "Failed to download and deserialize result"; // return this; //} if (file == null) { this.ResultStatus = "OK"; this.ResultMessage = "No results"; return(this); } //if (res.resourceSets == null || res.resourceSets.Count() < 1 || res.resourceSets[0].resources == null || res.resourceSets[0].resources.Count() < 1) //{ // Resource resource = res.resourceSets[0].resources[0]; // MapBingMaps(this, resource); //} this.ImageBase64 = file.Base64; this.ImageSize = file.Size; string filename = Guid.NewGuid() + file.FileExtension; this.ImageFilename = filename; this.ImageContentType = file.ContentType; // nothing specied so set defaults if (this.ImageWidth == 0) { this.ImageWidth = 300; } if (this.ImageHeight == 0) { this.ImageHeight = 300; } if (this.ImageZoom == 0) { this.ImageZoom = 10; } //this.EstimatedTotal = res.resourceSets[0].estimatedTotal; FileProperty fp = new FileProperty() { Content = this.ImageBase64, FileName = filename }; this.Image = fp.Value.ToString(); this.ResultStatus = "OK"; return(this); }
public BingMaps GetMapImageByLatLon() { /* need to: * pushpin co-ordinates * pushpint label * map type - aerialwithlabels, etc * image format - jpeg, png, * map layer * */ try { float.Parse(this.Lat); float.Parse(this.Lon); } catch (Exception ex) { this.ResultStatus = "Error"; this.ResultMessage = "Latitude and Longitude must be supplied as a float xxx.xxxxxx"; return(this); } BingMapsHelper Bing = new BingMapsHelper(ServiceConfiguration["BingMapsKey"].ToString()); PushPin p = new PushPin() { //Latitude = float.Parse(this.Lat), //Longitude = float.Parse(this.Lon), Latitude = this.Lat, Longitude = this.Lon, }; List <PushPin> pins = new List <PushPin>(); pins.Add(p); DownloadedFile file = Bing.GetMapImage(decimal.Parse(this.Lat).ToString(_decimalFormat), decimal.Parse(this.Lon).ToString(_decimalFormat), this.ImageZoom, this.MapStyle, this.ImageWidth, this.ImageHeight, "", pins, this.ImageFormat, false); //BingResult res = Bing.GetMapImageMetadata(decimal.Parse(this.Lat).ToString(_decimalFormat), decimal.Parse(this.Lon).ToString(_decimalFormat), this.ImageZoom, this.MapStyle, this.ImageWidth, this.ImageHeight, "", pins, this.ImageFormat, false); //BingResult res = Bing.SearchByPoint(decimal.Parse(this.Lat).ToString(_decimalFormat), decimal.Parse(this.Lon).ToString(_decimalFormat), ""); //BingResult res = Bing.SearchByPoint(this.Lat, this.Lon, ""); //if (res == null) //{ // this.ResultStatus = "Error"; // this.ResultMessage = "Failed to download and deserialize result"; // return this; //} if (file == null) { this.ResultStatus = "OK"; this.ResultMessage = "No results"; return(this); } //if (res.resourceSets == null || res.resourceSets.Count() < 1 || res.resourceSets[0].resources == null || res.resourceSets[0].resources.Count() < 1) //{ // Resource resource = res.resourceSets[0].resources[0]; // MapBingMaps(this, resource); //} this.ImageBase64 = file.Base64; this.ImageSize = file.Size; string filename = Guid.NewGuid() + file.FileExtension; this.ImageFilename = filename; this.ImageContentType = file.ContentType; // this.EstimatedTotal = res.resourceSets[0].estimatedTotal; FileProperty fp = new FileProperty() { Content = this.ImageBase64, FileName = filename }; this.Image = fp.Value.ToString(); // nothing specied so set defaults if (this.ImageWidth == 0) { this.ImageWidth = 300; } if (this.ImageHeight == 0) { this.ImageHeight = 300; } if (this.ImageZoom == 0) { this.ImageZoom = 10; } this.ResultStatus = "OK"; return(this); }