Skip to content
Snippets Groups Projects
Commit 20c21de6 authored by Petar Hristov's avatar Petar Hristov :speech_balloon:
Browse files

Done

parent 3133112b
No related branches found
No related tags found
1 merge request!7Breaking: Refactored the GraphDeployer
using Coscine.Configuration;
using Coscine.GraphDeployer.Logging;
using Coscine.Metadata;
using GitLabApiClient;
using GitLabApiClient.Models.Projects.Responses;
using LibGit2Sharp;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using NLog.Config;
using NLog.Extensions.Logging;
using System.Diagnostics;
......@@ -28,10 +25,9 @@ public class Program
ConfigurationItemFactory.Default.LayoutRenderers.RegisterDefinition("assembly-name", typeof(AssemblyNameLayoutRenderer));
ConfigurationItemFactory.Default.LayoutRenderers.RegisterDefinition("assembly-version", typeof(AssemblyVersionLayoutRenderer));
_logger = LoggerFactory.Create(builder => builder.AddNLog()).CreateLogger<Program>();
Token = Configuration.GetStringAndWait("coscine/global/gitlabtoken");
try
{
Token = Configuration.GetStringAndWait("coscine/global/gitlabtoken");
Run();
}
catch (Exception ex)
......@@ -103,10 +99,13 @@ public class Program
if (_rdfStoreConnector.HasGraph(graphName))
{
_logger.LogDebug("Clearing Graph {graphName}", graphName);
_rdfStoreConnector.ClearGraph(graphName);
_logger.LogInformation("Cleared Graph {graphName}", graphName);
}
else
{
_logger.LogInformation("No Graph {graphName}", graphName);
}
queries.Add($"ld_dir('{fileInfo.DirectoryName[2..].Replace("\\", "/")}', '{fileInfo.Name}', '{graphName}');");
}
......@@ -115,11 +114,11 @@ public class Program
foreach (var query in queries)
{
_logger.LogDebug("Executing queries {@queries}", queries);
ExecuteCommand(
"powershell.exe",
$"\"\\\"{query}\\\" | {virtuosoISQLLocation}\""
);
_logger.LogInformation("Query executed {@query}", query);
}
}
......@@ -127,7 +126,7 @@ public class Program
EmptyWorkingFolder();
}
Console.WriteLine("Done");
_logger.LogInformation("Done");
}
private static void ExecuteCommand(string fileName, string arguments)
......@@ -148,10 +147,12 @@ public class Program
process.Start();
string output = process.StandardOutput.ReadToEnd();
Console.WriteLine(output);
if (!string.IsNullOrWhiteSpace(output))
_logger.LogDebug("Executed queries {filename} {arguments} >>> {output}", fileName, arguments, output);
string errors = process.StandardError.ReadToEnd();
Console.WriteLine(errors);
if (!string.IsNullOrWhiteSpace(errors))
_logger.LogError("Errors during execution of command {filename} {arguments} >>> {errors}", fileName, arguments, errors);
}
public static void CloneGraphRepo(GraphRepo graphRepo, out bool success)
......@@ -177,17 +178,25 @@ public class Program
public static void EmptyWorkingFolder()
{
var directory = new DirectoryInfo(WorkingFolder);
_logger.LogInformation("Deleting {fileCount} files and {directoryCount} directories from {workingFolder}.", directory.EnumerateFiles().Count(), directory.EnumerateDirectories().Count(), WorkingFolder);
foreach (FileInfo file in directory.EnumerateFiles())
var filesToDelete = directory.EnumerateFiles("*.*", SearchOption.AllDirectories);
var dirsToDelete = directory.EnumerateDirectories();
_logger.LogInformation("Deleting {fileCount} files and {directoryCount} directories from {workingFolder}.", filesToDelete.Count(), dirsToDelete.Count(), WorkingFolder);
foreach (var file in filesToDelete)
{
file.Attributes = FileAttributes.Normal;
file.Delete();
}
foreach (DirectoryInfo dir in directory.EnumerateDirectories())
foreach (var dir in dirsToDelete)
{
dir.Delete(true);
}
}
private static FileAttributes RemoveAttribute(FileAttributes attributes, FileAttributes attributesToRemove)
{
return attributes & ~attributesToRemove;
}
private static void LogInnerException(Exception ex)
{
if (ex.InnerException is not null)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment