private void updateCommand(CommandLineApplication command)
        {
            var idOption           = command.Option("-id", "Guid of the map entry", CommandOptionType.SingleValue);
            var isBrowseableOption = command.Option("-isBrowseable", "", CommandOptionType.SingleValue);
            var descriptionOption  = command.Option("-description", "", CommandOptionType.SingleValue);

            command.OnExecute(() =>
            {
                if (!idOption.HasValue())
                {
                    command.Out.WriteLine("-id is required");
                    return(-1);
                }

                var map = _mapService.FindOneAsync(Guid.Parse(idOption.Value())).Result;

                if (map == null)
                {
                    command.Out.WriteLine($"No map with id {idOption.Value()} found.");
                    return(-1);
                }
                command.Out.WriteLine($"Updating map {map.Id} (Description={map.Description}, IsBrowseable={map.IsBrowseable})");

                if (isBrowseableOption.HasValue())
                {
                    map.IsBrowseable = isBrowseableOption.Value() == "1";
                    command.Out.WriteLine($"  Setting IsBrowseable to {map.IsBrowseable}");
                }
                if (descriptionOption.HasValue())
                {
                    map.Description = descriptionOption.Value();
                    command.Out.WriteLine($"  Setting Description to {map.Description}");
                }

                _mapService.ReplaceOneAsync(map).Wait();

                return(0);
            });
        }
        private void loadImageCommand(CommandLineApplication command)
        {
            var idOption        = command.Option("-id", "Guid of the map entry", CommandOptionType.SingleValue);
            var imagePathOption = command.Option("-imagePath", "Path to the image file to load",
                                                 CommandOptionType.SingleValue);

            command.OnExecute(() =>
            {
                var map   = _mapService.FindOneAsync(Guid.Parse(idOption.Value())).Result;
                var image = File.Open(imagePathOption.Value(), FileMode.Open, FileAccess.Read);

                var buffer = new byte[image.Length];
                image.Read(buffer, 0, (int)image.Length);

                Console.WriteLine($"Updating map image {map.Id} ({map.Description}) from {imagePathOption.Value()}...");

                var imageId   = _imageService.InsertOrUpdateImageAsync($"map:{map.Id}", buffer).Result;
                var imageInfo = _imageService.FindOneAsync(imageId).Result;
                Console.WriteLine(
                    $"Image record {imageId} has hash={imageInfo.ContentHashSha1}, last changed at {imageInfo.LastChangeDateTimeUtc} UTC");

                if (map.ImageId != imageId)
                {
                    map.ImageId = imageId;
                    map.Touch();
                    _mapService.ReplaceOneAsync(map);
                    Console.WriteLine("Map record has been updated.");
                }
                else
                {
                    Console.WriteLine("Map record has not changed.");
                }

                return(0);
            });
        }
Example #3
0
 public async Task <MapRecord> GetMapAsync([FromRoute] Guid Id)
 {
     return((await _mapService.FindOneAsync(Id)).Transient404(HttpContext));
 }