Skip to content

Commit

Permalink
Mark obsolete attributes internal to prevent serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
ptr727 committed Mar 23, 2023
1 parent 67f85ca commit ca783c2
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 60 deletions.
52 changes: 11 additions & 41 deletions PlexCleaner.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,6 @@
},
"HandBrakeOptions": {
"$ref": "#/definitions/HandBrakeOptions"
},
"EnableH265Encoder": {
"type": "boolean"
},
"VideoEncodeQuality": {
"type": "integer"
},
"AudioEncodeCodec": {
"type": [
"string",
"null"
]
}
},
"required": [
Expand Down Expand Up @@ -159,24 +147,6 @@
]
}
},
"ReEncodeVideoFormats": {
"type": [
"string",
"null"
]
},
"ReEncodeVideoCodecs": {
"type": [
"string",
"null"
]
},
"ReEncodeVideoProfiles": {
"type": [
"string",
"null"
]
},
"DeleteEmptyFolders": {
"type": "boolean"
},
Expand Down Expand Up @@ -356,27 +326,27 @@
"type": "integer",
"default": 0
},
"ConvertOptions": {
"$ref": "#/definitions/ConvertOptions"
"ToolsOptions": {
"$ref": "#/definitions/ToolsOptions"
},
"ProcessOptions": {
"$ref": "#/definitions/ProcessOptions"
},
"ToolsOptions": {
"$ref": "#/definitions/ToolsOptions"
},
"MonitorOptions": {
"$ref": "#/definitions/MonitorOptions"
"ConvertOptions": {
"$ref": "#/definitions/ConvertOptions"
},
"VerifyOptions": {
"$ref": "#/definitions/VerifyOptions"
},
"MonitorOptions": {
"$ref": "#/definitions/MonitorOptions"
}
},
"required": [
"ConvertOptions",
"ProcessOptions",
"ToolsOptions",
"MonitorOptions",
"VerifyOptions"
"ProcessOptions",
"ConvertOptions",
"VerifyOptions",
"MonitorOptions"
]
}
19 changes: 15 additions & 4 deletions PlexCleaner/ConfigFileJsonSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,30 +29,35 @@ public ConfigFileJsonSchemaBase() { }
}

// v1
[Obsolete]
public record ConfigFileJsonSchema1 : ConfigFileJsonSchemaBase
{
public ConfigFileJsonSchema1() { }

// Deprecated
[Obsolete]
public ConvertOptions1 ConvertOptions { get; protected set; } = new();
internal ConvertOptions1 ConvertOptions { get; set; } = new();
[Obsolete]
public ProcessOptions1 ProcessOptions { get; protected set; } = new();
internal ProcessOptions1 ProcessOptions { get; set; } = new();

[Required]
[JsonProperty(Order = 1)]
public ToolsOptions ToolsOptions { get; protected set; } = new();

[Required]
[JsonProperty(Order = 5)]
public MonitorOptions MonitorOptions { get; protected set; } = new();

[Required]
[JsonProperty(Order = 4)]
public VerifyOptions VerifyOptions { get; protected set; } = new();

// v1
public const int Version = 1;
}

// v2
[Obsolete]
public record ConfigFileJsonSchema2 : ConfigFileJsonSchema1
{
public ConfigFileJsonSchema2() { }
Expand All @@ -72,14 +77,16 @@ protected void Upgrade(ConfigFileJsonSchema1 configFileJsonSchema1)
}

[Obsolete]
public new ProcessOptions2 ProcessOptions { get; protected set; } = new();
internal new ProcessOptions2 ProcessOptions { get; set; } = new();

// v2
public new const int Version = 2;
}

// v3
#pragma warning disable CS0612 // Type or member is obsolete
public record ConfigFileJsonSchema : ConfigFileJsonSchema2
#pragma warning restore CS0612 // Type or member is obsolete
{
public ConfigFileJsonSchema() { }

Expand Down Expand Up @@ -107,9 +114,11 @@ protected void Upgrade(ConfigFileJsonSchema2 configFileJsonSchema2)
}

