Skip to content

Commit

Permalink
Merge pull request #1 from P9-P10/dev
Browse files Browse the repository at this point in the history
Proof of Concept Merge
  • Loading branch information
Kaliahh authored Nov 21, 2022
2 parents f586d90 + b13eabf commit 00a77b1
Show file tree
Hide file tree
Showing 65 changed files with 5,774 additions and 251 deletions.
36 changes: 36 additions & 0 deletions .github/workflows/dotnet.yml
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
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,11 @@ bin/
obj/
/packages/
riderModule.iml
/_ReSharper.Caches/
/_ReSharper.Caches/
.idea/

GraphManipulation/temp.ttl

GraphManipulation.sln.DotSettings.user

GraphManipulation/GraphStorage.sqlite
4 changes: 0 additions & 4 deletions .idea/.idea.GraphManipulation/.idea/encodings.xml

This file was deleted.

8 changes: 0 additions & 8 deletions .idea/.idea.GraphManipulation/.idea/indexLayout.xml

This file was deleted.

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/.idea.GraphManipulation/.idea/vcs.xml

This file was deleted.

79 changes: 0 additions & 79 deletions .idea/.idea.GraphManipulation/.idea/workspace.xml

This file was deleted.

6 changes: 6 additions & 0 deletions .run/Publish to linux-x64.run.xml
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>
6 changes: 0 additions & 6 deletions GraphManipulation.sln.DotSettings.user

This file was deleted.

10 changes: 10 additions & 0 deletions GraphManipulation/App.config
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>
69 changes: 69 additions & 0 deletions GraphManipulation/Configuration/ConfigurationHandler.cs
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);
}
}
112 changes: 112 additions & 0 deletions GraphManipulation/Extensions/DataStoreFromGraph.cs
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));
}
}
}
Loading

0 comments on commit 00a77b1

Please sign in to comment.