Changed File Structure of Repository
This commit is contained in:
		
							
								
								
									
										27
									
								
								Controllers/AppController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								Controllers/AppController.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,27 @@
 | 
			
		||||
using Microsoft.AspNetCore.Mvc;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using METAR_Web_App.Controllers.METAR;
 | 
			
		||||
using METAR_Web_App.Models;
 | 
			
		||||
 | 
			
		||||
namespace METAR_Web_App.Controllers
 | 
			
		||||
{
 | 
			
		||||
    public class AppController : Controller
 | 
			
		||||
    {
 | 
			
		||||
        public WeatherService weatherService = new WeatherService();
 | 
			
		||||
 | 
			
		||||
        public async Task<IActionResult> ICAO(string ICAO)
 | 
			
		||||
        {
 | 
			
		||||
            if (ICAO != null)
 | 
			
		||||
            {
 | 
			
		||||
                WeatherInformation weatherInformation = await weatherService.getInformation(ICAO);
 | 
			
		||||
 | 
			
		||||
                return View(weatherInformation);
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                return View();
 | 
			
		||||
            }   
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										37
									
								
								Controllers/HomeController.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								Controllers/HomeController.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,37 @@
 | 
			
		||||
using METAR_Web_App.Models;
 | 
			
		||||
using Microsoft.AspNetCore.Mvc;
 | 
			
		||||
using Microsoft.Extensions.Logging;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Diagnostics;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
 | 
			
		||||
namespace METAR_Web_App.Controllers
 | 
			
		||||
{
 | 
			
		||||
    public class HomeController : Controller
 | 
			
		||||
    {
 | 
			
		||||
        private readonly ILogger<HomeController> _logger;
 | 
			
		||||
 | 
			
		||||
        public HomeController(ILogger<HomeController> logger)
 | 
			
		||||
        {
 | 
			
		||||
            _logger = logger;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public IActionResult Index(string ICAO)
 | 
			
		||||
        {
 | 
			
		||||
            return View();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public IActionResult Privacy()
 | 
			
		||||
        {
 | 
			
		||||
            return View();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
 | 
			
		||||
        public IActionResult Error()
 | 
			
		||||
        {
 | 
			
		||||
            return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										118
									
								
								Controllers/METAR/WeatherService.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										118
									
								
								Controllers/METAR/WeatherService.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,118 @@
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Threading.Tasks;
 | 
			
		||||
using libmetar.Services;
 | 
			
		||||
using METAR_Web_App.Models;
 | 
			
		||||
 | 
			
		||||
namespace METAR_Web_App.Controllers.METAR
 | 
			
		||||
{
 | 
			
		||||
    public class WeatherService
 | 
			
		||||
    {
 | 
			
		||||
 | 
			
		||||
        private MetarService metarService { get; set; } = new MetarService();
 | 
			
		||||
        private List<string> METAR { get; set; } = new List<string>();
 | 
			
		||||
        private TafService tafService { get; set; } = new TafService();
 | 
			
		||||
        private List<string> TAF { get; set; } = new List<string>();
 | 
			
		||||
        private string ICAO { get; set; }
 | 
			
		||||
        private bool isValid { get; set; } = false;
 | 
			
		||||
 | 
			
		||||
        public async Task<WeatherInformation> getInformation(string ICAO)
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
            WeatherInformation weatherInformation = new WeatherInformation();
 | 
			
		||||
 | 
			
		||||
            weatherInformation.ICAO = ICAO.Trim();
 | 
			
		||||
 | 
			
		||||
            if (setICAO(weatherInformation.ICAO) == true)
 | 
			
		||||
            {
 | 
			
		||||
                //METAR
 | 
			
		||||
                var METAR = getMETAR();
 | 
			
		||||
                //TAF
 | 
			
		||||
                var TAF = getTAF();
 | 
			
		||||
 | 
			
		||||
                weatherInformation.METAR = await METAR;
 | 
			
		||||
                weatherInformation.TAF = await TAF;
 | 
			
		||||
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                weatherInformation.ICAOError = true;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
            return weatherInformation;
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //* ------------------Setter Functions ---------------------------*
 | 
			
		||||
        private bool setICAO(string ICAO)
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
            if (ICAO.Length == 4)
 | 
			
		||||
            {
 | 
			
		||||
                this.ICAO = ICAO.ToUpper();
 | 
			
		||||
                isValid = true;
 | 
			
		||||
            }
 | 
			
		||||
            else
 | 
			
		||||
            {
 | 
			
		||||
                isValid = false;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return isValid;
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
        //*--------------------------------------------------------------*
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
        //*-------------------- App Functions ---------------------------*
 | 
			
		||||
        private async Task<List<string>> getMETAR()
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
            METAR.Clear();
 | 
			
		||||
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                var downloadedMETAR = await metarService.GetRawAsync(ICAO);
 | 
			
		||||
 | 
			
		||||
                METAR.Add(downloadedMETAR.Raw);
 | 
			
		||||
 | 
			
		||||
                return METAR;
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception)
 | 
			
		||||
            {
 | 
			
		||||
                return null;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            
 | 
			
		||||
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private async Task<List<string>> getTAF()
 | 
			
		||||
        {
 | 
			
		||||
 | 
			
		||||
            TAF.Clear();
 | 
			
		||||
 | 
			
		||||
            //Try statement to collect the data from the server
 | 
			
		||||
 | 
			
		||||
            try
 | 
			
		||||
            {
 | 
			
		||||
                var downloadedTAF = await tafService.GetRawAsync(ICAO);
 | 
			
		||||
 | 
			
		||||
                foreach (var line in downloadedTAF.RawSplit)
 | 
			
		||||
                {
 | 
			
		||||
                    TAF.Add(line);
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return TAF;
 | 
			
		||||
            }
 | 
			
		||||
            catch (Exception)
 | 
			
		||||
            {
 | 
			
		||||
                return null;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        //*--------------------------------------------------------------*
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user