Skip to content

Commit 096803d

Browse files
committed
Minor.
1 parent ce98331 commit 096803d

9 files changed

Lines changed: 52 additions & 50 deletions

File tree

examples/DIExample/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using System.Threading;
21
using Gotenberg.Sharp.API.Client;
32
using Gotenberg.Sharp.API.Client.Domain.Builders;
43
using Gotenberg.Sharp.API.Client.Domain.Builders.Faceted;
54
using Gotenberg.Sharp.API.Client.Domain.Requests;
65
using Gotenberg.Sharp.API.Client.Domain.Settings;
76
using Gotenberg.Sharp.API.Client.Extensions;
7+
88
using Microsoft.Extensions.Configuration;
99
using Microsoft.Extensions.DependencyInjection;
1010
using Microsoft.Extensions.Logging;
@@ -29,7 +29,7 @@
2929

3030
var resultPath = Path.Combine(saveToPath, $"GotenbergFromUrl-{DateTime.Now:yyyyMMddHHmmss}.pdf");
3131

32-
using (var destinationStream = File.Create(resultPath))
32+
await using (var destinationStream = File.Create(resultPath))
3333
{
3434
await response.CopyToAsync(destinationStream, CancellationToken.None);
3535
}
@@ -63,8 +63,8 @@ Task<UrlRequest> CreateUrlRequest()
6363
.WithPageProperties(b =>
6464
{
6565
b.SetPaperSize(PaperSizes.A4)
66-
.SetMargins(Margins.None);
66+
.SetMargins(Margins.None);
6767
});
6868

6969
return builder.BuildAsync();
70-
}
70+
}

examples/HtmlConvert/Program.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using Gotenberg.Sharp.API.Client;
22
using Gotenberg.Sharp.API.Client.Domain.Builders;
3-
using Gotenberg.Sharp.API.Client.Domain.Builders.Faceted;
43
using Gotenberg.Sharp.API.Client.Domain.Settings;
54
using Gotenberg.Sharp.API.Client.Infrastructure.Pipeline;
5+
66
using Microsoft.Extensions.Configuration;
77

