Skip to content

Commit 57c462c

Browse files
committed
update example
1 parent a040538 commit 57c462c

13 files changed

Lines changed: 68 additions & 84 deletions

File tree

example/MultiSlideServer/ImageProvider.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,6 @@ public RetainableDeepZoomGenerator RetainDeepZoomGenerator(string name, string p
5353
dz.Dispose();
5454
return dz;
5555
}
56-
57-
private sealed class DummyDisposable : IDisposable
58-
{
59-
public static readonly DummyDisposable Instance = new DummyDisposable();
60-
public void Dispose()
61-
{
62-
// do nothing
63-
}
64-
}
56+
6557
}
6658
}

example/MultiSlideServer/MultiSlideServer.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,6 @@
1212
<ProjectReference Include="..\..\src\OpenSlideSharp.Windows\OpenSlideSharp.Windows.csproj" />
1313
</ItemGroup>
1414

15+
<ProjectExtensions><VisualStudio><UserProperties appsettings_1json__JsonSchema="" /></VisualStudio></ProjectExtensions>
16+
1517
</Project>
Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
using Microsoft.AspNetCore;
7-
using Microsoft.AspNetCore.Hosting;
8-
using Microsoft.Extensions.Configuration;
9-
using Microsoft.Extensions.Logging;
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Hosting;
103

114
namespace MultiSlideServer
125
{
136
public class Program
147
{
158
public static void Main(string[] args)
169
{
17-
BuildWebHost(args).Run();
10+
CreateHostBuilder(args).Build().Run();
1811
}
1912

20-
public static IWebHost BuildWebHost(string[] args) =>
21-
WebHost.CreateDefaultBuilder(args)
22-
.UseStartup<Startup>()
23-
.Build();
13+
public static IHostBuilder CreateHostBuilder(string[] args) =>
14+
Host.CreateDefaultBuilder(args)
15+
.ConfigureWebHostDefaults(webBuilder =>
16+
{
17+
webBuilder.UseStartup<Startup>();
18+
});
2419
}
2520
}

example/MultiSlideServer/Startup.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
7575
try
7676
{
7777
response.ContentType = "image/jpeg";
78-
response.Body = await Task.Run(() => dz.GetTileAsJpegStream(result.level, result.col, result.row, out var tmp));
78+
await dz.GetTileAsJpegStream(result.level, result.col, result.row, out var tmp).CopyToAsync(response.Body);
7979
}
8080
finally
8181
{
@@ -84,13 +84,15 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
8484
});
8585

8686
app.UseStaticFiles();
87+
app.UseRouting();
8788

8889
app.UseEndpoints(endpoints =>
8990
{
90-
endpoints.MapRazorPages();
91+
endpoints.MapControllers();
9192
});
9293
}
9394

95+
9496
// OPTIMIZE: Use ReadOnlySpan in .NET Core 2.1
9597
// expression: /{level}/{col}_{row}.jpeg
9698
private static bool TryParseDeepZoom(string expression, out (string name, int level, int col, int row, string format) result)
Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
11
{
22
"Logging": {
3-
"IncludeScopes": false,
4-
"Debug": {
5-
"LogLevel": {
6-
"Default": "Warning"
7-
}
8-
},
9-
"Console": {
10-
"LogLevel": {
11-
"Default": "Warning"
12-
}
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
137
}
148
},
9+
"AllowedHosts": "*",
1510
"Images": [
1611
{
1712
"Name": "test1",
18-
"Path": "image1.tif"
13+
"Path": "image1.tiff"
1914
},
2015
{
2116
"Name": "test2",
22-
"Path": "image2.tif"
17+
"Path": "image2.tiff"
2318
}
2419
]
2520
}

example/SingleSlideServer/ImageOption.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22
{
33
public class ImageOption
44
{
5-
public string Path { get; set; } = "image.tiff";
5+
public string Path { get; set; }
66
}
77
}
Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,38 @@
1-
using Microsoft.Extensions.Options;
1+
using System;
2+
using Microsoft.Extensions.Options;
23
using OpenSlideSharp;
3-
using System;
44