[Required]
[JsonProperty(Order = 3)]
public new ConvertOptions ConvertOptions { get; protected set; } = new();

[Required]
[JsonProperty(Order = 2)]
public new ProcessOptions ProcessOptions { get; protected set; } = new();

// v3
Expand Down Expand Up @@ -170,9 +179,9 @@ private static ConfigFileJsonSchema FromJson(string json)
// Deserialize the correct version
switch (configFileJsonSchemaBase.SchemaVersion)
{
#pragma warning disable CS0612 // Type or member is obsolete
// Version 1
case ConfigFileJsonSchema1.Version:
#pragma warning disable CS0612 // Type or member is obsolete
return new ConfigFileJsonSchema(JsonConvert.DeserializeObject<ConfigFileJsonSchema1>(json, Settings));
// Version 2
case ConfigFileJsonSchema2.Version:
Expand All @@ -195,6 +204,8 @@ private static ConfigFileJsonSchema FromJson(string json)
// Reuse the already created objects, required for HashSet() case insensitive comparison operator
ObjectCreationHandling = ObjectCreationHandling.Reuse
// TODO: Add TraceWriter to log to Serilog
// TODO: Add a custom resolver to control serialization od deprecated attributes, vs. using internal
// https://stackoverflow.com/questions/11564091/making-a-property-deserialize-but-not-serialize-with-json-net
};

public static void WriteSchemaToFile(string path)
Expand Down
9 changes: 6 additions & 3 deletions PlexCleaner/ConvertOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
namespace PlexCleaner;

// v1, v2
[Obsolete]
public record ConvertOptions1
{
[Obsolete]
public bool EnableH265Encoder { get; set; }
internal bool EnableH265Encoder { get; set; }
[Obsolete]
public int VideoEncodeQuality { get; set; }
internal int VideoEncodeQuality { get; set; }
[Obsolete]
public string AudioEncodeCodec { get; set; } = "";
internal string AudioEncodeCodec { get; set; } = "";
}

// v3
#pragma warning disable CS0612 // Type or member is obsolete
public record ConvertOptions : ConvertOptions1
#pragma warning restore CS0612 // Type or member is obsolete
{
public ConvertOptions() { }

Expand Down
2 changes: 2 additions & 0 deletions PlexCleaner/MonitorOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ public class MonitorOptions
[Required]
[Range(0, int.MaxValue)]
public int MonitorWaitTime { get; set; }

[Required]
[Range(0, int.MaxValue)]
public int FileRetryWaitTime { get; set; }

[Required]
[Range(0, int.MaxValue)]
public int FileRetryCount { get; set; }
Expand Down
18 changes: 11 additions & 7 deletions PlexCleaner/ProcessOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,23 @@ public class VideoFormat
}

// v1
[Obsolete]
public record ProcessOptions1
{
[Obsolete]
public string ReEncodeVideoFormats { get; set; } = "";
internal string ReEncodeVideoFormats { get; set; } = "";
[Obsolete]
public string ReEncodeVideoCodecs { get; set; } = "";
internal string ReEncodeVideoCodecs { get; set; } = "";
[Obsolete]
public string ReEncodeVideoProfiles { get; set; } = "";
internal string ReEncodeVideoProfiles { get; set; } = "";
[Obsolete]
public string ReEncodeAudioFormats { get; set; } = "";
internal string ReEncodeAudioFormats { get; set; } = "";
[Obsolete]
public string KeepExtensions { get; set; } = "";
internal string KeepExtensions { get; set; } = "";
[Obsolete]
public string KeepLanguages { get; set; } = "";
internal string KeepLanguages { get; set; } = "";
[Obsolete]
public string PreferredAudioFormats { get; set; } = "";
internal string PreferredAudioFormats { get; set; } = "";

[Required]
public bool DeleteEmptyFolders { get; set; }
Expand Down Expand Up @@ -80,6 +81,7 @@ public record ProcessOptions1
}

