Skip to content

Commit

Permalink
add logging to SMPTE dictionary
Browse files Browse the repository at this point in the history
  • Loading branch information
feigenanton authored and rayden84 committed Jan 13, 2023
1 parent 4415351 commit 1698d88
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
44 changes: 26 additions & 18 deletions MXF/Identifiers/UL/SMPTEULDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,48 +25,51 @@
using System.Collections.Generic;
using System.Xml.Linq;
using System.Linq;
using System.Diagnostics;
using static Myriadbits.MXF.KLVKey;
using Serilog;

namespace Myriadbits.MXF.Identifiers
{
public static class SMPTEULDictionary
{
private static Dictionary<ByteArray, ULDescription> dictionary { get; set; }
private static Dictionary<ByteArray, ULDescription> Dictionary { get; set; }

public static Dictionary<ByteArray, ULDescription> GetEntries()
{
// if already initialized return it
if (dictionary != null)
if (Dictionary != null)
{
return dictionary;
return Dictionary;
}
else
{
dictionary = new Dictionary<ByteArray, ULDescription>(new SMPTEUL_DictionaryComparer());
Dictionary = new Dictionary<ByteArray, ULDescription>(new SMPTEUL_DictionaryComparer());

//Parse SMPTE Labels register

XElement regEntries;
XElement regEntries = XElement.Parse(Properties.Resources.Labels); ;
XNamespace ns = "http://www.smpte-ra.org/schemas/400/2012";

regEntries = XElement.Parse(Properties.Resources.Labels);
AddEntries(dictionary, regEntries, ns);
AddEntries(Dictionary, regEntries, ns);
long count = Dictionary.Count;
Log.ForContext(typeof(SMPTEULDictionary)).Information($"A total of {count} SMPTE label register entries added to SMPTE dictionary");

// Parse SMPTE Elements register

ns = "http://www.smpte-ra.org/schemas/335/2012";
regEntries = XElement.Parse(Properties.Resources.Elements);
AddEntries(dictionary, regEntries, ns);
AddEntries(Dictionary, regEntries, ns);
Log.ForContext(typeof(SMPTEULDictionary)).Information($"A total of {Dictionary.Count-count} SMPTE elements register entries added to SMPTE dictionary");
count = Dictionary.Count;

//Parse SMPTE Groups register

ns = "http://www.smpte-ra.org/ns/395/2016";
regEntries = XElement.Parse(Properties.Resources.Groups);
AddEntries(dictionary, regEntries, ns);
AddEntries(Dictionary, regEntries, ns);
Log.ForContext(typeof(SMPTEULDictionary)).Information($"A total of {Dictionary.Count-count} SMPTE groups register entries added to SMPTE dictionary");

var values = dictionary.Values.OrderBy(s => s.Name).Select(o => o.Name).ToList();
return dictionary;
var values = Dictionary.Values.OrderBy(s => s.Name).Select(o => o.Name).ToList();
Log.ForContext(typeof(SMPTEULDictionary)).Information($"SMPTE Dictionary with {Dictionary.Count} entries loaded");
return Dictionary;
}
}

Expand All @@ -79,12 +82,17 @@ private static void AddEntries(IDictionary<ByteArray, ULDescription> dict, XElem
{
if (dict.TryAdd(entry.Value.Key, entry.Value.Value) == false)
{
// TODO: raise an exception! (or at least log)
Debug.WriteLine("Entry already present!");
Log.ForContext(typeof(SMPTEULDictionary)).Warning($"Unable to add SMPTE entry {entry} to SMPTE dictionary as entry is already present: {@e}", entry);
}
Log.ForContext(typeof(SMPTEULDictionary)).Debug($"SMPTE entry {entry} added successfully to SMPTE dictionary");
Log.ForContext(typeof(SMPTEULDictionary)).Verbose($"Details of SMPTE entry: {@e}", entry);
}
else
{
// TODO if entry not parseable it is null
// TODO catch this on a lower level, maybe via an exception
Log.ForContext(typeof(SMPTEULDictionary)).Warning($"Unable to parse SMPTE entry {entry}: {@e}", entry);
}
// TODO: heavy performance degrade on this debug statement!?
//Debug.WriteLine("Unable to parse entry!");
}
}

Expand Down
8 changes: 2 additions & 6 deletions MXFInspect/MXFInspect.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,8 @@
</PackageReference>
</ItemGroup>
<ItemGroup>
<Compile Update="FormMultiLineStringShowDlg.cs">
<SubType>Form</SubType>
</Compile>
<Compile Update="CustomControls\TreeListViewBase.cs">
<SubType>Component</SubType>
</Compile>
<Compile Update="FormMultiLineStringShowDlg.cs" />
<Compile Update="CustomControls\TreeListViewBase.cs" />
<Compile Update="Properties\Resources.Designer.cs">
<DesignTime>True</DesignTime>
<AutoGen>True</AutoGen>
Expand Down
4 changes: 2 additions & 2 deletions MXFInspect/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ static void Main()
string jsonLogFile = Path.Combine(path, "MXFInspect_log_.json");

using var log = new LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Verbose()
.Enrich.WithThreadId()
.Enrich.WithThreadName()
.Enrich.FromLogContext()
.Enrich.WithExceptionDetails()
.WriteTo.Debug()
.WriteTo.Debug(restrictedToMinimumLevel: Serilog.Events.LogEventLevel.Information)
.WriteTo.File(new JsonFormatter(renderMessage: true), jsonLogFile)
.WriteTo.File(txtLogFile,
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss.fff zzz} [{Level:u3}] ({SourceContext}) <{ThreadId}:{ThreadName}> {Message:lj}{NewLine}{Exception}",
Expand Down

0 comments on commit 1698d88

Please sign in to comment.