Skip to content

Commit

Permalink
Merge pull request #22 from luizen/develop
Browse files Browse the repository at this point in the history
Merging develop to main. Adding several features and fixes.
  • Loading branch information
luizen authored May 7, 2022
2 parents 6309d30 + 039e178 commit 6152240
Show file tree
Hide file tree
Showing 40 changed files with 731 additions and 560 deletions.
Binary file modified .DS_Store
Binary file not shown.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
.DS_Store
/obj/
/bin/
*.dll
*.pdb
*.cache
/LiteDb/
.DS_Store
output/*
15 changes: 10 additions & 5 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,16 @@
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/net6.0/als-tools.dll",
//"args": ["--locate=HG2;bx_tunner", "--folder=/Users/zenluiz/Desktop/Testes ALS"],
"args": ["--locate=kickbox;replika"],
// "args": ["--list"],
// "args": ["--initdb", "--folder=/Users/zenluiz/Desktop/Testes ALS"],
// "args": ["--initdb", "--folder=/Users/zenluiz/Splice"],

//"args": ["locate", "--plugin-names", "HG2", "bx_tunner"],
//"args": ["locate", "--plugin-names", "kickbox", "replika"],
//"args": ["locate", "--plugin-names", "A1StereoControl"],
//"args": ["list"],
//"args": ["count"],
//"args": ["initdb", "--folders", "/Users\/zenluiz/Desktop/Testes ALS/Projects folder 1", "/Users/zenluiz/Desktop/Testes ALS/Projects folder 2"],
"args": ["initdb", "--folders", "~/Desktop/Testes ALS/Projects folder 1"],
//"args": ["initdb", "--folders", "/Users/zenluiz/Splice"],

"cwd": "${workspaceFolder}",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
"console": "internalConsole",
Expand Down
6 changes: 5 additions & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@
"/property:GenerateFullPaths=true",
"/consoleloggerparameters:NoSummary"
],
"problemMatcher": "$msCompile"
"problemMatcher": "$msCompile",
"group": {
"kind": "build",
"isDefault": true
}
},
{
"label": "clean",
Expand Down
83 changes: 40 additions & 43 deletions App.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,72 +2,69 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using AlsTools.CliOptions;
using AlsTools.Core.Entities;
using AlsTools.Core.Interfaces;
using AlsTools.Exceptions;
using CommandLine;
using Microsoft.Extensions.Logging;

namespace AlsTools
{
public class App
{
private readonly ILogger<App> logger;
private readonly ILiveProjectService liveProjectService;
public App(ILogger<App> logger, ILiveProjectService liveProjectService)
private readonly ILiveProjectAsyncService liveProjectService;

public App(ILogger<App> logger, ILiveProjectAsyncService liveProjectService)
{
this.logger = logger;
this.liveProjectService = liveProjectService;
}

public async Task Run(ProgramArgs args)
public async Task Run(ParserResult<object> parserResult)
{
logger.LogDebug("App start");

if (args.InitDb)
{
int count = 0;
if (!string.IsNullOrEmpty(args.File))
count = liveProjectService.InitializeDbFromFile(args.File);
else
count = liveProjectService.InitializeDbFromFolder(args.Folder, args.IncludeBackups);

await Console.Out.WriteLineAsync($"\nTotal of projects loaded into DB: {count}");
}
else if (args.CountProjects)
{
int count = liveProjectService.CountProjects();
await parserResult.WithParsedAsync<InitDbOptions>(options => RunInitDb(options));
await parserResult.WithParsedAsync<CountOptions>(options => RunCount(options));
await parserResult.WithParsedAsync<ListOptions>(options => RunList(options));
await parserResult.WithParsedAsync<LocateOptions>(options => RunLocate(options));
await parserResult.WithNotParsedAsync(errors => { throw new CommandLineParseException(errors); });
}

await Console.Out.WriteLineAsync($"\nTotal of projects in the DB: {count}");
}
else if (args.ListPlugins)
{
var projects = liveProjectService.GetAllProjects().ToList();
await PrintProjectsAndPlugins(projects);
await Console.Out.WriteLineAsync($"\nTotal of projects: {projects.Count}");
}
else if (args.LocatePlugins)
{
var projects = liveProjectService.GetProjectsContainingPlugins(args.PluginsToLocate).ToList();
await PrintProjectsAndPlugins(projects);
await Console.Out.WriteLineAsync($"\nTotal of projects: {projects.Count}");
}
else if (args.Export)
{
var projects = liveProjectService.GetAllProjects().ToList();
await ExportProjectsAndPlugins(projects);
await Console.Out.WriteLineAsync($"\nTotal of projects: {projects.Count}");
}
private async Task RunInitDb(InitDbOptions options)
{
int count = 0;
if (options.Files.Any())
count = await liveProjectService.InitializeDbFromFilesAsync(options.Files);
else
{
throw new InvalidOperationException("Nothing to do?");
}
count = await liveProjectService.InitializeDbFromFoldersAsync(options.Folders, options.IncludeBackups);

await Console.Out.WriteLineAsync($"\nTotal of projects loaded into DB: {count}");
}

private async Task RunCount(CountOptions options)
{
int count = await liveProjectService.CountProjectsAsync();

await Console.Out.WriteLineAsync($"\nTotal of projects in the DB: {count}");
}

private Task ExportProjectsAndPlugins(List<LiveProject> projects)
private async Task RunList(ListOptions options)
{
throw new NotImplementedException();
var projects = (await liveProjectService.GetAllProjectsAsync()).ToList();
await PrintProjectsAndPlugins(projects);
await Console.Out.WriteLineAsync($"\nTotal of projects: {projects.Count}");
}

private async Task RunLocate(LocateOptions options)
{
var projects = (await liveProjectService.GetProjectsContainingPluginsAsync(options.PluginsToLocate)).ToList();
await PrintProjectsAndPlugins(projects);
await Console.Out.WriteLineAsync($"\nTotal of projects: {projects.Count}");
}

private async Task PrintProjectsAndPlugins(IEnumerable<LiveProject> projects)
{
foreach (var p in projects)
Expand All @@ -81,7 +78,7 @@ private async Task PrintProjectAndPlugins(LiveProject project)
await Console.Out.WriteLineAsync($"Live version (creator): {project.LiveVersion}");
await Console.Out.WriteLineAsync($"Full path: {project.Path}");
await Console.Out.WriteLineAsync("\tTracks and plugins:");

if (project.Tracks.Count == 0)
await Console.Out.WriteLineAsync("\t\tNo tracks found!");

Expand Down
9 changes: 9 additions & 0 deletions CliOptions/CountOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
using CommandLine;

namespace AlsTools.CliOptions
{
[Verb("count", HelpText = "Returns the total of projects stored in the als-tools database.")]
class CountOptions
{
}
}
21 changes: 21 additions & 0 deletions CliOptions/InitDbOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

using System.Collections.Generic;
using CommandLine;

namespace AlsTools.CliOptions
{
[Verb("initdb",
HelpText = @"Initialize the als-tools database with information extracted from Live sets, either from files or folders.")]
public class InitDbOptions
{
[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 IEnumerable<string> Folders { get; set; }

[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 IEnumerable<string> Files { get; set; }
}
}
10 changes: 10 additions & 0 deletions CliOptions/ListOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using CommandLine;

namespace AlsTools.CliOptions
{
[Verb("list", HelpText = "List all projects stored in the als-tools database.")]
public class ListOptions
{

}
}
12 changes: 12 additions & 0 deletions CliOptions/LocateOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Collections.Generic;
using CommandLine;

namespace AlsTools.CliOptions
{
[Verb("locate", HelpText = "Locates projects containing given plugins by their names.")]
class LocateOptions
{
[Option("plugin-names", Required = true, Min = 1, HelpText = "The plugin names to locate projects by.")]
public IEnumerable<string> PluginsToLocate { get; set; }
}
}
11 changes: 11 additions & 0 deletions Config/DbOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace AlsTools.Config
{
public class DbOptions
{
public string DataLocation { get; set; }

public string ServerUrl { get; set; }

public string DocumentStoreName { get; set; }
}
}
7 changes: 0 additions & 7 deletions Config/LiteDbOptions.cs

This file was deleted.

3 changes: 2 additions & 1 deletion Core/Entities/LiveProject.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Collections.Generic;
using AlsTools.Core.Entities.Tracks;

Expand All @@ -10,7 +11,7 @@ public LiveProject()
Tracks = new List<ITrack>();
}

public int Id { get; set; }
public string Id { get; set; }

public string Name { get; set; }

Expand Down
12 changes: 12 additions & 0 deletions Core/Interfaces/IEmbeddedDatabaseContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

using Raven.Client.Documents;

namespace AlsTools.Core.Interfaces
{
public interface IEmbeddedDatabaseContext
{
IDocumentStore DocumentStore { get; }

void Initialize();
}
}
21 changes: 21 additions & 0 deletions Core/Interfaces/ILiveProjectAsyncRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using AlsTools.Core.Entities;

namespace AlsTools.Core.Interfaces
{
public interface ILiveProjectAsyncRepository
{
Task InsertAsync(LiveProject project);

Task InsertAsync(IEnumerable<LiveProject> projects);

Task<IEnumerable<LiveProject>> GetProjectsContainingPluginsAsync(IEnumerable<string> pluginsToLocate);

Task<IEnumerable<LiveProject>> GetAllProjectsAsync();

Task DeleteAllAsync();

Task<int> CountProjectsAsync();
}
}
19 changes: 19 additions & 0 deletions Core/Interfaces/ILiveProjectAsyncService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using AlsTools.Core.Entities;

namespace AlsTools.Core.Interfaces
{
public interface ILiveProjectAsyncService
{
Task<int> InitializeDbFromFilesAsync(IEnumerable<string> filePaths);

Task<int> InitializeDbFromFoldersAsync(IEnumerable<string> folderPaths, bool includeBackupFolder);

Task<IEnumerable<LiveProject>> GetAllProjectsAsync();

Task<IEnumerable<LiveProject>> GetProjectsContainingPluginsAsync(IEnumerable<string> pluginsToLocate);

Task<int> CountProjectsAsync();
}
}
4 changes: 2 additions & 2 deletions Core/Interfaces/ILiveProjectFileSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ namespace AlsTools.Core.Interfaces
{
public interface ILiveProjectFileSystem
{
IEnumerable<FileInfo> LoadProjectFilesFromDirectory(string folderPath, bool includeBackupFolder);
IEnumerable<FileInfo> LoadProjectFilesFromDirectories(IEnumerable<string> folderPaths, bool includeBackupFolder);

FileInfo LoadProjectFileFromSetFile(string setFilePath);
IEnumerable<FileInfo> LoadProjectFilesFromSetFiles(IEnumerable<string> setFilePaths);
}
}
21 changes: 0 additions & 21 deletions Core/Interfaces/ILiveProjectRepository.cs

This file was deleted.

19 changes: 0 additions & 19 deletions Core/Interfaces/ILiveProjectService.cs

This file was deleted.

Loading

0 comments on commit 6152240

Please sign in to comment.