VMelnalksnis.PaperlessDotNet
1.1.0
Prefix Reserved
dotnet add package VMelnalksnis.PaperlessDotNet --version 1.1.0
NuGet\Install-Package VMelnalksnis.PaperlessDotNet -Version 1.1.0
<PackageReference Include="VMelnalksnis.PaperlessDotNet" Version="1.1.0" />
paket add VMelnalksnis.PaperlessDotNet --version 1.1.0
#r "nuget: VMelnalksnis.PaperlessDotNet, 1.1.0"
// Install VMelnalksnis.PaperlessDotNet as a Cake Addin #addin nuget:?package=VMelnalksnis.PaperlessDotNet&version=1.1.0 // Install VMelnalksnis.PaperlessDotNet as a Cake Tool #tool nuget:?package=VMelnalksnis.PaperlessDotNet&version=1.1.0
PaperlessDotNet
.NET client for the Paperless-ngx API.
Usage
A separate NuGet package is provided for ASP.NET Core (IConfiguration and IServiceCollection) . For use outside of ASP.NET Core, see the example in tests.
Add configuration (see options)
"Paperless": { "BaseAddress": "", "Token": "" }
Register required services (see tests)
serviceCollection .AddSingleton<IClock>(SystemClock.Instance) .AddSingleton(DateTimeZoneProviders.Tzdb) .AddPaperlessDotNet();
Use
IPaperlessClient
to access all endpoints, or one of the specific clients defined inIPaperlessClient
Custom fields
Paperless supports adding custom fields to documents. In order to use custom fields, first define a class with a property for each field:
internal sealed class CustomFields
{
public string? Field1 { get; set; }
public Uri? Field2 { get; set; }
public LocalDate? Field3 { get; set; }
public bool? Field4 { get; set; }
public int? Field5 { get; set; }
public float? Field6 { get; set; }
public float? Field7 { get; set; }
public int[]? Field8 { get; set; }
}
Then create a JsonSerializerContext
with all the API models that use custom fields:
[JsonSerializable(typeof(PaginatedList<Document<CustomFields>>))]
[JsonSerializable(typeof(DocumentUpdate<CustomFields>))]
internal sealed partial class SerializerContext : JsonSerializerContext;
And configure JSON serialization for the client:
serviceCollection.AddPaperlessDotNet(
configuration,
options =>
{
options.Options.Converters.Add(new CustomFieldsConverter<CustomFields>(options));
options.Options.TypeInfoResolverChain.Add(SerializerContext.Default);
});
For a working example see unit tests and integration tests.
Select custom fields
Version 2.11.0
introduced select
custom fields, which require additional setup in order to serialize/deserialize properly.
First, you'll need to define SmartEnum
class for each select
custom field:
public sealed class SelectOptions : SmartEnum<SelectOptions>
{
public static readonly SelectOptions Option1 = new("First option", 0);
public static readonly SelectOptions Option2 = new("Second option", 1);
private SelectOptions(string name, int value)
: base(name, value)
{
}
}
NOTE: the values MUST be sequential and start at 0 in order to match how they are stored in paperless.
Then you can add the property to your CustomFields
class
public SelectOptions? Field9 { get; set; }
and add the SmartEnumValueConverter<TEnum, TValue>
in one of the possible ways:
[JsonConverter(typeof(SmartEnumValueConverter<SelectOptions, int>))]
public SelectOptions? Field9 { get; set; }
or
serviceCollection.AddPaperlessDotNet(
configuration,
options =>
{
options.Options.Converters.Add(new SmartEnumValueConverter<SelectOptions, int>())
options.Options.Converters.Add(new CustomFieldsConverter<CustomFields>(options));
options.Options.TypeInfoResolverChain.Add(SerializerContext.Default);
});
In order to create a select
custom field, you also need to use
either SelectCustomFieldCreation<TEnum, TValue>
or SelectCustomFieldCreation<TEnum>
and add it to the JsonSerializerContext
.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Ardalis.SmartEnum (>= 2.1.0)
- Ardalis.SmartEnum.SystemTextJson (>= 2.1.0)
- Microsoft.Bcl.AsyncInterfaces (>= 9.0.0)
- NodaTime (>= 3.2.0)
- NodaTime.Serialization.SystemTextJson (>= 1.2.0)
- System.ComponentModel.Annotations (>= 5.0.0)
- System.Net.Http.Json (>= 9.0.0)
- System.Text.Json (>= 9.0.0)
-
net8.0
- Ardalis.SmartEnum (>= 2.1.0)
- Ardalis.SmartEnum.SystemTextJson (>= 2.1.0)
- NodaTime (>= 3.2.0)
- NodaTime.Serialization.SystemTextJson (>= 1.2.0)
- System.Text.Json (>= 9.0.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on VMelnalksnis.PaperlessDotNet:
Package | Downloads |
---|---|
VMelnalksnis.PaperlessDotNet.DependencyInjection
Dependency injection configuration for VMelnalksnis.PaperlessDotNet |
GitHub repositories
This package is not used by any popular GitHub repositories.