public static RestaurantBasicData RestaurantOsmToRestaurantBasicData(this RestaurantOsm restOsm, RestaurantBasicData basicRest) { bool modifiedFlag = false; try { if (restOsm != null && basicRest != null) { string restOsmName = restOsm.Name != null ? restOsm.Name : ""; string basicRestName = basicRest.Name != null ? basicRest.Name : ""; log.InfoFormat("[RestaurantOsmToRestaurantBasicData] restOsm.Id={0}, restOsm.Name={1}, basicRest.Id={2}, basicRest.Name={3}.", restOsm.Id.ToString(), restOsmName, basicRest.Id.ToString(), basicRestName); if (restOsm.Name != null && basicRest.Name == null) { basicRest.Name = restOsm.Name; modifiedFlag = true; } if (restOsm.LocalizedName != null && basicRest.LocalizedName == null) { basicRest.LocalizedName = restOsm.LocalizedName; modifiedFlag = true; } if (restOsm.Description != null && basicRest.Description == null) { basicRest.Description = restOsm.Description; modifiedFlag = true; } if (restOsm.LocalizedDescription != null && basicRest.LocalizedDescription == null) { basicRest.LocalizedDescription = restOsm.LocalizedDescription; modifiedFlag = true; } if (restOsm.Operator != null && basicRest.Operator == null) { basicRest.Operator = restOsm.Operator; modifiedFlag = true; } else { string restOperator; if (restOsm.NodeReference.tags.TryGetValue("operator", out restOperator)) { basicRest.Operator = restOperator; modifiedFlag = true; } else { if (restOsm.NodeReference.tags.TryGetValue("operator:en", out restOperator)) { basicRest.Operator = restOperator; modifiedFlag = true; } } } if (restOsm.ItemLocation != null && basicRest.ItemLocation == null) { basicRest.ItemLocation = restOsm.ItemLocation; modifiedFlag = true; } if (basicRest.Adress == null) { if (restOsm.ItemLocation != null) { GoogleAPIs.Services.Geocoding geocoding = new GoogleAPIs.Services.Geocoding(); Address tempAddr = geocoding.LocationToAdress(restOsm.ItemLocation); if (tempAddr != null) { Address addr = restOsm.Adress.CheckAttributes(tempAddr); if (addr != null) restOsm.Adress = addr; } } if (restOsm.Adress != null) { basicRest.Adress = restOsm.Adress; modifiedFlag = true; } } if (restOsm.Cuisine != null && basicRest.Cuisine == null) { basicRest.Cuisine = restOsm.Cuisine; modifiedFlag = true; } else { string restCuisine; if (restOsm.NodeReference.tags.TryGetValue("cuisine", out restCuisine)) { basicRest.Cuisine = restCuisine; modifiedFlag = true; } } if (restOsm.Phone != null && basicRest.Phone == null) { basicRest.Phone = restOsm.Phone; modifiedFlag = true; } if(modifiedFlag) return basicRest; log.ErrorFormat("[RestaurantOsmToRestaurantBasicData] basicRest not need to be updated."); return null; } else { log.ErrorFormat("[RestaurantOsmToRestaurantBasicData] resOsm or basicRest is null."); return null; } } catch (Exception e) { log.ErrorFormat("[RestaurantOsmToRestaurantBasicData] Exception={0}.", e); return null; } }
//====================================================================================================================== public static RestaurantBasicData RestaurantOsmToRestaurantBasicData(this RestaurantOsm restOsm) { try { string restOsmName = restOsm.Name != null ? restOsm.Name : ""; log.InfoFormat("[RestaurantOsmToRestaurantBasicData] restOsm.Id={0}, restOsm.Name={1}.", restOsm.Id, restOsmName); RestaurantBasicData basicRest = new RestaurantBasicData(); if (restOsm.Name != null) { basicRest.Name = restOsm.Name; } else { if (restOsm.LocalizedName != null && restOsm.LocalizedName.LocalizedList.Count > 0) { basicRest.Name = restOsm.LocalizedName.LocalizedList[0].Value; } } if (restOsm.LocalizedName != null) basicRest.LocalizedName = restOsm.LocalizedName; if (restOsm.Description != null) basicRest.Description = restOsm.Description; if (restOsm.LocalizedDescription != null) basicRest.LocalizedDescription = restOsm.LocalizedDescription; if (restOsm.Operator != null) basicRest.Operator = restOsm.Operator; else { string restOperator; if (restOsm.NodeReference.tags.TryGetValue("operator", out restOperator)) { basicRest.Operator = restOperator; } else { if (restOsm.NodeReference.tags.TryGetValue("operator:en", out restOperator)) { basicRest.Operator = restOperator; } } } Address tempAddr = null; if (restOsm.ItemLocation != null) { basicRest.ItemLocation = restOsm.ItemLocation; GoogleAPIs.Services.Geocoding geocoding = new GoogleAPIs.Services.Geocoding(); //tempAddr = geocoding.LocationToAdress(restOsm.ItemLocation); } if (restOsm.Adress != null) { if (tempAddr != null) { Address addr = restOsm.Adress.CheckAttributes(tempAddr); if (addr != null) restOsm.Adress = addr; } basicRest.Adress = restOsm.Adress; } else { if (tempAddr != null) basicRest.Adress = tempAddr; } if (restOsm.Cuisine != null) basicRest.Cuisine = restOsm.Cuisine; else { string restCuisine; if (restOsm.NodeReference.tags.TryGetValue("cuisine", out restCuisine)) { basicRest.Cuisine = restCuisine; } } if (restOsm.Phone != null) basicRest.Phone = restOsm.Phone; if (restOsm.Source != null) basicRest.Source = restOsm.Source; else basicRest.Source = "OpenStreetMap"; return basicRest; } catch (Exception e) { log.ErrorFormat("[RestaurantOsmToRestaurantBasicData] Exception={0}.", e); return null; } }