88
var config = new ConfigurationBuilder()
@@ -30,15 +30,16 @@ static async Task<string> CreateFromHtml(string destinationDirectory, string res
3030

3131
using var httpClient = new HttpClient(authHandler ?? (HttpMessageHandler)handler)
3232
{
33-
BaseAddress = options.ServiceUrl
33+
BaseAddress = options.ServiceUrl,
34+
Timeout = options.TimeOut
3435
};
3536

3637
var sharpClient = new GotenbergSharpClient(httpClient);
3738

3839
var builder = new HtmlRequestBuilder()
39-
.AddAsyncDocument(async doc =>
40+
.AddAsyncDocument(async doc =>
4041
doc.SetBody(await GetHtmlFile(resourcePath, "body.html"))
41-
.SetFooter(await GetHtmlFile(resourcePath, "footer.html"))
42+
.SetFooter(await GetHtmlFile(resourcePath, "footer.html"))
4243
).WithPageProperties(dims => dims.UseChromeDefaults())
4344
.WithAsyncAssets(async assets =>
4445
assets.AddItem("ear-on-beach.jpg", await GetImageBytes(resourcePath))
@@ -53,10 +54,8 @@ static async Task<string> CreateFromHtml(string destinationDirectory, string res
5354
var resultPath = Path.Combine(destinationDirectory, $"GotenbergFromHtml-{DateTime.Now:yyyyMMddHHmmss}.pdf");
5455
var response = await sharpClient.HtmlToPdfAsync(request);
5556

56-
using (var destinationStream = File.Create(resultPath))
57-
{
58-
await response.CopyToAsync(destinationStream, CancellationToken.None);
59-
}
57+
await using var destinationStream = File.Create(resultPath);
58+
await response.CopyToAsync(destinationStream, CancellationToken.None);
6059

6160
return resultPath;
6261
}
@@ -69,4 +68,4 @@ static Task<byte[]> GetImageBytes(string resourcePath)
6968
static Task<byte[]> GetHtmlFile(string resourcePath, string fileName)
7069
{
7170
return File.ReadAllBytesAsync(Path.Combine(resourcePath, fileName));
72-
}
71+
}

examples/HtmlWithMarkdown/Program.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ static async Task<string> CreateFromMarkdown(string destinationDirectory, string
2929

3030
using var httpClient = new HttpClient(authHandler ?? (HttpMessageHandler)handler)
3131
{
32-
BaseAddress = options.ServiceUrl
32+
BaseAddress = options.ServiceUrl,
33+
Timeout = options.TimeOut
3334
};
3435

3536
var sharpClient = new GotenbergSharpClient(httpClient);
@@ -56,10 +57,8 @@ static async Task<string> CreateFromMarkdown(string destinationDirectory, string
5657

5758
var outPath = Path.Combine(destinationDirectory, $"GotenbergFromMarkDown-{DateTime.Now:yyyyMMddHHmmss}.pdf");
5859

59-
using (var destinationStream = File.Create(outPath))
60-
{
61-
await response.CopyToAsync(destinationStream, CancellationToken.None);
62-
}
60+
await using var destinationStream = File.Create(outPath);
61+
await response.CopyToAsync(destinationStream, CancellationToken.None);
6362

6463
return outPath;
6564
}

examples/OfficeMerge/Program.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Gotenberg.Sharp.API.Client.Domain.Builders.Faceted;
44
using Gotenberg.Sharp.API.Client.Domain.Settings;
55
using Gotenberg.Sharp.API.Client.Infrastructure.Pipeline;
6+
67
using Microsoft.Extensions.Configuration;
78

89
var config = new ConfigurationBuilder()
@@ -29,7 +30,8 @@ static async Task<string> DoOfficeMerge(string sourceDirectory, string destinati
2930

3031
using var httpClient = new HttpClient(authHandler ?? (HttpMessageHandler)handler)
3132
{
32-
BaseAddress = options.ServiceUrl
33+
BaseAddress = options.ServiceUrl,
34+
Timeout = options.TimeOut
3335
};
3436

3537
var client = new GotenbergSharpClient(httpClient);
@@ -44,10 +46,9 @@ static async Task<string> DoOfficeMerge(string sourceDirectory, string destinati
4446

4547
var mergeResultPath = Path.Combine(destinationDirectory, $"GotenbergOfficeMerge-{DateTime.Now:yyyyMMddHHmmss}.pdf");
4648

47-
using (var destinationStream = File.Create(mergeResultPath))
48-
{
49-
await response.CopyToAsync(destinationStream, CancellationToken.None);
50-
}
49+
await using var destinationStream = File.Create(mergeResultPath);
50+
51+
await response.CopyToAsync(destinationStream, CancellationToken.None);
5152

5253
return mergeResultPath;
5354
}
@@ -62,4 +63,4 @@ static async Task<IEnumerable<KeyValuePair<string, byte[]>>> GetDocsAsync(string
6263

6364
return names.Select((name, index) => KeyValuePair.Create(name, docs[index]))
6465
.Take(10);
65-
}
66+
}

examples/PdfConvert/Program.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Gotenberg.Sharp.API.Client.Domain.Builders.Faceted;
44
using Gotenberg.Sharp.API.Client.Domain.Settings;
55
using Gotenberg.Sharp.API.Client.Infrastructure.Pipeline;
6+
67
using Microsoft.Extensions.Configuration;
78

89
// If you get 1 file, the result is a PDF; get more and the API returns a zip containing the results
@@ -32,7 +33,8 @@ static async Task<string> DoConversion(string sourcePath, string destinationPath
3233

3334
using var httpClient = new HttpClient(authHandler ?? (HttpMessageHandler)handler)
3435
{
35-
BaseAddress = options.ServiceUrl
36+
BaseAddress = options.ServiceUrl,
37+
Timeout = options.TimeOut
3638
};
3739

3840
var sharpClient = new GotenbergSharpClient(httpClient);
@@ -61,10 +63,9 @@ static async Task<string> DoConversion(string sourcePath, string destinationPath
6163
var extension = items.Count() > 1 ? "zip" : "pdf";
6264
var outPath = Path.Combine(destinationPath, $"GotenbergConvertResult.{extension}");
6365

64-
using (var destinationStream = File.Create(outPath))
65-
{
66-
await response.CopyToAsync(destinationStream, CancellationToken.None);
67-
}
66+
await using var destinationStream = File.Create(outPath);
67+
68+
await response.CopyToAsync(destinationStream, CancellationToken.None);
6869

6970
return outPath;
70-
}
71+
}

examples/PdfMerge/Program.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ static async Task<string> DoMerge(string sourcePath, string destinationPath, Got
2929

3030
using var httpClient = new HttpClient(authHandler ?? (HttpMessageHandler)handler)
3131
{
32-
BaseAddress = options.ServiceUrl
32+
BaseAddress = options.ServiceUrl,
33+
Timeout = options.TimeOut
3334
};
3435

3536
var sharpClient = new GotenbergSharpClient(httpClient);
@@ -57,10 +58,9 @@ static async Task<string> DoMerge(string sourcePath, string destinationPath, Got
5758

5859
var outPath = Path.Combine(destinationPath, "GotenbergMergeResult.pdf");
5960

60-
using (var destinationStream = File.Create(outPath))
61-
{
62-
await response.CopyToAsync(destinationStream, CancellationToken.None);
63-
}
61+
await using var destinationStream = File.Create(outPath);
62+
63+
await response.CopyToAsync(destinationStream, CancellationToken.None);
6464

6565
return outPath;
6666
}

examples/UrlConvert/Program.cs

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using Gotenberg.Sharp.API.Client.Domain.Builders.Faceted;
44
using Gotenberg.Sharp.API.Client.Domain.Settings;
55
using Gotenberg.Sharp.API.Client.Infrastructure.Pipeline;
6+
67
using Microsoft.Extensions.Configuration;
78

89
var config = new ConfigurationBuilder()
@@ -32,7 +33,8 @@ static async Task<string> CreateFromUrl(string destinationPath, string headerPat
3233

3334
using var httpClient = new HttpClient(authHandler ?? (HttpMessageHandler)handler)
3435
{
35-
BaseAddress = options.ServiceUrl
36+
BaseAddress = options.ServiceUrl,
37+
Timeout = options.TimeOut
3638
};
3739

3840
var sharpClient = new GotenbergSharpClient(httpClient);
@@ -43,24 +45,23 @@ static async Task<string> CreateFromUrl(string destinationPath, string headerPat
4345
.ConfigureRequest(b => b.SetTrace("ConsoleExample").SetPageRanges("1-2"))
4446
.AddAsyncHeaderFooter(async b =>
4547
b.SetHeader(await File.ReadAllBytesAsync(headerPath))
46-
.SetFooter(await File.ReadAllBytesAsync(footerPath))
48+
.SetFooter(await File.ReadAllBytesAsync(footerPath))
4749
)
4850
.WithPageProperties(b =>
4951
b.SetPaperSize(PaperSizes.A4)
50-
.UseChromeDefaults()
51-
.SetMarginLeft(0)
52-
.SetMarginRight(0)
52+
.UseChromeDefaults()
53+
.SetMarginLeft(0)
54+
.SetMarginRight(0)
5355
);
5456

5557
var request = await builder.BuildAsync();
5658
var response = await sharpClient.UrlToPdfAsync(request);
5759

5860
var resultPath = Path.Combine(destinationPath, $"GotenbergFromUrl-{DateTime.Now:yyyyMMddHHmmss}.pdf");
5961

60-
using (var destinationStream = File.Create(resultPath))
61-
{
62-
await response.CopyToAsync(destinationStream, CancellationToken.None);
63-
}
62+
await using var destinationStream = File.Create(resultPath);
63+
64+
await response.CopyToAsync(destinationStream, CancellationToken.None);
6465

6566
return resultPath;
66-
}
67+
}

examples/UrlsToMergedPdf/Program.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,9 @@ static async Task<string> WriteFileAndGetPath(Stream responseStream, string dest
9999
{
100100
var fullPath = Path.Combine(destinationDirectory, $"{DateTime.Now:yyyy-MM-dd}-{DateTime.Now.Ticks}.pdf");
101101

102-
using (var destinationStream = File.Create(fullPath))
103-
{
104-
await responseStream.CopyToAsync(destinationStream, CancellationToken.None);
105-
}
102+
await using var destinationStream = File.Create(fullPath);
103+
104+
await responseStream.CopyToAsync(destinationStream, CancellationToken.None);
105+
106106
return fullPath;
107107
}

examples/Webhook/Program.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ static async Task CreateFromUrl(string headerPath, string footerPath, GotenbergS
3535

3636
using var httpClient = new HttpClient(authHandler ?? (HttpMessageHandler)handler)
3737
{
38-
BaseAddress = options.ServiceUrl
38+
BaseAddress = options.ServiceUrl,
39+
Timeout = options.TimeOut
3940
};
4041

4142
var sharpClient = new GotenbergSharpClient(httpClient);

0 commit comments

Comments
 (0)