Esempio n. 1
0
        public void WriteToJsonFileTest()
        {
            string path          = "D:\\Weather Info\\Source";
            var    directoryInfo = FileIOHelper.CreateDestinationFolder(path);
            var    now           = DateTime.Now;
            var    yearName      = now.ToString("yyyy");
            var    monthName     = now.ToString("MMMM");
            var    dayName       = now.ToString("dd-MM-yyyy");
            string filepath      = $"{path}\\{yearName}\\{monthName}\\{dayName}";


            City city = new City()
            {
                Cityname = "London", CityId = "2643741"
            };

            IWeatherFetcher wf                  = new WeatherFetcher("http://api.openweathermap.org", "aa69195559bd4f88d79f9aadeb77a8f6");
            var             currentWeather      = wf.GetCurrentWeather(city.CityId);
            var             destinationFilepath = $"{filepath}\\{city.Cityname}_{city.CityId}.txt";

            FileIOHelper.WriteToJsonFile <CurrentWeather>(destinationFilepath, currentWeather, append: false);

            var DoesFileExist = File.Exists(destinationFilepath);

            Assert.IsTrue(DoesFileExist);
        }
Esempio n. 2
0
        public async Task <IActionResult> Index(IFormFile file)
        {
            if (file == null || file.Length == 0)
            {
                return(Content("file not selected"));
            }

            var destPath = _configuration["DestinationDir"];

            using (var stream = new FileStream(file.FileName, FileMode.Create))
            {
                await file.CopyToAsync(stream);
            }

            IEnumerable <City> cities = FileIOHelper.ReadFromFile(file.FileName);

            Parallel.ForEach(cities, (currentCity) =>
            {
                IWeatherFetcher wf = new WeatherFetcher(_configuration["WeatherAPIUrl"], _configuration["WeatherAPIKey"]);
                var currentWeather = wf.GetCurrentWeather(currentCity.CityId);
                var dirInfo        = FileIOHelper.CreateDestinationFolder(destPath);
                FileIOHelper.WriteToJsonFile <CurrentWeather>($"{dirInfo.FullName}\\{currentCity.Cityname}_{currentCity.CityId} .txt", currentWeather, append: false);
            });

            ViewBag.Message = string.Format("Report generated at specified destination path.\\nCurrent Date and Time: {0}", DateTime.Now.ToString());
            return(View());
        }
Esempio n. 3
0
        public void CreateDestinationFolder()
        {
            string path          = "D:\\Weather Info\\Source";
            var    directoryInfo = FileIOHelper.CreateDestinationFolder(path);
            var    now           = DateTime.Now;
            var    yearName      = now.ToString("yyyy");
            var    monthName     = now.ToString("MMMM");
            var    dayName       = now.ToString("dd-MM-yyyy");
            var    doesFileExits = Directory.Exists($"{path}\\{yearName}\\{monthName}\\{dayName}");

            Assert.IsTrue(doesFileExits, "Folder created successfully.");
        }