public async Task SetSingleVariableAsync(ScopedVariableJsonModel variable) { if (string.IsNullOrEmpty(variable.Server) && string.IsNullOrEmpty(variable.ServerRole) && string.IsNullOrEmpty(variable.Environment)) { throw new InvalidOperationException("Specified variable requires at least one scope (server, role, or environment)."); } using (var client = this.CreateClient()) { string url = "api/variables/scoped/single"; this.LogRequest(url); using (var stream = new SlimMemoryStream()) using (var writer = new StreamWriter(stream)) { JsonSerializer.CreateDefault().Serialize(writer, variable); await writer.FlushAsync().ConfigureAwait(false); stream.Position = 0; using (var content = new StreamContent(stream)) using (var response = await client.PostAsync(url, content).ConfigureAwait(false)) { await HandleError(response).ConfigureAwait(false); } } } }
private Stream OpenEntry(TreeEntry entry) { if (!(entry.Target is Blob blob)) { return(null); } using (var s = blob.GetContentStream()) { var buffer = new SlimMemoryStream(); s.CopyTo(buffer); buffer.Position = 0; return(buffer); } }
private void SaveVariables() { var repo = this.lazyRepository.Value; using (var buffer = new SlimMemoryStream()) { var writer = new StreamWriter(buffer, InedoLib.UTF8Encoding); WriteStandardVariableData(this.lazyVariables.Value, writer); writer.Flush(); buffer.Position = 0; var blob = repo.ObjectDatabase.CreateBlob(buffer, "variables"); this.lazyCurrentTree.Value.Add(string.IsNullOrEmpty(this.RepositoryRoot) ? "variables" : PathEx.Combine('/', this.RepositoryRoot, "variables"), blob, Mode.NonExecutableFile); this.dirty = true; } }