/// <summary> /// /// </summary> /// <param name="alpha3Code"></param> /// <returns></returns> public HRCountryBorder GetBorderCountriesByAlpha3Code(string alpha3Code) { HRCountryBorder countryBorder = new HRCountryBorder(); string path = HttpContext.Current.Server.MapPath("~/App_Data/Boundaries.json"); try { FeatureCollection featureCollectionToCache = JsonConvert.DeserializeObject <FeatureCollection>(File.ReadAllText(path)); if (featureCollectionToCache != null) { int featuresCount = featureCollectionToCache.Features.Count; for (int i = 0; i < featuresCount; i++) { //!Pas en dur. if (featureCollectionToCache.Features[i].Properties != null && featureCollectionToCache.Features[i].Properties.Keys.Contains("ISO3")) { if (featureCollectionToCache.Features[i].Properties["ISO3"].ToString().ToLower() == alpha3Code.ToLower()) { countryBorder.alpha3Code = alpha3Code; FeatureCollection fCollection = new FeatureCollection(); fCollection.Features.Add(featureCollectionToCache.Features[i]); countryBorder.oGCFeature = JsonConvert.SerializeObject(fCollection); } } } } } catch (Exception ex) { LogException(ex, System.Reflection.MethodBase.GetCurrentMethod()); } return(countryBorder); }
/// <summary> /// 1- If Buffer is null /// 1.1- Asynchronous Load of jsonData file /// 1.2- ForEach Feature retrieved, add a new HRCountryBorder with ISO3/alpha3Code and Features/OgcFeature /// 2- Else retrun true /// Does not catch any Exception and throw one if data can not be reached. /// </summary> /// <returns>true or throw an exception if data can not be loaded</returns> private async Task <bool> InitAsync() { //1- if (_countriesBorderBuffer == null) { //1.1- if (_contentGetter != null) { FeatureCollection featureCollectionToCache = JsonConvert.DeserializeObject <FeatureCollection>(await _contentGetter.GetBoundariesData()); if (featureCollectionToCache != null) { lock (_locker) { _countriesBorderBuffer = new List <HRCountryBorder>(); int featuresCount = featureCollectionToCache.Features.Count; //1.2- for (int i = 0; i < featuresCount; i++) { HRCountryBorder border = new HRCountryBorder(); Feature featurei = featureCollectionToCache.Features[i]; if (featurei.Properties != null && featurei.Properties.Keys.Contains(Constant.BOUNDARIES_STUB.ISO3_PROPERTIE_NAME)) { border.alpha3Code = featurei.Properties[Constant.BOUNDARIES_STUB.ISO3_PROPERTIE_NAME].ToString(); FeatureCollection fCollection = new FeatureCollection(); fCollection.Features.Add(featurei); border.oGCFeature = JsonConvert.SerializeObject(fCollection); _countriesBorderBuffer.Add(border); } } } } else { throw new Exception(Constant.BOUNDARIES_STUB.NO_DATA_ERROR_MESSAGE); } } else { throw new Exception(Constant.BOUNDARIES_STUB.NO_DATA_ERROR_MESSAGE); } } return(true); }