private CartoPlaceInfo CreateCleanPlaceInfo(CartoPlaceData data) { data.PlaceType = TextMutate.TrimSafe(data.PlaceType); data.PlaceTags = TextMutate.FixKeywords(data.PlaceTags); data.Timezone = TextMutate.TrimSafe(data.Timezone); data.Country = TextMutate.TrimSafe(data.Country); data.Region = TextMutate.TrimSafe(data.Region); data.Name = TextMutate.TrimSafe(data.Name); data.LocalName = TextMutate.TrimSafe(data.LocalName); data.DisplayAs = TextMutate.TrimSafe(data.DisplayAs); data.Description = TextMutate.TrimSafe(data.Description); data.Address = TextMutate.TrimSafe(data.Address); data.Locality = TextMutate.TrimSafe(data.Locality); data.Postcode = TextMutate.TrimSafe(data.Postcode); data.Subregions = TextMutate.TrimSafe(data.Subregions); data.Sublocalities = TextMutate.TrimSafe(data.Sublocalities); return(new CartoPlaceInfo(data)); }
/// <summary> /// Updates the trail metadata and synchronizes file and cache /// </summary> public ValidationServiceResponse <TopoTrailInfo> UpdateTrail(ITopoTrailUpdateRequest request) { // validate update request var response = ValidateUpdate(request); if (response.HasErrors) { return(response); } // process update request var trail = response.Data; // save current filename for later var existing = GetFilename(trail); // check file system if (!Directory.Exists(_rootUri)) { throw new Exception($"Directory not initalized: {_rootUri}"); } var folder = Path.Combine(_rootUri, trail.Country.Name); if (!Directory.Exists(folder)) { Directory.CreateDirectory(folder); } // update trail properties trail.Timezone = GeoTimezoneInfo.Find(request.Timezone); trail.Country = GeoCountryInfo.Find(request.Country); trail.Region = GeoRegionInfo.Find(request.Region); trail.Name = TextMutate.TrimSafe(request.Name); trail.Description = TextMutate.TrimSafe(request.Description); trail.Location = TextMutate.TrimSafe(request.Location); trail.Keywords = TextMutate.FixKeywords(request.Keywords); // TODO: BUG: fix url writing for v1.1 files! //trail.UrlLink = TextMutate.FixUrl(request.UrlLink); //trail.UrlText = TextMutate.TrimSafe(request.UrlText); // generate new and rename/remove existing files var filename = GetFilename(trail); // check if overwrite file var renamed = String.Compare(existing, filename, true) != 0; if (!renamed) { // temp rename current file File.Move(existing, existing + "~temp"); existing = existing + "~temp"; } // write new file var contents = BuildGpx(trail); File.WriteAllText(filename, contents); // delete old file File.Delete(existing); // refresh key and cache data if (renamed) { trail.Key = Path.GetFileNameWithoutExtension(filename).ToUpperInvariant(); _trails.Remove(request.Key.ToUpperInvariant()); _trails.Add(trail); } // return successful response return(response); }