Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic example to serialize model & twin #5

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions DigitalTwins-CodeFirst-dotnet.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Tests", "Tests", "{D8068994
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Telstra.Twins.Test", "Tests\Telstra.Twins.Test\Telstra.Twins.Test.csproj", "{4E5BF74D-C0EF-4D13-872C-F40FC347AD67}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Examples", "Examples", "{5BA14B5E-B883-4B92-802D-0BA49C93842B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SimpleExample", "Examples\SimpleExample\SimpleExample.csproj", "{BAB10325-0CE2-4528-A2FE-C65F74982D28}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{2249F79B-DD17-4FAF-91B7-3E69A5E9546C}"
ProjectSection(SolutionItems) = preProject
README.md = README.md
Expand Down Expand Up @@ -67,8 +71,21 @@ Global
{4E5BF74D-C0EF-4D13-872C-F40FC347AD67}.Release|x64.Build.0 = Release|Any CPU
{4E5BF74D-C0EF-4D13-872C-F40FC347AD67}.Release|x86.ActiveCfg = Release|Any CPU
{4E5BF74D-C0EF-4D13-872C-F40FC347AD67}.Release|x86.Build.0 = Release|Any CPU
{BAB10325-0CE2-4528-A2FE-C65F74982D28}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BAB10325-0CE2-4528-A2FE-C65F74982D28}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BAB10325-0CE2-4528-A2FE-C65F74982D28}.Debug|x64.ActiveCfg = Debug|Any CPU
{BAB10325-0CE2-4528-A2FE-C65F74982D28}.Debug|x64.Build.0 = Debug|Any CPU
{BAB10325-0CE2-4528-A2FE-C65F74982D28}.Debug|x86.ActiveCfg = Debug|Any CPU
{BAB10325-0CE2-4528-A2FE-C65F74982D28}.Debug|x86.Build.0 = Debug|Any CPU
{BAB10325-0CE2-4528-A2FE-C65F74982D28}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BAB10325-0CE2-4528-A2FE-C65F74982D28}.Release|Any CPU.Build.0 = Release|Any CPU
{BAB10325-0CE2-4528-A2FE-C65F74982D28}.Release|x64.ActiveCfg = Release|Any CPU
{BAB10325-0CE2-4528-A2FE-C65F74982D28}.Release|x64.Build.0 = Release|Any CPU
{BAB10325-0CE2-4528-A2FE-C65F74982D28}.Release|x86.ActiveCfg = Release|Any CPU
{BAB10325-0CE2-4528-A2FE-C65F74982D28}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{4E5BF74D-C0EF-4D13-872C-F40FC347AD67} = {D8068994-FDA6-41F1-9196-59AADA892F11}
{BAB10325-0CE2-4528-A2FE-C65F74982D28} = {5BA14B5E-B883-4B92-802D-0BA49C93842B}
EndGlobalSection
EndGlobal
20 changes: 20 additions & 0 deletions Examples/SimpleExample/Models/Factory.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System.Collections.Generic;
using Telstra.Twins.Attributes;

namespace SimpleExample.Models
{
[DigitalTwin(Version = 1, DisplayName = "Digital Factory - Interface Model")]
public class Factory
{
[TwinProperty] public string? Country { get; set; }

[TwinProperty] public string? FactoryId { get; set; }

[TwinProperty] public string? FactoryName { get; set; }

[TwinRelationship(DisplayName = "Has Floors")]
public List<FactoryFloor> Floors { get; set; } = new List<FactoryFloor>();

[TwinProperty] public string? ZipCode { get; set; }
}
}
12 changes: 12 additions & 0 deletions Examples/SimpleExample/Models/FactoryFloor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using Telstra.Twins.Attributes;

namespace SimpleExample.Models
{
[DigitalTwin(Version = 1, DisplayName = "Digital Factory - Interface Model")]
public class FactoryFloor
{
[TwinProperty] public string? FloorId { get; set; }

[TwinProperty] public string? FloorName { get; set; }
}
}
49 changes: 49 additions & 0 deletions Examples/SimpleExample/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using System;
using SimpleExample.Models;
using Telstra.Twins.Core;
using Telstra.Twins.Services;

namespace SimpleExample
{
internal static class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Simple Digital Twin Serializer Example");

var modelLibrary = new ModelLibrary();
var serializer = new DigitalTwinSerializer(modelLibrary);

Console.WriteLine("Models:");
Console.WriteLine();

var model1Dtdl = serializer.SerializeModel<Factory>();
Console.WriteLine(model1Dtdl);
Console.WriteLine();

var model2Dtdl = serializer.SerializeModel<FactoryFloor>();
Console.WriteLine(model2Dtdl);
Console.WriteLine();

Console.WriteLine("Twins:");
Console.WriteLine();

var factory = new Factory
{
FactoryId = "factory1",
Country = "AU",
ZipCode = "4000",
FactoryName = "Chocolate Factory"
};
factory.Floors.Add(new FactoryFloor { FloorId = "floor1", FloorName = "Floor 1" });

var twin1Dtdl = serializer.SerializeTwin(factory);
Console.WriteLine(twin1Dtdl);
Console.WriteLine();

var twin2Dtdl = serializer.SerializeTwin(factory.Floors[0]);
Console.WriteLine(twin2Dtdl);
Console.WriteLine();
}
}
}
13 changes: 13 additions & 0 deletions Examples/SimpleExample/SimpleExample.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\Telstra.Twins\Telstra.Twins.csproj" />
</ItemGroup>

</Project>