-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from P9-P10/dev
Proof of Concept Merge
- Loading branch information
Showing
65 changed files
with
5,774 additions
and
251 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
name: .NET | ||
|
||
on: push | ||
|
||
jobs: | ||
ubuntu-build: | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup .NET Core SDK | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: '6.0.x' | ||
- name: Restore dependencies | ||
run: dotnet restore | ||
- name: Build | ||
run: dotnet build --no-restore | ||
- name: Test | ||
run: dotnet test --no-build --verbosity normal | ||
|
||
windows-build: | ||
runs-on: windows-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Setup .Net Core SDK | ||
uses: actions/setup-dotnet@v3 | ||
with: | ||
dotnet-version: '6.0.x' | ||
- name: Restore dependencies | ||
run: dotnet restore | ||
- name: Build | ||
run: dotnet build --no-restore | ||
- name: Test | ||
run: dotnet test --no-build --verbosity normal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
6 changes: 0 additions & 6 deletions
6
.idea/.idea.GraphManipulation/.idea/projectSettingsUpdater.xml
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<component name="ProjectRunConfigurationManager"> | ||
<configuration default="false" name="Publish to linux-x64" type="DotNetFolderPublish" factoryName="Publish to folder"> | ||
<riderPublish configuration="Release" include_native_libs_for_self_extract="true" platform="Any CPU" produce_single_file="true" ready_to_run="true" runtime="linux-x64" self_contained="true" target_folder="$USER_HOME$/GraphManipulation" target_framework="net6.0" trim_unused_assemblies="true" uuid_high="7685552078552253963" uuid_low="-6018413118667333411" /> | ||
<method v="2" /> | ||
</configuration> | ||
</component> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
|
||
<configuration> | ||
<appSettings> | ||
|
||
</appSettings> | ||
<connectionStrings> | ||
|
||
</connectionStrings> | ||
</configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
using System.Configuration; | ||
|
||
namespace GraphManipulation.Configuration; | ||
|
||
public static class ConfigurationHandler | ||
{ | ||
private const string OntologyKey = "OntologyPath"; | ||
private const string GraphStorageKey = "GraphStorageConnectionString"; | ||
|
||
public static string GetConnectionString(Uri datastoreUri) | ||
{ | ||
return ConfigurationManager.ConnectionStrings[datastoreUri.ToString()].ConnectionString; | ||
} | ||
|
||
public static string? GetOntologyPath() | ||
{ | ||
return ConfigurationManager.AppSettings[OntologyKey]; | ||
} | ||
|
||
// Heavily inspired by | ||
// https://learn.microsoft.com/en-us/dotnet/api/system.configuration.configurationmanager?view=dotnet-plat-ext-7.0 | ||
public static void UpdateOntologyPath(string value) | ||
{ | ||
var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); | ||
var settings = configFile.AppSettings.Settings; | ||
if (settings[OntologyKey] is null) | ||
{ | ||
settings.Add(OntologyKey, value); | ||
} | ||
else | ||
{ | ||
settings[OntologyKey].Value = value; | ||
} | ||
|
||
configFile.Save(ConfigurationSaveMode.Modified); | ||
ConfigurationManager.RefreshSection(configFile.AppSettings.SectionInformation.Name); | ||
} | ||
|
||
public static string? GetGraphStorageConnectionString() | ||
{ | ||
try | ||
{ | ||
return ConfigurationManager.ConnectionStrings[GraphStorageKey].ConnectionString; | ||
} | ||
catch (Exception) | ||
{ | ||
return null; | ||
} | ||
} | ||
|
||
// Heavily inspired by | ||
// https://learn.microsoft.com/en-us/dotnet/api/system.configuration.configurationmanager?view=dotnet-plat-ext-7.0 | ||
public static void UpdateGraphStorageConnectionString(string value) | ||
{ | ||
var configFile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); | ||
var settings = configFile.ConnectionStrings.ConnectionStrings; | ||
if (settings[GraphStorageKey] is null) | ||
{ | ||
settings.Add(new ConnectionStringSettings(GraphStorageKey, value)); | ||
} | ||
else | ||
{ | ||
settings[GraphStorageKey].ConnectionString = value; | ||
} | ||
|
||
configFile.Save(ConfigurationSaveMode.Modified); | ||
ConfigurationManager.RefreshSection(configFile.ConnectionStrings.SectionInformation.Name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
using GraphManipulation.Models.Stores; | ||
using GraphManipulation.Models.Structures; | ||
using GraphManipulation.Ontologies; | ||
using VDS.RDF; | ||
|
||
namespace GraphManipulation.Extensions; | ||
|
||
public static class DataStoreFromGraph | ||
{ | ||
public static T? ConstructDataStore<T>(this IGraph graph) where T : DataStore | ||
{ | ||
return graph | ||
.GetTriplesWithObject(graph.CreateUriNode(GraphDataType.GetGraphTypeString(typeof(T)))) | ||
.Select(triple => | ||
{ | ||
var name = graph.GetNameOfNode(triple.Subject); | ||
// TODO: Det her er åbenbart langsomt, men jeg kunne ikke finde andre måder der virkede | ||
return (T)Activator.CreateInstance(typeof(T), name, graph.BaseUri.ToString())!; | ||
}) | ||
.Select(datastore => | ||
{ | ||
if (datastore is Relational relational) | ||
{ | ||
graph.ConstructRelational(relational); | ||
} | ||
return datastore; | ||
}) | ||
.FirstOrDefault(); | ||
} | ||
|
||
private static void ConstructRelational(this IGraph graph, Relational relational) | ||
{ | ||
graph.ConstructSchemas(relational); | ||
graph.ConstructForeignKeys(relational); | ||
} | ||
|
||
private static void ConstructSchemas(this IGraph graph, Relational relational) | ||
{ | ||
foreach (var schema in graph.GetSubStructures<Schema>(relational)) | ||
{ | ||
relational.AddStructure(schema); | ||
graph.ConstructTables(schema); | ||
} | ||
} | ||
|
||
private static void ConstructTables(this IGraph graph, Schema schema) | ||
{ | ||
foreach (var table in graph.GetSubStructures<Table>(schema)) | ||
{ | ||
schema.AddStructure(table); | ||
graph.ConstructColumns(table); | ||
graph.ConstructPrimaryKeys(table); | ||
} | ||
} | ||
|
||
private static void ConstructPrimaryKeys(this IGraph graph, Table table) | ||
{ | ||
foreach (var columnNode in graph | ||
.GetTriplesWithSubjectPredicate( | ||
graph.CreateUriNode(table.Uri), | ||
graph.CreateUriNode(DataStoreDescriptionLanguage.PrimaryKey)) | ||
.Select(triple => (triple.Object as UriNode)!)) | ||
{ | ||
var matchingColumn = table.SubStructures.First(sub => sub.Uri == columnNode.Uri) as Column; | ||
table.AddPrimaryKey(matchingColumn!); | ||
} | ||
} | ||
|
||
private static void ConstructForeignKeys(this IGraph graph, Relational relational) | ||
{ | ||
var triples = graph | ||
.GetTriplesWithPredicate(graph.CreateUriNode(DataStoreDescriptionLanguage.References)) | ||
.Where(triple => | ||
{ | ||
var subjStore = graph.GetTripleWithSubjectPredicateObject( | ||
triple.Subject, | ||
graph.CreateUriNode(DataStoreDescriptionLanguage.HasStore), | ||
graph.CreateUriNode(relational.Uri)); | ||
var objStore = graph.GetTripleWithSubjectPredicateObject( | ||
triple.Object, | ||
graph.CreateUriNode(DataStoreDescriptionLanguage.HasStore), | ||
graph.CreateUriNode(relational.Uri)); | ||
return subjStore is not null && objStore is not null; | ||
}); | ||
|
||
foreach (var triple in triples) | ||
{ | ||
var subj = (triple.Subject as UriNode)!; | ||
var obj = (triple.Object as UriNode)!; | ||
|
||
var from = relational.Find<Column>(subj.Uri)!; | ||
var to = relational.Find<Column>(obj.Uri)!; | ||
|
||
(from.ParentStructure as Table)!.AddForeignKey(from, to); | ||
} | ||
} | ||
|
||
private static void ConstructColumns(this IGraph graph, Table table) | ||
{ | ||
foreach (var column in graph.GetSubStructures<Column>(table)) | ||
{ | ||
table.AddStructure(column); | ||
column.SetDataType(graph.GetColumnDataType(column)); | ||
column.SetIsNotNull(graph.GetColumnIsNotNull(column)); | ||
column.SetOptions(graph.GetColumnOptions(column)); | ||
} | ||
} | ||
} |
Oops, something went wrong.