예제 #1
0
        public async Task CreateBeerReport()
        {
            /* Get the weather information */
            log.LogInformation($"Getting weather forecast of Amsterdam on {DateTime.Today}");
            string json = await GetWeatherInformation();

            /* Filter the weather Information to get only the date and average celcius of today */
            WeatherInformation weatherInformation = GetNecessaryInformation(json);

            // WeatherInformation weatherInformation = new WeatherInformation(DateTime.Now, 12); // <----- THIS IS HERE BECAUSE MY WEATHERAPI ONLY ALLOWS 50 CALLS EACH DAY, SO I NEEDED TEST DATA!!!!

            /* Send the data to the queue */
            log.LogInformation($"Sending weather data to the Queue");
            SendDataToQueue(weatherInformation);
        }
예제 #2
0
        /* Send the important weather information to the queue to trigger the queue */
        public void SendDataToQueue(WeatherInformation weatherInformation)
        {
            string jsonData = JsonConvert.SerializeObject(weatherInformation);

            try {
                /* Make the azure services */
                CloudQueueClient cloudQueueClient = cloudStorageAccount.CreateCloudQueueClient();
                CloudQueue       cloudQueue       = cloudQueueClient.GetQueueReference("beerqueue");

                /* Create a queue if it doesnt exist already and pass the JSON as message to the queue */
                cloudQueue.CreateIfNotExists();
                cloudQueue.AddMessage(new CloudQueueMessage(jsonData));
            } catch (Exception) {
                throw new ServiceUnavailableException();
            }
        }
예제 #3
0
        public static async void Run([QueueTrigger("beerqueue", Connection = "AzureWebJobsStorage")] string weatherQueue, ILogger log)
        {
            log.LogInformation($"beerqueue triggered");
            /* Parse JSON to Weather object */
            WeatherInformation weatherInformation = JsonConvert.DeserializeObject <WeatherInformation>(weatherQueue);

            /* Make a Map object to perform image and blob actions */
            MapImage mapImage = new MapImage(weatherInformation);

            /* Replace the ',' sign with '.' to ensure that the coordinate values URLAmsterdamMap are doubles with dots to ensure 2 coordinates instead of 4 */
            NumberFormatInfo nfi = new NumberFormatInfo();

            nfi.NumberDecimalSeparator = ".";

            /* Get the coordinates of Amsterdam with '.' sign instead of ','*/
            string longitude = weatherInformation.Longitude.ToString(nfi);
            string latitude  = weatherInformation.Latitude.ToString(nfi);

            /* Azure MAPS API call URL with the given key and Amsterdam coordinates */
            string URLAmsterdamMap = $"https://atlas.microsoft.com/map/static/png?subscription-key={EnvironmentStrings.AzureMaps}&api-version=1.0&style=main&zoom=11&center={longitude},{latitude}&height=1024&width=1024";

            /* Try to execute the Azure API GET call to get the Map */
            Stream result = null;

            try {
                HttpClient         newClient  = new HttpClient();
                HttpRequestMessage newRequest = new HttpRequestMessage(HttpMethod.Get, string.Format(URLAmsterdamMap));

                log.LogInformation($"Calling Azure Maps API");
                HttpResponseMessage response = await newClient.SendAsync(newRequest);

                /* Read the result and put it in a Stream (this is the image of a map of Amsterdam */
                result = await response.Content.ReadAsStreamAsync();
            }catch (Exception) {
                throw new BadRequestException();
            }

            /* Try to upload the map to the blob storage */
            try {
                log.LogInformation($"Uploading image to blob storage");
                mapImage.UploadImageToBlob(result);
            }catch (Exception) {
                throw new UploadException();
            }
        }
예제 #4
0
 public MapImage(WeatherInformation weatherInformation)
 {
     this.weatherInformation = weatherInformation;
 }