Exemple #1
0
        public ActionResult Modify(string key, string name, string description)
        {
            var model = InitModel();

            var track = _trackEditService.GetTrack(key);

            track.Name        = TextMutate.TrimSafe(name);
            track.Description = TextMutate.TrimSafe(description);

            model.EditTrack      = InitEditModel(track);
            model.ConfirmMessage = $"Updated at {DateTime.Now}";

            return(View(model));
        }
        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);
        }
        public CartoPlaceInfo(GoogleLocationResult result)
        {
            _raw  = result.RawJson;
            _data = new CartoPlaceData();

            _data.PlaceKey  = result.PlaceID;
            _data.GoogleKey = result.PlaceID;

            _data.PlaceType = result.TypedNameSource;

            _data.Name        = TextMutate.StripAccents(result.ShortName);
            _data.LocalName   = (_data.Name == result.LongName ? "" : result.LongName);
            _data.DisplayAs   = (_data.Name == result.TypedName ? "" : result.TypedName);
            _data.Description = result.ColloquialArea;

            //data.Timezone = // TODO: determine timezone
            _data.Country = result.Country;
            _data.Region  = result.Region;

            _data.Subregions = "";
            if (!String.IsNullOrWhiteSpace(result.Region2))
            {
                _data.Subregions += result.Region2;
            }
            if (!String.IsNullOrWhiteSpace(result.Region3))
            {
                _data.Subregions += @" \ " + result.Region3;
            }
            if (!String.IsNullOrWhiteSpace(result.Region4))
            {
                _data.Subregions += @" \ " + result.Region4;
            }
            if (!String.IsNullOrWhiteSpace(result.Region5))
            {
                _data.Subregions += @" \ " + result.Region5;
            }

            var address = $"{result.StreeNumber} {result.Route}";

            _data.Address  = (String.IsNullOrWhiteSpace(address) ? result.Intersection : address);
            _data.Postcode = result.PostalCode;

            /*
             * _data.Premise = result.Premise;
             * if (!String.IsNullOrWhiteSpace(result.SubPremise)) _data.Premise += @" \ " + result.SubPremise;
             */

            _data.Locality      = result.Locality;
            _data.Sublocalities = result.SubLocality;

            _data.CenterLatitude  = result.Center.Latitude;
            _data.CenterLongitude = result.Center.Longitude;

            _data.NorthLatitude = result.Bounds.NorthWest.Latitude;
            _data.WestLongitude = result.Bounds.NorthWest.Longitude;
            _data.SouthLatitude = result.Bounds.SouthEast.Latitude;
            _data.EastLongitude = result.Bounds.SouthEast.Longitude;

            // update place type based on current data
            MapPlaceType();
        }