// v2
[Obsolete]
public record ProcessOptions2 : ProcessOptions1
{
public ProcessOptions2() { }
Expand Down Expand Up @@ -182,7 +184,9 @@ protected void Upgrade(ProcessOptions1 processOptions1)
}

// v3
#pragma warning disable CS0612 // Type or member is obsolete
public record ProcessOptions : ProcessOptions2
#pragma warning restore CS0612 // Type or member is obsolete
{
public ProcessOptions() { }

Expand Down
15 changes: 10 additions & 5 deletions PlexCleaner/SidecarFileJsonSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ public SidecarFileJsonSchemaBase() { }
}

// v1
[Obsolete]
public record SidecarFileJsonSchema1 : SidecarFileJsonSchemaBase
{
public SidecarFileJsonSchema1() { }

[Obsolete]
public string FfMpegToolVersion { get; set; }
internal string FfMpegToolVersion { get; set; }
[Obsolete]
public string MkvToolVersion { get; set; }
internal string MkvToolVersion { get; set; }
[Obsolete]
public string FfIdetInfoData { get; set; }
internal string FfIdetInfoData { get; set; }

[Required]
public DateTime MediaLastWriteTimeUtc { get; set; }
Expand All @@ -57,6 +58,7 @@ public SidecarFileJsonSchema1() { }
}

// v2
[Obsolete]
public record SidecarFileJsonSchema2 : SidecarFileJsonSchema1
{
public SidecarFileJsonSchema2() { }
Expand All @@ -76,13 +78,14 @@ protected void Upgrade(SidecarFileJsonSchema1 sidecarFileJsonSchema1)
}

[Obsolete]
public bool Verified { get; set; }
internal bool Verified { get; set; }

// v2
public new const int Version = 2;
}

// v3
[Obsolete]
public record SidecarFileJsonSchema3 : SidecarFileJsonSchema2
{
public SidecarFileJsonSchema3() { }
Expand Down Expand Up @@ -125,7 +128,9 @@ protected void Upgrade(SidecarFileJsonSchema2 sidecarFileJsonSchema2)
}

// v4
#pragma warning disable CS0612 // Type or member is obsolete
public record SidecarFileJsonSchema : SidecarFileJsonSchema3
#pragma warning restore CS0612 // Type or member is obsolete
{
public SidecarFileJsonSchema() { }

Expand Down Expand Up @@ -185,9 +190,9 @@ public static SidecarFileJsonSchema FromJson(string json)
// Deserialize the correct version
switch (sidecarFileJsonSchemaBase.SchemaVersion)
{
#pragma warning disable CS0612 // Type or member is obsolete
// Version 1
case SidecarFileJsonSchema1.Version:
#pragma warning disable CS0612 // Type or member is obsolete
return new SidecarFileJsonSchema(JsonConvert.DeserializeObject<SidecarFileJsonSchema1>(json, Settings));
// Version 2
case SidecarFileJsonSchema2.Version:
Expand Down
3 changes: 3 additions & 0 deletions PlexCleaner/ToolsOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ public class ToolsOptions
{
[Required]
public bool UseSystem { get; set; }

[Required]
public string RootPath { get; set; } = "";

[Required]
public bool RootRelative { get; set; }

[Required]
public bool AutoUpdate { get; set; }

Expand Down
7 changes: 7 additions & 0 deletions PlexCleaner/VerifyOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,29 @@ public class VerifyOptions
{
[Required]
public bool AutoRepair { get; set; }

[Required]
public bool DeleteInvalidFiles { get; set; }

[Required]
public bool RegisterInvalidFiles { get; set; }

[Required]
[Range(0, int.MaxValue)]
public int MinimumDuration { get; set; }

[Required]
[Range(0, int.MaxValue)]
public int VerifyDuration { get; set; }

[Required]
[Range(0, int.MaxValue)]
public int IdetDuration { get; set; }

[Required]
[Range(0, int.MaxValue)]
public int MaximumBitrate { get; set; }

[Required]
[Range(0, int.MaxValue)]
public int MinimumFileAge { get; set; }
Expand Down

0 comments on commit ca783c2

Please sign in to comment.