55
namespace SingleSlideServer
66
{
77
public class ImageProvider : IDisposable
88
{
9-
private OpenSlideImage _image;
109
private DeepZoomGenerator _generator;
1110

1211
public ImageProvider(IOptions<ImageOption> options)
1312
{
14-
var path = options.Value.Path;
15-
_image = OpenSlideImage.Open(path);
16-
_generator = new DeepZoomGenerator(_image, tileSize: 254, overlap: 1);
13+
_generator = new DeepZoomGenerator(OpenSlideImage.Open(options.Value.Path), tileSize: 254, overlap: 1);
1714
}
1815

1916
public DeepZoomGenerator DeepZoomGenerator => _generator;
2017

18+
private bool disposedValue;
19+
protected virtual void Dispose(bool disposing)
20+
{
21+
if (!disposedValue)
22+
{
23+
if (disposing)
24+
{
25+
_generator.Dispose();
26+
}
27+
28+
disposedValue = true;
29+
}
30+
}
31+
2132
public void Dispose()
2233
{
23-
_generator.Dispose();
24-
_image.Dispose();
34+
Dispose(disposing: true);
35+
GC.SuppressFinalize(this);
2536
}
2637
}
2738
}
Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,20 @@
1-
using System;
2-
using System.Collections.Generic;
3-
using System.IO;
4-
using System.Linq;
5-
using System.Threading.Tasks;
6-
using Microsoft.AspNetCore;
7-
using Microsoft.AspNetCore.Hosting;
8-
using Microsoft.Extensions.Configuration;
9-
using Microsoft.Extensions.Logging;
1+
using Microsoft.AspNetCore.Hosting;
2+
using Microsoft.Extensions.Hosting;
103

114
namespace SingleSlideServer
125
{
136
public class Program
147
{
158
public static void Main(string[] args)
169
{
17-
BuildWebHost(args).Run();
10+
CreateHostBuilder(args).Build().Run();
1811
}
1912

20-
public static IWebHost BuildWebHost(string[] args) =>
21-
WebHost.CreateDefaultBuilder(args)
22-
.UseStartup<Startup>()
23-
.Build();
13+
public static IHostBuilder CreateHostBuilder(string[] args) =>
14+
Host.CreateDefaultBuilder(args)
15+
.ConfigureWebHostDefaults(webBuilder =>
16+
{
17+
webBuilder.UseStartup<Startup>();
18+
});
2419
}
2520
}

example/SingleSlideServer/Startup.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,21 +57,19 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
5757
var provider = context.RequestServices.GetService<ImageProvider>();
5858
var response = context.Response;
5959
response.ContentType = "image/jpeg";
60-
response.Body = await Task.Run(()=> provider.DeepZoomGenerator.GetTileAsJpegStream(result.level, result.col, result.row,out var tmp));
60+
await provider.DeepZoomGenerator.GetTileAsJpegStream(result.level, result.col, result.row, out var tmp).CopyToAsync(response.Body);
6161
});
6262
});
6363

6464
app.UseDefaultFiles();
65-
6665
app.UseStaticFiles();
67-
66+
app.UseRouting();
6867
app.UseEndpoints(endpoints =>
6968
{
70-
endpoints.MapRazorPages();
69+
endpoints.MapControllers();
7170
});
7271
}
7372

74-
// OPTIMIZE: Use ReadOnlySpan in .NET Core 2.1
7573
// expression: /{level}/{col}_{row}.jpeg
7674
private static bool TryParseDeepZoom(string expression, out (int level, int col, int row, string format) result)
7775
{
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
{
22
"Logging": {
3-
"IncludeScopes": false,
43
"LogLevel": {
5-
"Default": "Debug",
6-
"System": "Information",
7-
"Microsoft": "Information"
4+
"Default": "Information",
5+
"Microsoft": "Warning",
6+
"Microsoft.Hosting.Lifetime": "Information"
87
}
98
}
10-
}
9+
}

0 commit comments

Comments
 (0)