Skip to content

Commit 639f185

Browse files
committed
add readme, System.IO.Abstraction
1 parent aa744ed commit 639f185

6 files changed

Lines changed: 34 additions & 11 deletions

File tree

README.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,18 @@
1-
# SharpIppNextServer
1+
# SharpIppNextServer
2+
3+
IPP printer (web app) based on `SharIppNext` library.
4+
5+
## Installation
6+
7+
1. Add manually using add printer wizard
8+
2. Add automatically using script
9+
10+
- Windows: `add-printer -Name "SharpIpp on http://127.0.0.1:631" -DriverName "Microsoft IPP Class Driver" -PortName "http://127.0.0.1:631/"`
11+
3. Add to `NetPrinter` app from Google Play Store
12+
4. Add to IPP / CUPS printing for Chrome & Chromebooks extension from Chrome Web Store.
13+
14+
## Integration testing
15+
16+
1. Install package: `sudo zypper install cups-client cups-backends`
17+
2. Obtain correct IP: `ip route`
18+
3. Make test: `ipptool -t ipp://172.25.192.1 ipp-1.1.test`

SharpIppNextServer/Directory.Packages.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="8.0.0" />
2222
<PackageVersion Include="System.Diagnostics.DiagnosticSource" Version="8.0.0" />
2323
<PackageVersion Include="System.Drawing.Common" Version="8.0.3" />
24+
<PackageVersion Include="System.IO.Abstractions" Version="21.0.2" />
2425
<PackageVersion Include="System.Security.AccessControl" Version="6.0.0" />
2526
<PackageVersion Include="System.Security.Cryptography.ProtectedData" Version="8.0.0" />
2627
<PackageVersion Include="System.Security.Permissions" Version="8.0.0" />

SharpIppNextServer/Program.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
using SharpIpp;
55
using SharpIppNextServer.Models;
66
using SharpIppNextServer.Services;
7+
using System.IO.Abstractions;
78

89
var builder = WebApplication.CreateBuilder(args);
910
builder.Services
1011
.AddSingleton<IDateTimeProvider, DateTimeProvider>()
1112
.AddSingleton<IDateTimeOffsetProvider, DateTimeOffsetProvider>()
1213
.AddSingleton<ISharpIppServer, SharpIppServer>()
14+
.AddSingleton<IFileSystem, FileSystem>()
1315
.Configure<KestrelServerOptions>(options => options.AllowSynchronousIO = true)
1416
.Configure<PrinterOptions>(builder.Configuration.GetSection("Printer"))
1517
.AddSingleton<PrinterService>()

SharpIppNextServer/Properties/launchSettings.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,26 @@
1212
"http": {
1313
"commandName": "Project",
1414
"dotnetRunMessages": true,
15-
"launchBrowser": true,
15+
"launchBrowser": false,
1616
"launchUrl": "",
17-
"applicationUrl": "http://localhost:631",
17+
"applicationUrl": "http://0.0.0.0:631",
1818
"environmentVariables": {
1919
"ASPNETCORE_ENVIRONMENT": "Development"
2020
}
2121
},
2222
"https": {
2323
"commandName": "Project",
2424
"dotnetRunMessages": true,
25-
"launchBrowser": true,
25+
"launchBrowser": false,
2626
"launchUrl": "",
27-
"applicationUrl": "https://localhost:631;http://localhost:631",
27+
"applicationUrl": "https://0.0.0.0:631;http://0.0.0.0:631",
2828
"environmentVariables": {
2929
"ASPNETCORE_ENVIRONMENT": "Development"
3030
}
3131
},
3232
"IIS Express": {
3333
"commandName": "IISExpress",
34-
"launchBrowser": true,
34+
"launchBrowser": false,
3535
"launchUrl": "",
3636
"environmentVariables": {
3737
"ASPNETCORE_ENVIRONMENT": "Development"

SharpIppNextServer/Services/JobService.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
using Quartz;
33
using SharpIpp.Models;
44
using SharpIpp.Protocol.Models;
5+
using System.IO.Abstractions;
56

67
namespace SharpIppNextServer.Services;
78

89
public class JobService(
910
PrinterService printerService,
10-
IWebHostEnvironment env) : IJob
11+
IWebHostEnvironment env,
12+
IFileSystem fileSystem) : IJob
1113
{
1214
private readonly FileExtensionContentTypeProvider _contentTypeProvider = new();
1315

@@ -69,7 +71,7 @@ private async Task SaveAsync(string prefix, SendUriRequest request)
6971
if (!result.IsSuccessStatusCode)
7072
return;
7173
using var stream = await result.Content.ReadAsStreamAsync();
72-
await SaveAsync(stream, GetFileName(prefix, request.DocumentAttributes, Path.GetFileNameWithoutExtension(request.DocumentUri.LocalPath), Path.GetExtension(request.DocumentUri.LocalPath)));
74+
await SaveAsync(stream, GetFileName(prefix, request.DocumentAttributes, fileSystem.Path.GetFileNameWithoutExtension(request.DocumentUri.LocalPath), fileSystem.Path.GetExtension(request.DocumentUri.LocalPath)));
7375
}
7476

7577
private string GetFileName(string prefix, DocumentAttributes? documentAttributes, string? alternativeDocumentName = null, string? alternativeExtension = null)
@@ -82,9 +84,9 @@ private string GetFileName(string prefix, DocumentAttributes? documentAttributes
8284

8385
private async Task SaveAsync(Stream stream, string fileName)
8486
{
85-
var path = Path.Combine(env.ContentRootPath, "jobs", fileName);
86-
Directory.CreateDirectory(Path.Combine(env.ContentRootPath, "jobs"));
87-
using var fileStream = new FileStream(path, FileMode.OpenOrCreate);
87+
var path = fileSystem.Path.Combine(env.ContentRootPath, "jobs", fileName);
88+
fileSystem.Directory.CreateDirectory(fileSystem.Path.Combine(env.ContentRootPath, "jobs"));
89+
using var fileStream = fileSystem.FileStream.New(path, FileMode.OpenOrCreate);
8890
await stream.CopyToAsync(fileStream);
8991
}
9092
}

SharpIppNextServer/SharpIppNextServer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<ItemGroup>
1717
<PackageReference Include="Quartz.Extensions.Hosting" />
1818
<PackageReference Include="SharpIppNext" />
19+
<PackageReference Include="System.IO.Abstractions" />
1920
</ItemGroup>
2021

2122
</Project>

0 commit comments

Comments
 (0)