public async Task <ArangoVoid> ReplaceServiceAsync(ArangoHandle database, string mount, ArangoFoxxSource service, bool?teardown = null, bool?setup = null, bool?legacy = null, bool?force = null, CancellationToken cancellationToken = default) { var parameter = new Dictionary <string, string> { { "mount", mount } }; if (teardown.HasValue) { parameter.Add("teardown", teardown.Value.ToString().ToLowerInvariant()); } if (setup.HasValue) { parameter.Add("setup", setup.Value.ToString().ToLowerInvariant()); } if (legacy.HasValue) { parameter.Add("legacy", legacy.Value.ToString().ToLowerInvariant()); } if (force.HasValue) { parameter.Add("force", force.Value.ToString().ToLowerInvariant()); } var res = await Context.Configuration.Transport.SendContentAsync(HttpMethod.Put, ApiPath(database, "foxx/service", parameter), PackService(service), cancellationToken : cancellationToken); return(new ArangoVoid()); }
private MultipartFormDataContent PackService(ArangoFoxxSource service) { var content = new MultipartFormDataContent(); if (service.JavaScript != null) { content.Add(new StringContent(service.JavaScript, Encoding.UTF8, "application/javascript"), "source"); } else if (service.Url != null) { content.Add(new StringContent(service.Url), "source"); } else if (service.ZipArchive != null) { var stream = new StreamContent(service.ZipArchive); stream.Headers.ContentType = new MediaTypeHeaderValue("application/zip"); content.Add(stream, "source"); } else { throw new ArangoException("Invalid service description"); } return(content); }
public async Task InstallZip() { await SetupAsync("system-camel"); await Arango.Foxx.InstallServiceAsync("test", "/sample/service", ArangoFoxxSource.FromZip(await BuildService("world"))); await Arango.Foxx.ReplaceConfigurationAsync("test", "/sample/service", new { currency = "€", secretKey = "s3cr3t" }); var services = await Arango.Foxx.ListServicesAsync("test", true); Assert.Single(services); Assert.Equal("/sample/service", services.First().Mount); var res = await Arango.Foxx.GetAsync <Dictionary <string, string> >("test", "/sample/service/hello-world"); Assert.Equal("world", res["hello"]); await Arango.Foxx.UpgradeServiceAsync("test", "/sample/service", ArangoFoxxSource.FromZip(await BuildService("universe"))); var res2 = await Arango.Foxx.GetAsync <Dictionary <string, string> >("test", "/sample/service/hello-world"); Assert.Equal("universe", res2["hello"]); await Arango.Foxx.UninstallServiceAsync("test", "/sample/service"); services = await Arango.Foxx.ListServicesAsync("test", true); Assert.Empty(services); }
public async Task InstallScript() { await SetupAsync("system-camel"); await Arango.Foxx.InstallServiceAsync("test", "/sample/service", ArangoFoxxSource.FromJavaScript(@" 'use strict'; const createRouter = require('@arangodb/foxx/router'); const router = createRouter(); module.context.use(router); router.get('/hello-world', function (req, res) { res.send('Hello World!'); }) .response(['text/plain'], 'A generic greeting.') .summary('Generic greeting') .description('Prints a generic greeting.'); ")); var services = await Arango.Foxx.ListServicesAsync("test", true); Assert.Single(services); Assert.Equal("/sample/service", services.First().Mount); }