public IActionResult Index() { using (StreamReader r = new StreamReader("JSON/set01.json")) { string json = r.ReadToEnd(); Models.Rootobject item = JsonConvert.DeserializeObject <Rootobject>(json); } //MVCCore.Utilities.DBSetUp.createDefaultLanguages(); return(View()); }
public T[] recieveData <T>(string entity, string operation) { string connectionString = String.Format("http://{0}:{1}/shop-management/shop-infrastructure/{2}/{3}", ConnectionParams.IpAddress, ConnectionParams.Port, operation, entity); WebRequest request = WebRequest.Create(connectionString); request.Method = "POST"; request.ContentType = "application/json"; WebResponse response = request.GetResponse(); Stream dataStream = response.GetResponseStream(); StreamReader reader = new StreamReader(dataStream); Models.Rootobject <T> list = JsonConvert.DeserializeObject <Models.Rootobject <T> >(reader.ReadToEnd()); reader.Close(); dataStream.Close(); response.Close(); return(list.body); }
public async Task <ResponsePackage> GetPartnerData(string baseUri, string reqUri, Models.Rootobject message) { ResponsePackage responsePackage = new ResponsePackage(); using (var client = new HttpClient()) { client.BaseAddress = new Uri(baseUri); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage Res = await client.PostAsJsonAsync(reqUri, message); if (Res.IsSuccessStatusCode) { var partnerResponse = Res.Content.ReadAsStringAsync().Result; responsePackage = JsonConvert.DeserializeObject <ResponsePackage>(partnerResponse); } return(responsePackage); } }
public async Task <Models.Weather> YRWeather(LoactionCoord location) { var correctComma = new CultureInfo("en-US"); XmlDocument doc = new XmlDocument(); var yrroot = new Models.Rootobject(); var url = $"https://api.met.no/weatherapi/locationforecast/1.9/?lat={location.Latitude}&lon={location.Longitude}"; var weatherInfo = await _http.Get(url); doc.LoadXml(weatherInfo); string data = JsonConvert.SerializeXmlNode(doc); data = data.Replace("@", ""); var a = DateTime.UtcNow.AddHours(2); DateTime to = new DateTime(a.Year, a.Month, a.Day, a.Hour, 0, 0, 0); DateTime from = new DateTime(a.Year, a.Month, a.Day, a.Hour + 1, 0, 0, 0); yrroot = JsonConvert.DeserializeObject <Models.Rootobject>(data); var rootNow = yrroot.weatherdata.product.time.FirstOrDefault(x => x.from == to).location; var rootToGetIcon = yrroot.weatherdata.product.time.FirstOrDefault(x => x.from == to && x.to == from).location.symbol; var forecastTemp = new List <Forecast>(); var forecast = new List <Forecast>(); var prog00t = yrroot.weatherdata.product.time.FirstOrDefault(x => x.from.Hour == 00 && x.to.Hour == 00).location.temperature.value; var prog00s = yrroot.weatherdata.product.time.FirstOrDefault(x => x.from.Hour == 00 && x.to.Hour == 01).location.symbol.number; forecastTemp.Add(new Forecast { Temperatur = float.Parse(prog00t, correctComma.NumberFormat), ImgIcon = prog00s, Time = "00" }); var prog03t = float.Parse(yrroot.weatherdata.product.time.FirstOrDefault(x => x.from.Hour == 03 && x.to.Hour == 03).location.temperature.value, correctComma.NumberFormat); var prog03s = yrroot.weatherdata.product.time.FirstOrDefault(x => x.from.Hour == 03 && x.to.Hour == 04).location.symbol.number; forecastTemp.Add(new Forecast { Temperatur = prog03t, ImgIcon = prog03s, Time = "03" }); var prog06t = float.Parse(yrroot.weatherdata.product.time.FirstOrDefault(x => x.from.Hour == 06 && x.to.Hour == 06).location.temperature.value, correctComma.NumberFormat); var prog06s = yrroot.weatherdata.product.time.FirstOrDefault(x => x.from.Hour == 06 && x.to.Hour == 07).location.symbol.number; forecastTemp.Add(new Forecast { Temperatur = prog06t, ImgIcon = prog06s, Time = "06" }); var prog09t = float.Parse(yrroot.weatherdata.product.time.FirstOrDefault(x => x.from.Hour == 09 && x.to.Hour == 09).location.temperature.value, correctComma.NumberFormat); var prog09s = yrroot.weatherdata.product.time.FirstOrDefault(x => x.from.Hour == 09 && x.to.Hour == 10).location.symbol.number; forecastTemp.Add(new Forecast { Temperatur = prog09t, ImgIcon = prog09s, Time = "09" }); var prog12t = float.Parse(yrroot.weatherdata.product.time.FirstOrDefault(x => x.from.Hour == 12 && x.to.Hour == 12).location.temperature.value, correctComma.NumberFormat); var prog12s = yrroot.weatherdata.product.time.FirstOrDefault(x => x.from.Hour == 12 && x.to.Hour == 13).location.symbol.number; forecastTemp.Add(new Forecast { Temperatur = prog12t, ImgIcon = prog12s, Time = "12" }); var prog15t = float.Parse(yrroot.weatherdata.product.time.FirstOrDefault(x => x.from.Hour == 15 && x.to.Hour == 15).location.temperature.value, correctComma.NumberFormat); var prog15s = yrroot.weatherdata.product.time.FirstOrDefault(x => x.from.Hour == 15 && x.to.Hour == 16).location.symbol.number; forecastTemp.Add(new Forecast { Temperatur = prog15t, ImgIcon = prog15s, Time = "15" }); var prog18t = float.Parse(yrroot.weatherdata.product.time.FirstOrDefault(x => x.from.Hour == 18 && x.to.Hour == 18).location.temperature.value, correctComma.NumberFormat); var prog18s = yrroot.weatherdata.product.time.FirstOrDefault(x => x.from.Hour == 18 && x.to.Hour == 19).location.symbol.number; forecastTemp.Add(new Forecast { Temperatur = prog18t, ImgIcon = prog18s, Time = "18" }); var prog21t = float.Parse(yrroot.weatherdata.product.time.FirstOrDefault(x => x.from.Hour == 21 && x.to.Hour == 21).location.temperature.value, correctComma.NumberFormat); var prog21s = yrroot.weatherdata.product.time.FirstOrDefault(x => x.from.Hour == 21 && x.to.Hour == 22).location.symbol.number; forecastTemp.Add(new Forecast { Temperatur = prog21t, ImgIcon = prog21s, Time = "21" }); foreach (var item in forecastTemp) { var t = new DateTime(a.Year, a.Month, a.Day, int.Parse(item.Time), 0, 0, 0); item.ImgIcon = GetImgIcon(float.Parse(item.ImgIcon, correctComma.NumberFormat), t); forecast.Add(item); } var nått = forecast.Where(x => int.Parse(x.Time) > a.Hour).ToList(); nått.RemoveRange(3, nått.Count - 3); var unformatedDesc = rootToGetIcon.id; var imgIconUrl = float.Parse(rootToGetIcon.number); string pattern = $"([a-z](?=[A-Z])|[A-Z](?=[A-Z][a-z]))"; var desc = Regex.Replace(unformatedDesc, pattern, "$1 "); var img = rootToGetIcon.number; var temp = rootNow.temperature.value; var humid = rootNow.humidity.value; var wind = rootNow.windSpeed.mps; string prec; if (rootNow.precipitation == null) { prec = "0"; } else { prec = rootNow.precipitation.value; } return(new Models.Weather { Temperatur = float.Parse(temp, correctComma.NumberFormat), Loc = location, Description = desc, Humidity = float.Parse(humid, correctComma.NumberFormat), Wind = float.Parse(wind, correctComma.NumberFormat), ImgIcon = GetImgIcon(imgIconUrl, a), Precipitation = float.Parse(prec, correctComma.NumberFormat), Supplier = new WeatherSupplier { Name = "YR.no" }, Forecasts = nått.ToList(), Updated = DateTime.UtcNow.AddHours(2) }); }