From fa801d8fa8be7784d3e8a7b1d9bbe6780d46c8ea Mon Sep 17 00:00:00 2001 From: luizen Date: Sat, 28 May 2022 15:35:01 -0300 Subject: [PATCH 1/2] Fixing nullable related warnings + small bugs --- src/als-tools.core/Config/DbOptions.cs | 6 ++-- src/als-tools.core/Entities/LiveProject.cs | 25 +++++++++------- src/als-tools.core/Factories/TrackFactory.cs | 16 +++++----- .../ValueObjects/Devices/BaseDevice.cs | 6 ++-- .../ValueObjects/Devices/IDevice.cs | 2 +- src/als-tools.core/ValueObjects/Locator.cs | 8 ++--- src/als-tools.core/ValueObjects/Scene.cs | 14 ++++----- .../ValueObjects/Tracks/AudioTrack.cs | 2 +- .../ValueObjects/Tracks/BaseTrack.cs | 30 ++++++++++--------- .../ValueObjects/Tracks/GroupTrack.cs | 2 +- .../ValueObjects/Tracks/ITrack.cs | 8 ++--- .../ValueObjects/Tracks/MidiTrack.cs | 2 +- .../ValueObjects/Tracks/ReturnTrack.cs | 2 +- .../EmbeddedDatabaseContext.cs | 6 ++-- .../BaseMaxForLiveSortExtractor.cs | 8 ++--- .../Extractors/PluginDeviceExtractor.cs | 2 +- .../BasePluginFormatExtractor.cs | 8 ++--- .../Vst2PluginFormatExtractor.cs | 2 +- .../Vst3PluginFormatExtractor.cs | 2 +- .../StockDevices/BaseStockDeviceExtractor.cs | 6 ++-- .../Handlers/DeviceExtractionHandler.cs | 8 ++--- .../Handlers/LiveProjectExtractionHandler.cs | 8 ++--- .../Handlers/LocatorExtractionHandler.cs | 8 ++--- .../Handlers/SceneExtractionHandler.cs | 16 +++++----- .../Handlers/TrackExtractionHandler.cs | 8 ++--- .../LiveProjectRavenDBRepository.cs | 10 +------ .../XmlNodeNames/LiveStockDeviceNodeNames.cs | 6 ++-- .../CliOptions/InitDbOptions.cs | 5 ++-- .../CliOptions/LocateOptions.cs | 2 +- .../Exceptions/CommandLineParseException.cs | 6 ++-- src/als-tools.ui.cli/Program.Extra.cs | 14 +++++++-- src/als-tools.ui.cli/Program.cs | 1 - src/als-tools.ui.cli/ui.cli.usings.cs | 1 + 33 files changed, 128 insertions(+), 122 deletions(-) diff --git a/src/als-tools.core/Config/DbOptions.cs b/src/als-tools.core/Config/DbOptions.cs index b17bce8..45eb172 100644 --- a/src/als-tools.core/Config/DbOptions.cs +++ b/src/als-tools.core/Config/DbOptions.cs @@ -8,15 +8,15 @@ public class DbOptions /// /// The folder where the database data files will be created /// - public string DataLocation { get; set; } + public string DataLocation { get; set; } = string.Empty; /// /// The database server URL to connect to /// - public string ServerUrl { get; set; } + public string ServerUrl { get; set; } = string.Empty; /// /// The root document store name, where data will be saved to /// - public string DocumentStoreName { get; set; } + public string DocumentStoreName { get; set; } = string.Empty; } diff --git a/src/als-tools.core/Entities/LiveProject.cs b/src/als-tools.core/Entities/LiveProject.cs index bda2e22..5191fb6 100644 --- a/src/als-tools.core/Entities/LiveProject.cs +++ b/src/als-tools.core/Entities/LiveProject.cs @@ -13,34 +13,37 @@ public LiveProject() } /// - /// Internal (persistency related) project ID + /// Internal (persistency related) project ID. + /// This must be nullable and null at the moment of the bulk insert for an + /// ID to be auto generated by the DB engine. + /// BulkInsert error with RavenDB: Document id must have a non empty value /// - public string Id { get; set; } - + public string? Id { get; set; } + /// /// The project name /// - public string Name { get; set; } + public string Name { get; set; } = string.Empty; /// /// The full path of this project /// - public string Path { get; set; } + public string Path { get; set; } = string.Empty; /// /// Creator ("Live version") /// - public string Creator { get; set; } + public string Creator { get; set; } = string.Empty; /// /// Minor version /// - public string MinorVersion { get; set; } + public string MinorVersion { get; set; } = string.Empty; /// /// Major version /// - public string MajorVersion { get; set; } + public string MajorVersion { get; set; } = string.Empty; /// /// Schema change count @@ -65,15 +68,15 @@ public LiveProject() /// /// The tracks this project contains /// - public IReadOnlyList Tracks { get; set; } + public IReadOnlyList Tracks { get; set; } /// /// The scenes this project contains /// - public IReadOnlyList Scenes { get; set; } + public IReadOnlyList Scenes { get; set; } /// /// The locators this project contains /// - public IReadOnlyList Locators { get; set; } + public IReadOnlyList Locators { get; set; } } \ No newline at end of file diff --git a/src/als-tools.core/Factories/TrackFactory.cs b/src/als-tools.core/Factories/TrackFactory.cs index 70ebc1f..1e21153 100644 --- a/src/als-tools.core/Factories/TrackFactory.cs +++ b/src/als-tools.core/Factories/TrackFactory.cs @@ -5,21 +5,21 @@ namespace AlsTools.Core.Factories; public static class TrackFactory { - public static ITrack CreateTrack(TrackType type, string effectiveName, string userName, string annotation, bool? isFrozen, TrackDelay trackDelay, int? parentGroupId = null) + public static ITrack CreateTrack(TrackType type, string effectiveName, string userName, string annotation, bool? isFrozen, TrackDelay trackDelay, int parentGroupId) { ITrack track = type switch { - TrackType.Audio => track = new AudioTrack(), - TrackType.Midi => track = new MidiTrack(), - TrackType.Return => track = new ReturnTrack(), - TrackType.Group => track = new GroupTrack(), - _ => track = new MasterTrack() + TrackType.Audio => new AudioTrack(), + TrackType.Midi => new MidiTrack(), + TrackType.Return => new ReturnTrack(), + TrackType.Group => new GroupTrack(), + _ => new MasterTrack() }; return SetDefaultProperties(track, effectiveName, userName, annotation, isFrozen, trackDelay, parentGroupId); } - private static ITrack SetDefaultProperties(ITrack track, string effectiveName, string userName, string annotation, bool? isFrozen, TrackDelay trackDelay, int? parentGroupId = null) + private static ITrack SetDefaultProperties(ITrack track, string effectiveName, string userName, string annotation, bool? isFrozen, TrackDelay trackDelay, int parentGroupId) { track.EffectiveName = effectiveName; track.UserName = userName; @@ -27,7 +27,7 @@ private static ITrack SetDefaultProperties(ITrack track, string effectiveName, s track.IsFrozen = isFrozen; track.TrackDelay = trackDelay; track.TrackGroupId = parentGroupId; - + return track; } } diff --git a/src/als-tools.core/ValueObjects/Devices/BaseDevice.cs b/src/als-tools.core/ValueObjects/Devices/BaseDevice.cs index 23077c8..31ef85b 100644 --- a/src/als-tools.core/ValueObjects/Devices/BaseDevice.cs +++ b/src/als-tools.core/ValueObjects/Devices/BaseDevice.cs @@ -14,11 +14,11 @@ public BaseDevice(DeviceFamily family) public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } = string.Empty; - public string UserName { get; set; } + public string UserName { get; set; } = string.Empty; - public string Annotation { get; set; } + public string Annotation { get; set; } = string.Empty; public DeviceFamily Family { get; protected set; } } diff --git a/src/als-tools.core/ValueObjects/Devices/IDevice.cs b/src/als-tools.core/ValueObjects/Devices/IDevice.cs index 8345b38..1ab53d1 100644 --- a/src/als-tools.core/ValueObjects/Devices/IDevice.cs +++ b/src/als-tools.core/ValueObjects/Devices/IDevice.cs @@ -11,7 +11,7 @@ public interface IDevice /// The device original, factory name /// string Name { get; set; } - + /// /// The name the user has given to the device /// diff --git a/src/als-tools.core/ValueObjects/Locator.cs b/src/als-tools.core/ValueObjects/Locator.cs index b0574a5..e763de9 100644 --- a/src/als-tools.core/ValueObjects/Locator.cs +++ b/src/als-tools.core/ValueObjects/Locator.cs @@ -10,20 +10,20 @@ public class Locator /// /// The time point where the location is set /// - public int? Time { get; set; } + public int Time { get; set; } /// /// Locator name (displayed in arrangement window) /// - public string Name { get; set; } + public string Name { get; set; } = string.Empty; /// /// Locator notes /// - public string Annotation { get; set; } + public string Annotation { get; set; } = string.Empty; /// /// Whether or not the locator is set as Song Start /// - public bool? IsSongStart { get; set; } + public bool IsSongStart { get; set; } } \ No newline at end of file diff --git a/src/als-tools.core/ValueObjects/Scene.cs b/src/als-tools.core/ValueObjects/Scene.cs index 65ac0ba..24f1cf8 100644 --- a/src/als-tools.core/ValueObjects/Scene.cs +++ b/src/als-tools.core/ValueObjects/Scene.cs @@ -5,35 +5,35 @@ public class Scene /// /// Scene number (Id attribute) /// - public int? Number { get; set; } + public int Number { get; set; } /// /// Scene name /// - public string Name { get; set; } + public string Name { get; set; } = string.Empty; /// /// Scene notes /// - public string Annotation { get; set; } + public string Annotation { get; set; } = string.Empty; /// /// The scene BPM/Tempo /// - public int? Tempo { get; set; } + public int Tempo { get; set; } /// /// Whether a tempo/BPM is set /// - public bool? IsTempoEnabled { get; set; } + public bool IsTempoEnabled { get; set; } /// /// The scene time signature Id. This is probably a bit mask value. /// - public int? TimeSignatureId { get; set; } + public int TimeSignatureId { get; set; } /// /// Whether a time signature is set /// - public bool? IsTimeSignatureEnabled { get; set; } + public bool IsTimeSignatureEnabled { get; set; } } \ No newline at end of file diff --git a/src/als-tools.core/ValueObjects/Tracks/AudioTrack.cs b/src/als-tools.core/ValueObjects/Tracks/AudioTrack.cs index 3ce5889..4d20329 100644 --- a/src/als-tools.core/ValueObjects/Tracks/AudioTrack.cs +++ b/src/als-tools.core/ValueObjects/Tracks/AudioTrack.cs @@ -5,4 +5,4 @@ public class AudioTrack : BaseTrack, ITrack public AudioTrack() : base(TrackType.Audio) { } -} +} diff --git a/src/als-tools.core/ValueObjects/Tracks/BaseTrack.cs b/src/als-tools.core/ValueObjects/Tracks/BaseTrack.cs index 25d7896..1fb8f42 100644 --- a/src/als-tools.core/ValueObjects/Tracks/BaseTrack.cs +++ b/src/als-tools.core/ValueObjects/Tracks/BaseTrack.cs @@ -4,6 +4,8 @@ namespace AlsTools.Core.ValueObjects.Tracks; public abstract class BaseTrack : ITrack { + public const int DefaultGroupId = -1; + public BaseTrack(TrackType type) { StockDevices = new List(); @@ -20,9 +22,9 @@ public BaseTrack(TrackType type) // /// // public int Id { get; set; } - public string UserName { get; set; } + public string UserName { get; set; } = string.Empty; - public string EffectiveName { get; set; } + public string EffectiveName { get; set; } = string.Empty; public TrackType Type { get; set; } @@ -32,30 +34,30 @@ public BaseTrack(TrackType type) public IList MaxForLiveDevices { get; protected set; } - public string Annotation { get; set; } + public string Annotation { get; set; } = string.Empty; - public GroupTrack ParentGroupTrack { get; set; } + public GroupTrack? ParentGroupTrack { get; set; } public bool IsPartOfGroup => ParentGroupTrack != null; public TrackDelay TrackDelay { get; set; } - - public int? TrackGroupId { get; set; } - + + public int TrackGroupId { get; set; } + public bool? IsFrozen { get; set; } public void AddDevice(IDevice device) { - //TODO: should I get rid of the specific collections (stock, plugins, max4live) and put all devices in a single collection? - - List l = new List(); + if (device == null) + throw new ArgumentNullException(nameof(device)); + //TODO: should I get rid of the specific collections (stock, plugins, max4live) and put all devices in a single collection? if (device.Family.Type == DeviceType.Plugin) - Plugins.Add(device as PluginDevice); - if (device.Family.Type == DeviceType.Stock) - StockDevices.Add(device as LiveDevice); + Plugins.Add((PluginDevice)device); + else if (device.Family.Type == DeviceType.Stock) + StockDevices.Add((LiveDevice)device); else - MaxForLiveDevices.Add(device as MaxForLiveDevice); + MaxForLiveDevices.Add((MaxForLiveDevice)device); } public void AddDevices(IEnumerable devices) diff --git a/src/als-tools.core/ValueObjects/Tracks/GroupTrack.cs b/src/als-tools.core/ValueObjects/Tracks/GroupTrack.cs index 5a2aabe..0a64e76 100644 --- a/src/als-tools.core/ValueObjects/Tracks/GroupTrack.cs +++ b/src/als-tools.core/ValueObjects/Tracks/GroupTrack.cs @@ -15,4 +15,4 @@ public GroupTrack(IList childrenTracks) : base(TrackType.Group) /// The children tracks that this group track groups under it. /// public IList ChildrenTracks { get; set; } //TODO: this shouldn`t be allowed to be set from external... -} +} \ No newline at end of file diff --git a/src/als-tools.core/ValueObjects/Tracks/ITrack.cs b/src/als-tools.core/ValueObjects/Tracks/ITrack.cs index 77d5e27..29a6da3 100644 --- a/src/als-tools.core/ValueObjects/Tracks/ITrack.cs +++ b/src/als-tools.core/ValueObjects/Tracks/ITrack.cs @@ -17,7 +17,7 @@ public interface ITrack string EffectiveName { get; set; } /// - /// The track type. + /// The track type. /// /// TrackType Type { get; set; } @@ -37,14 +37,14 @@ public interface ITrack // /// Can be null. TrackGroupId property. // /// TODO: this shouldn't be here, since Master and Return tracks can't be grouped. // /// - // GroupTrack ParentGroupTrack { get; set; } //TODO: is it really necessary? + // GroupTrack ParentGroupTrack { get; set; } //TODO: is it really necessary? /// /// The group track Id which this track belongs to, if any. - /// Can be null. TrackGroupId property. + /// Can be null? TrackGroupId property. /// TODO: this shouldn't be here, since Master and Return tracks can't be grouped. /// - int? TrackGroupId { get; set; } //TODO: is it really necessary? + int TrackGroupId { get; set; } //TODO: is it really necessary? /// /// Whether or not this track is part of a group track diff --git a/src/als-tools.core/ValueObjects/Tracks/MidiTrack.cs b/src/als-tools.core/ValueObjects/Tracks/MidiTrack.cs index 7d053aa..cc8b8c5 100644 --- a/src/als-tools.core/ValueObjects/Tracks/MidiTrack.cs +++ b/src/als-tools.core/ValueObjects/Tracks/MidiTrack.cs @@ -5,4 +5,4 @@ public class MidiTrack : BaseTrack, ITrack public MidiTrack() : base(TrackType.Midi) { } -} +} diff --git a/src/als-tools.core/ValueObjects/Tracks/ReturnTrack.cs b/src/als-tools.core/ValueObjects/Tracks/ReturnTrack.cs index 4a4f0e4..c726973 100644 --- a/src/als-tools.core/ValueObjects/Tracks/ReturnTrack.cs +++ b/src/als-tools.core/ValueObjects/Tracks/ReturnTrack.cs @@ -5,4 +5,4 @@ public class ReturnTrack : BaseTrack, ITrack public ReturnTrack() : base(TrackType.Return) { } -} +} diff --git a/src/als-tools.infrastructure/EmbeddedDatabaseContext.cs b/src/als-tools.infrastructure/EmbeddedDatabaseContext.cs index 4d824dc..493ffc0 100644 --- a/src/als-tools.infrastructure/EmbeddedDatabaseContext.cs +++ b/src/als-tools.infrastructure/EmbeddedDatabaseContext.cs @@ -11,9 +11,9 @@ public class EmbeddedDatabaseContext : IEmbeddedDatabaseContext private readonly ILogger logger; private readonly IOptions options; private bool isInitialized = false; - private IDocumentStore documentStore = null; + private IDocumentStore? documentStore; - public IDocumentStore DocumentStore + public IDocumentStore DocumentStore { get { @@ -33,7 +33,7 @@ public EmbeddedDatabaseContext(ILogger logger, IOptions public void Initialize() { logger.LogDebug("Starting database server..."); - + EmbeddedServer.Instance.StartServer(new ServerOptions { ServerUrl = options.Value.ServerUrl, diff --git a/src/als-tools.infrastructure/Extractors/MaxForLiveSorts/BaseMaxForLiveSortExtractor.cs b/src/als-tools.infrastructure/Extractors/MaxForLiveSorts/BaseMaxForLiveSortExtractor.cs index 930fb4a..a329804 100644 --- a/src/als-tools.infrastructure/Extractors/MaxForLiveSorts/BaseMaxForLiveSortExtractor.cs +++ b/src/als-tools.infrastructure/Extractors/MaxForLiveSorts/BaseMaxForLiveSortExtractor.cs @@ -21,10 +21,10 @@ public IDevice ExtractFromXml(XPathNavigator pluginDescNode) var device = new MaxForLiveDevice(deviceSort) { - Id = pluginDescNode.SelectSingleNode(@"@Id").ValueAsInt, - Name = GetMaxForLiveDeviceNameFromXmlNodePath(pluginDescNode.SelectSingleNode(@"SourceContext/Value/BranchSourceContext/OriginalFileRef/FileRef/Path/@Value")?.Value), - UserName = pluginDescNode.SelectSingleNode(@"UserName/@Value")?.Value, - Annotation = pluginDescNode.SelectSingleNode(@"Annotation/@Value")?.Value + Id = pluginDescNode.SelectSingleNode(@"@Id")!.ValueAsInt, + Name = GetMaxForLiveDeviceNameFromXmlNodePath(pluginDescNode.SelectSingleNode(@"SourceContext/Value/BranchSourceContext/OriginalFileRef/FileRef/Path/@Value")!.Value), + UserName = pluginDescNode.SelectSingleNode(@"UserName/@Value")!.Value, + Annotation = pluginDescNode.SelectSingleNode(@"Annotation/@Value")!.Value }; return device; diff --git a/src/als-tools.infrastructure/Extractors/PluginDeviceExtractor.cs b/src/als-tools.infrastructure/Extractors/PluginDeviceExtractor.cs index 91c7261..55ab061 100644 --- a/src/als-tools.infrastructure/Extractors/PluginDeviceExtractor.cs +++ b/src/als-tools.infrastructure/Extractors/PluginDeviceExtractor.cs @@ -36,7 +36,7 @@ private IPluginFormatExtractor GetPluginFormatExtractor(XPathNavigator deviceNod { var pluginDescNode = deviceNode.Select(@"PluginDesc"); pluginDescNode.MoveNext(); - if (pluginDescNode.Current.HasChildren) + if (pluginDescNode.Current?.HasChildren ?? false) { if (pluginDescNode.Current.MoveToFirstChild()) { diff --git a/src/als-tools.infrastructure/Extractors/PluginFormats/BasePluginFormatExtractor.cs b/src/als-tools.infrastructure/Extractors/PluginFormats/BasePluginFormatExtractor.cs index d4d609c..fbd8ff3 100644 --- a/src/als-tools.infrastructure/Extractors/PluginFormats/BasePluginFormatExtractor.cs +++ b/src/als-tools.infrastructure/Extractors/PluginFormats/BasePluginFormatExtractor.cs @@ -18,15 +18,15 @@ public virtual IDevice ExtractFromXml(XPathNavigator pluginDeviceNode) { logger.LogDebug("----"); logger.LogDebug("Extracting {@PluginFormat} plugin device...", pluginFormat); - var pluginName = pluginDeviceNode.SelectSingleNode(PluginNameXpath)?.Value; + var pluginName = pluginDeviceNode.SelectSingleNode(PluginNameXpath)!.Value; logger.LogDebug("Plugin found: {@PluginName} ", pluginName); var sort = GetPluginSort(pluginDeviceNode, pluginName); var pluginDevice = new PluginDevice(sort, pluginFormat); pluginDevice.Name = pluginName; - pluginDevice.UserName = pluginDeviceNode.SelectSingleNode(@"UserName/@Value")?.Value; - pluginDevice.Annotation = pluginDeviceNode.SelectSingleNode(@"Annotation/@Value")?.Value; - pluginDevice.Id = pluginDeviceNode.SelectSingleNode(@"@Id").ValueAsInt; + pluginDevice.UserName = pluginDeviceNode.SelectSingleNode(@"UserName/@Value")!.Value; + pluginDevice.Annotation = pluginDeviceNode.SelectSingleNode(@"Annotation/@Value")!.Value; + pluginDevice.Id = pluginDeviceNode.SelectSingleNode(@"@Id")!.ValueAsInt; return pluginDevice; } diff --git a/src/als-tools.infrastructure/Extractors/PluginFormats/Vst2PluginFormatExtractor.cs b/src/als-tools.infrastructure/Extractors/PluginFormats/Vst2PluginFormatExtractor.cs index 8d468eb..8f5c276 100644 --- a/src/als-tools.infrastructure/Extractors/PluginFormats/Vst2PluginFormatExtractor.cs +++ b/src/als-tools.infrastructure/Extractors/PluginFormats/Vst2PluginFormatExtractor.cs @@ -28,7 +28,7 @@ public Vst2PluginFormatExtractor(ILogger logger) : ba protected override DeviceSort GetPluginSort(XPathNavigator pluginDescNode, string pluginName) { - var category = pluginDescNode.SelectSingleNode(@"PluginDesc/VstPluginInfo/Category/@Value")?.Value; + var category = pluginDescNode.SelectSingleNode(@"PluginDesc/VstPluginInfo/Category/@Value")!.Value; // Voxengo SPAN, for instance (and I have no idea why), has if (!deviceSortsByCategory.ContainsKey(category)) diff --git a/src/als-tools.infrastructure/Extractors/PluginFormats/Vst3PluginFormatExtractor.cs b/src/als-tools.infrastructure/Extractors/PluginFormats/Vst3PluginFormatExtractor.cs index c48ad79..f951d04 100644 --- a/src/als-tools.infrastructure/Extractors/PluginFormats/Vst3PluginFormatExtractor.cs +++ b/src/als-tools.infrastructure/Extractors/PluginFormats/Vst3PluginFormatExtractor.cs @@ -28,7 +28,7 @@ public Vst3PluginFormatExtractor(ILogger logger) : ba protected override DeviceSort GetPluginSort(XPathNavigator pluginDescNode, string pluginName) { - var deviceType = pluginDescNode.SelectSingleNode(@"PluginDesc/Vst3PluginInfo/DeviceType/@Value")?.Value; + var deviceType = pluginDescNode.SelectSingleNode(@"PluginDesc/Vst3PluginInfo/DeviceType/@Value")!.Value; if (!deviceSortsByDeviceType.ContainsKey(deviceType)) { diff --git a/src/als-tools.infrastructure/Extractors/StockDevices/BaseStockDeviceExtractor.cs b/src/als-tools.infrastructure/Extractors/StockDevices/BaseStockDeviceExtractor.cs index 718d4fd..3c68a83 100644 --- a/src/als-tools.infrastructure/Extractors/StockDevices/BaseStockDeviceExtractor.cs +++ b/src/als-tools.infrastructure/Extractors/StockDevices/BaseStockDeviceExtractor.cs @@ -28,9 +28,9 @@ public virtual IDevice ExtractFromXml(XPathNavigator deviceNode) logger.LogDebug("Device name: {DeviceName}", device.Name); - device.UserName = deviceNode.SelectSingleNode(@"UserName/@Value")?.Value; - device.Annotation = deviceNode.SelectSingleNode(@"Annotation/@Value")?.Value; - device.Id = deviceNode.SelectSingleNode(@"@Id").ValueAsInt; + device.UserName = deviceNode.SelectSingleNode(@"UserName/@Value")!.Value; + device.Annotation = deviceNode.SelectSingleNode(@"Annotation/@Value")!.Value; + device.Id = deviceNode.SelectSingleNode(@"@Id")!.ValueAsInt; return device; } diff --git a/src/als-tools.infrastructure/Handlers/DeviceExtractionHandler.cs b/src/als-tools.infrastructure/Handlers/DeviceExtractionHandler.cs index 01e49f6..c484777 100644 --- a/src/als-tools.infrastructure/Handlers/DeviceExtractionHandler.cs +++ b/src/als-tools.infrastructure/Handlers/DeviceExtractionHandler.cs @@ -8,7 +8,7 @@ public class DeviceExtractionHandler : IDeviceExtractionHandler { private readonly ILogger logger; private readonly IDictionary deviceExtractors; - + private static readonly IDictionary deviceTypesByNodeDesc = new Dictionary() { [DeviceTypeNodeName.Plugin] = DeviceType.Plugin, @@ -35,7 +35,7 @@ public IReadOnlyList ExtractFromXml(XPathNavigator nav) var devices = new List(); var devicesIterator = nav.Select(@"DeviceChain/DeviceChain/Devices"); devicesIterator.MoveNext(); - if (devicesIterator.Current.HasChildren) + if (devicesIterator.Current?.HasChildren ?? false) { if (devicesIterator.Current.MoveToFirstChild()) { @@ -68,7 +68,7 @@ private IDevice ExtractDeviceFromNode(XPathNavigator deviceNode) private IDeviceExtractor GetDeviceExtractorByDeviceType(DeviceType type) { logger.LogDebug("Getting device extractor by device type ({@DeviceType})...", type); - + var extractor = deviceExtractors[type]; logger.LogDebug("Found device extractor: {@DeviceExtractor})", extractor); @@ -82,7 +82,7 @@ private DeviceType GetDeviceTypeByDeviceNodeName(string deviceNodeName) var deviceNodeNameUpper = deviceNodeName.ToUpperInvariant(); DeviceType type; - + if (deviceTypesByNodeDesc.TryGetValue(deviceNodeNameUpper, out type)) return type; diff --git a/src/als-tools.infrastructure/Handlers/LiveProjectExtractionHandler.cs b/src/als-tools.infrastructure/Handlers/LiveProjectExtractionHandler.cs index 95df225..9e03844 100644 --- a/src/als-tools.infrastructure/Handlers/LiveProjectExtractionHandler.cs +++ b/src/als-tools.infrastructure/Handlers/LiveProjectExtractionHandler.cs @@ -18,9 +18,9 @@ public IReadOnlyList ExtractFromXml(XPathNavigator nav) var project = new LiveProject() { - Creator = GetProjectAttribute(nav, "Creator"), - MajorVersion = GetProjectAttribute(nav, "MajorVersion"), - MinorVersion = GetProjectAttribute(nav, "MinorVersion"), + Creator = GetProjectAttribute(nav, "Creator")!, + MajorVersion = GetProjectAttribute(nav, "MajorVersion")!, + MinorVersion = GetProjectAttribute(nav, "MinorVersion")!, SchemaChangeCount = GetProjectAttribute(nav, "SchemaChangeCount"), Tempo = GetMasterTrackMixerAttribute(nav, "Tempo"), TimeSignature = GetMasterTrackMixerAttribute(nav, "TimeSignature"), @@ -47,7 +47,7 @@ private T GetXpathValue(XPathNavigator nav, string expression) { var node = nav.SelectSingleNode(expression); if (node == null) - return default(T); + return default(T)!; var result = (T)node.ValueAs(typeof(T)); return result; diff --git a/src/als-tools.infrastructure/Handlers/LocatorExtractionHandler.cs b/src/als-tools.infrastructure/Handlers/LocatorExtractionHandler.cs index 93aaac4..d53f728 100644 --- a/src/als-tools.infrastructure/Handlers/LocatorExtractionHandler.cs +++ b/src/als-tools.infrastructure/Handlers/LocatorExtractionHandler.cs @@ -25,10 +25,10 @@ public IReadOnlyList ExtractFromXml(XPathNavigator nav) var locator = new Locator() { Number = locatorNode.SelectSingleNode(@"@Id")?.ValueAsInt, - Name = locatorNode.SelectSingleNode(@"Name/@Value")?.Value, - Annotation = locatorNode.SelectSingleNode(@"Annotation/@Value")?.Value, - Time = locatorNode.SelectSingleNode(@"Time/@Value")?.ValueAsInt, - IsSongStart = locatorNode.SelectSingleNode(@"IsSongStart/@Value")?.ValueAsBoolean + Name = locatorNode.SelectSingleNode(@"Name/@Value")!.Value, + Annotation = locatorNode.SelectSingleNode(@"Annotation/@Value")!.Value, + Time = locatorNode.SelectSingleNode(@"Time/@Value")!.ValueAsInt, + IsSongStart = locatorNode.SelectSingleNode(@"IsSongStart/@Value")!.ValueAsBoolean }; locators.Add(locator); diff --git a/src/als-tools.infrastructure/Handlers/SceneExtractionHandler.cs b/src/als-tools.infrastructure/Handlers/SceneExtractionHandler.cs index 1cb2ae6..848c05a 100644 --- a/src/als-tools.infrastructure/Handlers/SceneExtractionHandler.cs +++ b/src/als-tools.infrastructure/Handlers/SceneExtractionHandler.cs @@ -15,7 +15,7 @@ public IReadOnlyList ExtractFromXml(XPathNavigator nav) { logger.LogDebug("----"); logger.LogDebug("Extracting Scenes from XML..."); - + var expression = @"/Ableton/LiveSet/Scenes/Scene"; var scenesIterator = nav.Select(expression); var scenes = new List(); @@ -24,13 +24,13 @@ public IReadOnlyList ExtractFromXml(XPathNavigator nav) { var scene = new Scene() { - Number = sceneNode.SelectSingleNode(@"@Id")?.ValueAsInt, - Name = sceneNode.SelectSingleNode(@"Name/@Value")?.Value, - Annotation = sceneNode.SelectSingleNode(@"Annotation/@Value")?.Value, - Tempo = sceneNode.SelectSingleNode(@"Tempo/@Value")?.ValueAsInt, - IsTempoEnabled = sceneNode.SelectSingleNode(@"IsTempoEnabled/@Value")?.ValueAsBoolean, - TimeSignatureId = sceneNode.SelectSingleNode(@"TimeSignatureId/@Value")?.ValueAsInt, - IsTimeSignatureEnabled = sceneNode.SelectSingleNode(@"IsTimeSignatureEnabled/@Value")?.ValueAsBoolean + Number = sceneNode.SelectSingleNode(@"@Id")!.ValueAsInt, + Name = sceneNode.SelectSingleNode(@"Name/@Value")!.Value, + Annotation = sceneNode.SelectSingleNode(@"Annotation/@Value")!.Value, + Tempo = sceneNode.SelectSingleNode(@"Tempo/@Value")!.ValueAsInt, + IsTempoEnabled = sceneNode.SelectSingleNode(@"IsTempoEnabled/@Value")!.ValueAsBoolean, + TimeSignatureId = sceneNode.SelectSingleNode(@"TimeSignatureId/@Value")!.ValueAsInt, + IsTimeSignatureEnabled = sceneNode.SelectSingleNode(@"IsTimeSignatureEnabled/@Value")!.ValueAsBoolean }; scenes.Add(scene); diff --git a/src/als-tools.infrastructure/Handlers/TrackExtractionHandler.cs b/src/als-tools.infrastructure/Handlers/TrackExtractionHandler.cs index 77657a7..acce664 100644 --- a/src/als-tools.infrastructure/Handlers/TrackExtractionHandler.cs +++ b/src/als-tools.infrastructure/Handlers/TrackExtractionHandler.cs @@ -49,11 +49,11 @@ private void GetTrackByExpression(IList tracks, XPathNavigator nav, stri // Iterate through the tracks of the same type (audio, midi, return, master) foreach (XPathNavigator trackNode in tracksIterator) { - var effectiveName = trackNode.SelectSingleNode(@"Name/EffectiveName/@Value")?.Value; - var userName = trackNode.SelectSingleNode(@"Name/UserName/@Value")?.Value; - var annotation = trackNode.SelectSingleNode(@"Name/Annotation/@Value")?.Value; + var effectiveName = trackNode.SelectSingleNode(@"Name/EffectiveName/@Value")!.Value; + var userName = trackNode.SelectSingleNode(@"Name/UserName/@Value")!.Value; + var annotation = trackNode.SelectSingleNode(@"Name/Annotation/@Value")!.Value; var isFrozen = trackNode.SelectSingleNode(@"Freeze/@Value")?.ValueAsBoolean; - var groupId = trackNode.SelectSingleNode(@"TrackGroupId/@Value")?.ValueAsInt; + var groupId = trackNode.SelectSingleNode(@"TrackGroupId/@Value")!.ValueAsInt; var trackDelay = new TrackDelay() { Value = trackNode.SelectSingleNode(@"TrackDelay/Value/@Value")?.ValueAsInt, diff --git a/src/als-tools.infrastructure/Repositories/LiveProjectRavenDBRepository.cs b/src/als-tools.infrastructure/Repositories/LiveProjectRavenDBRepository.cs index 7f87fb6..ddbf0f7 100644 --- a/src/als-tools.infrastructure/Repositories/LiveProjectRavenDBRepository.cs +++ b/src/als-tools.infrastructure/Repositories/LiveProjectRavenDBRepository.cs @@ -36,11 +36,8 @@ public async Task InsertAsync(LiveProject project) public async Task InsertAsync(IEnumerable projects) { - BulkInsertOperation bulkInsert = null; - - try + await using (var bulkInsert = store.BulkInsert()) { - bulkInsert = store.BulkInsert(); int count = 0; foreach (var project in projects) { @@ -50,11 +47,6 @@ public async Task InsertAsync(IEnumerable projects) logger.LogDebug("Inserted {InsertedProjects} projects", count); } - finally - { - if (bulkInsert != null) - await bulkInsert.DisposeAsync().ConfigureAwait(false); - } } public async Task> GetProjectsContainingPluginsAsync(IEnumerable pluginsToLocate) diff --git a/src/als-tools.infrastructure/XmlNodeNames/LiveStockDeviceNodeNames.cs b/src/als-tools.infrastructure/XmlNodeNames/LiveStockDeviceNodeNames.cs index 37b52ce..7599a2c 100644 --- a/src/als-tools.infrastructure/XmlNodeNames/LiveStockDeviceNodeNames.cs +++ b/src/als-tools.infrastructure/XmlNodeNames/LiveStockDeviceNodeNames.cs @@ -3,7 +3,7 @@ namespace AlsTools.Infrastructure.XmlNodeNames; public static class LiveStockDeviceNodeNames { /// - /// A dictionary associating a stock device XML Node internal name to its readable name, which sometimes is different + /// A dictionary associating a stock device XML Node internal name to its readable name, which sometimes is different /// private static readonly IReadOnlyDictionary stockDeviceNamesByNodeInternalName; @@ -19,7 +19,7 @@ static LiveStockDeviceNodeNames() foreach (var field in fields) { - var key = field.GetValue(null).ToString().ToUpperInvariant(); + var key = field.GetValue(null)!.ToString()!.ToUpperInvariant(); var value = field.Name.Humanize(LetterCasing.Title); dic.Add(key, value); @@ -32,7 +32,7 @@ static LiveStockDeviceNodeNames() public static string GetDeviceNameByNodeName(string nodeName) { var key = nodeName.ToUpperInvariant(); - string value = null; + string? value; if (stockDeviceNamesByNodeInternalName.TryGetValue(key, out value)) return value; diff --git a/src/als-tools.ui.cli/CliOptions/InitDbOptions.cs b/src/als-tools.ui.cli/CliOptions/InitDbOptions.cs index f3bc0c5..93790d8 100644 --- a/src/als-tools.ui.cli/CliOptions/InitDbOptions.cs +++ b/src/als-tools.ui.cli/CliOptions/InitDbOptions.cs @@ -3,13 +3,14 @@ namespace AlsTools.Ui.Cli.CliOptions; [Verb("initdb", HelpText = @"Initialize the als-tools database with information extracted from Live sets, either from files or folders.")] public class InitDbOptions : CommonOptions { + [Option("folders", Required = true, SetName = "folders", Min = 1, HelpText = "The root folders to look for Live Sets, recursively including children folders. This option is mutually exclusive with the --files option.")] - public IReadOnlyCollection Folders { get; set; } + public IReadOnlyCollection Folders { get; set; } = new List(); [Option("include-backups", SetName = "folders", Default = false, HelpText = "Set it to true to include backup Live Sets.")] public bool IncludeBackups { get; set; } [Option("files", Required = true, SetName = "files", Min = 1, HelpText = "The files to extract Live Set information from. This option is mutually exclusive with the --folders option.")] - public IReadOnlyCollection Files { get; set; } + public IReadOnlyCollection Files { get; set; } = new List(); } \ No newline at end of file diff --git a/src/als-tools.ui.cli/CliOptions/LocateOptions.cs b/src/als-tools.ui.cli/CliOptions/LocateOptions.cs index ccc5d0c..ff81046 100644 --- a/src/als-tools.ui.cli/CliOptions/LocateOptions.cs +++ b/src/als-tools.ui.cli/CliOptions/LocateOptions.cs @@ -4,5 +4,5 @@ namespace AlsTools.Ui.Cli.CliOptions; public class LocateOptions : CommonOptions { [Option("plugin-names", Required = true, Min = 1, HelpText = "The plugin names to locate projects by.")] - public IReadOnlyCollection PluginsToLocate { get; set; } + public IReadOnlyCollection PluginsToLocate { get; set; } = new List(); } \ No newline at end of file diff --git a/src/als-tools.ui.cli/Exceptions/CommandLineParseException.cs b/src/als-tools.ui.cli/Exceptions/CommandLineParseException.cs index cd0785e..5335d94 100644 --- a/src/als-tools.ui.cli/Exceptions/CommandLineParseException.cs +++ b/src/als-tools.ui.cli/Exceptions/CommandLineParseException.cs @@ -3,7 +3,7 @@ namespace AlsTools.Ui.Cli.Exceptions; [System.Serializable] public class CommandLineParseException : Exception { - public IEnumerable Errors { get; private set; } + public IEnumerable? Errors { get; private set; } public CommandLineParseException() { } @@ -27,6 +27,6 @@ public CommandLineParseException(string message, IEnumerable errors, Syst } protected CommandLineParseException( - System.Runtime.Serialization.SerializationInfo info, - System.Runtime.Serialization.StreamingContext context) : base(info, context) { } + SerializationInfo info, + StreamingContext context) : base(info, context) { } } \ No newline at end of file diff --git a/src/als-tools.ui.cli/Program.Extra.cs b/src/als-tools.ui.cli/Program.Extra.cs index 767e694..80b095a 100644 --- a/src/als-tools.ui.cli/Program.Extra.cs +++ b/src/als-tools.ui.cli/Program.Extra.cs @@ -21,6 +21,8 @@ namespace AlsTools.Ui.Cli; public partial class Program { + // private static IConfigurationRoot configuration; + private static void SetupLogging(ParserResult parserResult) { Log.Debug("Setting up logging settings..."); @@ -64,8 +66,8 @@ private static void ConfigureServices(IServiceCollection serviceCollection) serviceCollection.AddLogging(); // Build configuration - configuration = new ConfigurationBuilder() - .SetBasePath(Directory.GetParent(AppContext.BaseDirectory).FullName) + var configuration = new ConfigurationBuilder() + .SetBasePath(Directory.GetParent(AppContext.BaseDirectory)?.FullName) .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true) .Build(); @@ -148,7 +150,13 @@ private static void AddStockDeviceExtractorsFromNodeNamesType(IDictionary Main(string[] args) diff --git a/src/als-tools.ui.cli/ui.cli.usings.cs b/src/als-tools.ui.cli/ui.cli.usings.cs index cae36e8..fb1a29e 100644 --- a/src/als-tools.ui.cli/ui.cli.usings.cs +++ b/src/als-tools.ui.cli/ui.cli.usings.cs @@ -8,3 +8,4 @@ global using System.Reflection; global using System.Text.Json; global using CommandLine; +global using System.Runtime.Serialization; \ No newline at end of file From 426f75cb870c01332da1775c595395edb0b4297f Mon Sep 17 00:00:00 2001 From: luizen Date: Sun, 29 May 2022 11:47:07 -0300 Subject: [PATCH 2/2] gitignore update --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index ef5f02d..df25664 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ src/als-tools.infrastructure/bin/* src/als-tools.ui.cli/bin/* src/als-tools.ui.cli/obj/* src/als-tools.ui.cli/output/* +ravendb-license.json