diff --git a/src/OrganizationDeployer/Program.cs b/src/OrganizationDeployer/Program.cs index d5b2dcb5afe751dea47c73e2c2ab9440027fb792..c31ef28089b78089f2163661b38f4a38f6865a63 100644 --- a/src/OrganizationDeployer/Program.cs +++ b/src/OrganizationDeployer/Program.cs @@ -14,26 +14,10 @@ namespace Coscine.OrganizationDeployer { public static void Main(string[] args) { - ProcessStartInfo startInfo = new ProcessStartInfo - { - FileName = @"powershell.exe", - Arguments = $@"& '{ Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "getOrganizations.ps1") }'", - RedirectStandardOutput = true, - RedirectStandardError = true, - UseShellExecute = false, - CreateNoWindow = true - }; - Process process = new Process - { - StartInfo = startInfo - }; - process.Start(); - - string output = process.StandardOutput.ReadToEnd(); - Console.WriteLine(output); - - string errors = process.StandardError.ReadToEnd(); - Console.WriteLine(errors); + ExecuteCommand( + "powershell.exe", + $@"& '{ Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "getOrganizations.ps1") }'" + ); var configuration = new ConsulConfiguration(); @@ -45,28 +29,68 @@ namespace Coscine.OrganizationDeployer VirtuosoManager virtuosoManager = new VirtuosoManager($"Server={virtuosoHost};Uid={virtuosoUser};pwd={virtuosoPassword}"); var _util = new Util(virtuosoServer); - foreach (var file in GetFiles("organizations").Where((file) => file.Contains(".ttl"))) + var folder = "/voc"; + var virtuosoISQLLocation = configuration.GetString( + "coscine/local/virtuoso/isql", + "C:/Programs/Virtuoso/bin/isql.exe" + ); + var queries = new List<string>(); + foreach (var file in GetFiles(folder).Where((file) => file.Contains(".ttl"))) { + var fileInfo = new FileInfo(file); var graph = new Graph(); graph.LoadFromFile(file); var graphName = graph.BaseUri.ToString(); + if (_util.HasGraph(graphName)) { Console.WriteLine($"Clearing {graphName}"); _util.ClearGraph(graphName); } - else - { - Console.WriteLine($"Creating {graphName}"); - _util.CreateNamedGraph(graphName); - } - - Console.WriteLine($"Adding to {graphName}"); - virtuosoManager.SaveGraph(graph); + + queries.Add($"ld_dir('{fileInfo.DirectoryName.Substring(2).Replace("\\", "/")}', '{fileInfo.Name}', '{graphName}');"); + } + queries.Add($"rdf_loader_run ();"); + queries.Add($"DELETE from DB.DBA.load_list where 1=1;"); + + foreach (var query in queries) + { + ExecuteCommand( + "powershell.exe", + $"\"\\\"{query}\\\" | {virtuosoISQLLocation}\"" + ); } + Console.WriteLine("Done"); } + private static void ExecuteCommand(string fileName, string arguments) + { + ProcessStartInfo startInfo = new ProcessStartInfo + { + FileName = fileName, + Arguments = arguments, + RedirectStandardOutput = true, + RedirectStandardError = true, + UseShellExecute = false, + CreateNoWindow = true, + }; + using (var process = new Process + { + StartInfo = startInfo + }) + { + process.Start(); + + string output = process.StandardOutput.ReadToEnd(); + Console.WriteLine(output); + + string errors = process.StandardError.ReadToEnd(); + Console.WriteLine(errors); + } + } + + private static IEnumerable<string> GetFiles(string path) { Queue<string> queue = new Queue<string>(); diff --git a/src/OrganizationDeployer/getOrganizations.ps1 b/src/OrganizationDeployer/getOrganizations.ps1 index 2d265fb7606ca84e3fdf4f70a3bc8f01e20ab444..34e0498c7d2027ca6a54c89ab21344dd4bcdca7b 100644 --- a/src/OrganizationDeployer/getOrganizations.ps1 +++ b/src/OrganizationDeployer/getOrganizations.ps1 @@ -6,10 +6,32 @@ $gitlab_token = & $fullPath kv get "coscine/global/gitlabtoken" Push-Location $PSScriptRoot +$organizationsPath = 'organizations' +# Twice remove, because of: https://stackoverflow.com/questions/7909167/how-to-quietly-remove-a-directory-with-content-in-powershell#comment10316056_7909195 +If(Test-Path $organizationsPath) { Remove-Item -LiteralPath $organizationsPath -Force -Recurse } +If(Test-Path $organizationsPath) { Remove-Item -LiteralPath $organizationsPath -Force -Recurse } + git clone https://gitlab-ci-token:$gitlab_token@git.rwth-aachen.de/coscine/organizations.git cd organizations -git checkout Master +$pagebranch = & $fullPath kv get 'coscine/local/organizationdeployer/branch' + +if ($pagebranch -And $pagebranch -ne 'master' ) { + git checkout $pagebranch + git pull +} + +cd .. + +$path = '/voc' + +# Twice remove, because of: https://stackoverflow.com/questions/7909167/how-to-quietly-remove-a-directory-with-content-in-powershell#comment10316056_7909195 +If(Test-Path $path) { Remove-Item -LiteralPath $path -Force -Recurse } +If(Test-Path $path) { Remove-Item -LiteralPath $path -Force -Recurse } + +New-Item -ItemType Directory -Force -Path $path + +Copy-Item './organizations/*' $path -Recurse; Pop-Location \ No newline at end of file