From b11cc28bdc1e2b31078ca3a717d646173c4e6d20 Mon Sep 17 00:00:00 2001 From: MASES Public Developers Team <94312179+masesdevelopers@users.noreply.github.com> Date: Fri, 20 Oct 2023 01:40:45 +0200 Subject: [PATCH] Added first template project and package (#117) --- README.md | 1 + src/documentation/articles/toc.yml | 4 +- src/documentation/articles/usageTemplates.md | 26 ++++ src/documentation/index.md | 1 + src/net/Common/Common.props | 2 +- src/net/KEFCore.sln | 6 + src/net/templates/templatepack.csproj | 28 +++++ .../kefcoreApp/.template.config/template.json | 12 ++ .../templates/templates/kefcoreApp/Program.cs | 117 ++++++++++++++++++ .../kefcoreApp/knetConnectSink.csproj | 14 +++ test/KEFCore.Test.sln | 9 ++ 11 files changed, 218 insertions(+), 2 deletions(-) create mode 100644 src/documentation/articles/usageTemplates.md create mode 100644 src/net/templates/templatepack.csproj create mode 100644 src/net/templates/templates/kefcoreApp/.template.config/template.json create mode 100644 src/net/templates/templates/kefcoreApp/Program.cs create mode 100644 src/net/templates/templates/kefcoreApp/knetConnectSink.csproj diff --git a/README.md b/README.md index 50e76c03..5738adf4 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ This project adheres to the Contributor [Covenant code of conduct](CODE_OF_CONDU * [Usage](src/documentation/articles/usage.md) * [Use cases](src/documentation/articles/usecases.md) * [Serialization](src/documentation/articles/serialization.md) +* [Templates usage](src/documentation/articles/usageTemplates.md) * [External application](src/documentation/articles/externalapplication.md) * [Roadmap](src/documentation/articles/roadmap.md) * [Current state](src/documentation/articles/currentstate.md) diff --git a/src/documentation/articles/toc.yml b/src/documentation/articles/toc.yml index f0a89c83..88eb5c34 100644 --- a/src/documentation/articles/toc.yml +++ b/src/documentation/articles/toc.yml @@ -15,4 +15,6 @@ - name: Current state href: currentstate.md - name: KafkaDbContext - href: kafkadbcontext.md \ No newline at end of file + href: kafkadbcontext.md +- name: Template usage + href: usageTemplates.md \ No newline at end of file diff --git a/src/documentation/articles/usageTemplates.md b/src/documentation/articles/usageTemplates.md new file mode 100644 index 00000000..688d0557 --- /dev/null +++ b/src/documentation/articles/usageTemplates.md @@ -0,0 +1,26 @@ +# KEFCore: Template Usage Guide + +For more information related to .NET templates look at https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-new-sdk-templates. + +## Installation + +To install the templates executes the following command within a command shell: + +> +> dotnet new --install MASES.EntityFrameworkCore.KNet.Templates +> + +The command installs the latest version and on success will list all templates added to the list of available templates. +There is single template: +1. kefcoreApp: a project to create a console application using Entity Framework Core provider for Apache Kafka + +## Simple usage + +To use one of the available templates run the following command: + +> +> dotnet new kefcoreApp +> + +the previous command will create a .NET project for an executable. The user shall modify the code to set-up, at least the Apache Kafka broker address, and then execute it against an Apache Kafka server. +The template create the topics and fill them, then execute queries on previously data loaded. \ No newline at end of file diff --git a/src/documentation/index.md b/src/documentation/index.md index 12a37323..e9c33f9b 100644 --- a/src/documentation/index.md +++ b/src/documentation/index.md @@ -45,6 +45,7 @@ This project adheres to the Contributor [Covenant code of conduct](CODE_OF_CONDU * [Usage](articles/usage.md) * [Use cases](articles/usecases.md) * [Serialization](articles/serialization.md) +* [Templates usage](articles/usageTemplates.md) * [External application](articles/externalapplication.md) * [Roadmap](articles/roadmap.md) * [Current state](articles/currentstate.md) diff --git a/src/net/Common/Common.props b/src/net/Common/Common.props index 1a59d6e0..cd2325be 100644 --- a/src/net/Common/Common.props +++ b/src/net/Common/Common.props @@ -4,7 +4,7 @@ MASES s.r.l. MASES s.r.l. MASES s.r.l. - 0.10.0.0 + 0.10.1.0 net6.0;net7.0 latest true diff --git a/src/net/KEFCore.sln b/src/net/KEFCore.sln index 16fc8977..5f170aed 100644 --- a/src/net/KEFCore.sln +++ b/src/net/KEFCore.sln @@ -11,6 +11,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KEFCore.SerDes.Avro", "KEFC EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KEFCore.SerDes.Avro.Compiler", "KEFCore.SerDes.Avro.Compiler\KEFCore.SerDes.Avro.Compiler.csproj", "{1E2A2989-7F4C-4651-907F-BCED5E8FA717}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "templatepack", "templates\templatepack.csproj", "{F5A4D889-A4EA-4050-8F04-550E0FFC82FD}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -33,6 +35,10 @@ Global {1E2A2989-7F4C-4651-907F-BCED5E8FA717}.Debug|Any CPU.Build.0 = Debug|Any CPU {1E2A2989-7F4C-4651-907F-BCED5E8FA717}.Release|Any CPU.ActiveCfg = Release|Any CPU {1E2A2989-7F4C-4651-907F-BCED5E8FA717}.Release|Any CPU.Build.0 = Release|Any CPU + {F5A4D889-A4EA-4050-8F04-550E0FFC82FD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {F5A4D889-A4EA-4050-8F04-550E0FFC82FD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {F5A4D889-A4EA-4050-8F04-550E0FFC82FD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {F5A4D889-A4EA-4050-8F04-550E0FFC82FD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/net/templates/templatepack.csproj b/src/net/templates/templatepack.csproj new file mode 100644 index 00000000..50c3de7f --- /dev/null +++ b/src/net/templates/templatepack.csproj @@ -0,0 +1,28 @@ + + + + ..\..\..\bin\ + Template + MASES.EntityFrameworkCore.KNet.Templates + EntityFrameworkCore KNet Templates - Templates to use with KNet + Ready made templates to create applications based on Entity Framework Core provider for Apache Kafka + Ready made templates to create applications based on Entity Framework Core provider for Apache Kafka. The templates are ready made starting points, all information and APIs are available in the official website https://masesgroup.github.io/KEFCore + knet kafka apache-kafka dotnet clr netcore net6 template kafka connect streams producer consumer providers streamprovider confluent + MASES.EntityFrameworkCore.KNet Templates + false + false + true + content + usageTemplates.md + False + False + + + + + + + + + + diff --git a/src/net/templates/templates/kefcoreApp/.template.config/template.json b/src/net/templates/templates/kefcoreApp/.template.config/template.json new file mode 100644 index 00000000..f17cdafa --- /dev/null +++ b/src/net/templates/templates/kefcoreApp/.template.config/template.json @@ -0,0 +1,12 @@ +{ + "$schema": "http://json.schemastore.org/template", + "author": "MASES s.r.l.", + "classifications": [ "Common", "Library" ], + "identity": "MASES.EntityFrameworkCore.KNet.Templates", + "name": "Executable template: Simple Console for EntityFrameworkCore provider for Apache Kafka project", + "shortName": "kefcoreApp", + "tags": { + "language": "C#", + "type": "project" + } +} \ No newline at end of file diff --git a/src/net/templates/templates/kefcoreApp/Program.cs b/src/net/templates/templates/kefcoreApp/Program.cs new file mode 100644 index 00000000..c147c51a --- /dev/null +++ b/src/net/templates/templates/kefcoreApp/Program.cs @@ -0,0 +1,117 @@ +using MASES.EntityFrameworkCore.KNet.Infrastructure; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; + +namespace MASES.EntityFrameworkCore.KNet.Templates +{ + partial class Program + { + static void Main(string[] args) + { + BloggingContext context = null; + try + { + context = new BloggingContext() + { + BootstrapServers = "KAFKA-BROKER:9092", + ApplicationId = "MyApplicationId", + DbName = "MyDB", + }; + // cleanup topics on Broker + context.Database.EnsureDeleted(); + context.Database.EnsureCreated(); + + // prefill data + for (int i = 0; i < 1000; i++) + { + context.Add(new Blog + { + Url = "http://blogs.msdn.com/adonet" + i.ToString(), + Posts = new List() + { + new Post() + { + Title = "title", + Content = i.ToString() + } + }, + Rating = i, + }); + } + // save data + context.SaveChanges(); + + // make some queries + var selector = (from op in context.Blogs + join pg in context.Posts on op.BlogId equals pg.BlogId + where pg.BlogId == op.BlogId + select new { pg, op }); + var pageObject = selector.FirstOrDefault(); + + var post = context.Posts.Single(b => b.BlogId == 2); + + post = context.Posts.Single(b => b.BlogId == 1); + + var all = context.Posts.All((o) => true); + + var value = context.Blogs.AsQueryable().ToQueryString(); + } + catch (Exception ex) + { + Console.WriteLine(ex.ToString()); + } + finally + { + context?.Dispose(); + } + } + } + + public class BloggingContext : KafkaDbContext + { + // uncomment for persistent storage + // public override bool UsePersistentStorage { get; set; } = true; + + // uncomment to disable compacted replicator + //public override bool UseCompactedReplicator { get; set; } = false; + + public DbSet Blogs { get; set; } + public DbSet Posts { get; set; } + + /// uncomment for model builder + //protected override void OnModelCreating(ModelBuilder modelBuilder) + //{ + // modelBuilder.Entity().HasKey(c => new { c.BlogId, c.Rating }); + //} + } + + public class Blog + { + public int BlogId { get; set; } + public string Url { get; set; } + public int Rating { get; set; } + public List Posts { get; set; } + + public override string ToString() + { + return $"BlogId: {BlogId} Url: {Url} Rating: {Rating}"; + } + } + + public class Post + { + public int PostId { get; set; } + public string Title { get; set; } + public string Content { get; set; } + + public int BlogId { get; set; } + public Blog Blog { get; set; } + + public override string ToString() + { + return $"PostId: {PostId} Title: {Title} Content: {Content} BlogId: {BlogId}"; + } + } +} diff --git a/src/net/templates/templates/kefcoreApp/knetConnectSink.csproj b/src/net/templates/templates/kefcoreApp/knetConnectSink.csproj new file mode 100644 index 00000000..edcfce30 --- /dev/null +++ b/src/net/templates/templates/kefcoreApp/knetConnectSink.csproj @@ -0,0 +1,14 @@ + + + latest + net6.0;net7.0 + + + + + + + + + + diff --git a/test/KEFCore.Test.sln b/test/KEFCore.Test.sln index 21aaa0bc..0c8d960b 100644 --- a/test/KEFCore.Test.sln +++ b/test/KEFCore.Test.sln @@ -25,6 +25,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KEFCore.SerDes.Avro.Compile EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "KEFCore.Extractor.Test", "KEFCore.Extractor.Test\KEFCore.Extractor.Test.csproj", "{E1BE56EB-4701-47E7-876A-D2146619C211}" EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Templates", "Templates", "{68A75218-B566-4DF6-8BFF-586B7C3E7ED6}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "knetConnectSink", "..\src\net\templates\templates\kefcoreApp\knetConnectSink.csproj", "{FBB94BFE-4492-4366-914F-410C82F6AEB7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -67,6 +71,10 @@ Global {E1BE56EB-4701-47E7-876A-D2146619C211}.Debug|Any CPU.Build.0 = Debug|Any CPU {E1BE56EB-4701-47E7-876A-D2146619C211}.Release|Any CPU.ActiveCfg = Release|Any CPU {E1BE56EB-4701-47E7-876A-D2146619C211}.Release|Any CPU.Build.0 = Release|Any CPU + {FBB94BFE-4492-4366-914F-410C82F6AEB7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FBB94BFE-4492-4366-914F-410C82F6AEB7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FBB94BFE-4492-4366-914F-410C82F6AEB7}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FBB94BFE-4492-4366-914F-410C82F6AEB7}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -81,6 +89,7 @@ Global {40D1001C-EC50-4994-BE40-F410DB20AF4F} = {4A0AD520-9BC4-4F92-893B-6F92BBC35BFA} {BED3DF6D-B60E-486D-96E9-AD069D0600D2} = {B35B16BB-890F-4385-AB20-7AA4DD6E9C01} {E1BE56EB-4701-47E7-876A-D2146619C211} = {4A0AD520-9BC4-4F92-893B-6F92BBC35BFA} + {FBB94BFE-4492-4366-914F-410C82F6AEB7} = {68A75218-B566-4DF6-8BFF-586B7C3E7ED6} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {36C294ED-9ECE-42AA-8273-31E008749AF3}