Skip to content

Commit

Permalink
Added first template project and package (#117)
Browse files Browse the repository at this point in the history
  • Loading branch information
masesdevelopers authored Oct 19, 2023
1 parent 1a4616f commit b11cc28
Show file tree
Hide file tree
Showing 11 changed files with 218 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/documentation/articles/toc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@
- name: Current state
href: currentstate.md
- name: KafkaDbContext
href: kafkadbcontext.md
href: kafkadbcontext.md
- name: Template usage
href: usageTemplates.md
26 changes: 26 additions & 0 deletions src/documentation/articles/usageTemplates.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions src/documentation/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/net/Common/Common.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Owners>MASES s.r.l.</Owners>
<Authors>MASES s.r.l.</Authors>
<Company>MASES s.r.l.</Company>
<Version>0.10.0.0</Version>
<Version>0.10.1.0</Version>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<LangVersion>latest</LangVersion>
<GenerateAssemblyInfo>true</GenerateAssemblyInfo>
Expand Down
6 changes: 6 additions & 0 deletions src/net/KEFCore.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
28 changes: 28 additions & 0 deletions src/net/templates/templatepack.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\Common\Common.props" />
<PropertyGroup>
<OutputPath>..\..\..\bin\</OutputPath>
<PackageType>Template</PackageType>
<PackageId>MASES.EntityFrameworkCore.KNet.Templates</PackageId>
<Title>EntityFrameworkCore KNet Templates - Templates to use with KNet</Title>
<Summary>Ready made templates to create applications based on Entity Framework Core provider for Apache Kafka</Summary>
<Description>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</Description>
<PackageTags>knet kafka apache-kafka dotnet clr netcore net6 template kafka connect streams producer consumer providers streamprovider confluent</PackageTags>
<Product>MASES.EntityFrameworkCore.KNet Templates</Product>
<IncludeSymbols>false</IncludeSymbols>
<IncludeBuildOutput>false</IncludeBuildOutput>
<IncludeContentInPack>true</IncludeContentInPack>
<ContentTargetFolders>content</ContentTargetFolders>
<PackageReadmeFile>usageTemplates.md</PackageReadmeFile>
<RunAnalyzersDuringLiveAnalysis>False</RunAnalyzersDuringLiveAnalysis>
<RunAnalyzersDuringBuild>False</RunAnalyzersDuringBuild>
</PropertyGroup>
<ItemGroup>
<None Include="..\..\documentation\articles\usageTemplates.md" Pack="true" PackagePath="\" />
<Content Include="templates\**\*" Exclude="templates\**\bin\**;templates\**\obj\**;templates\**\.vscode\**" />
<Compile Remove="**\*" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -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"
}
}
117 changes: 117 additions & 0 deletions src/net/templates/templates/kefcoreApp/Program.cs
Original file line number Diff line number Diff line change
@@ -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<Post>()
{
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<Blog> Blogs { get; set; }
public DbSet<Post> Posts { get; set; }

/// uncomment for model builder
//protected override void OnModelCreating(ModelBuilder modelBuilder)
//{
// modelBuilder.Entity<Blog>().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<Post> 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}";
}
}
}
14 changes: 14 additions & 0 deletions src/net/templates/templates/kefcoreApp/knetConnectSink.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<LangVersion>latest</LangVersion>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition="Exists('..\..\..\KEFCore\KEFCore.csproj')">
<!--Within GitHub repo: used for test purpose-->
<ProjectReference Include="..\..\..\KEFCore\KEFCore.csproj" />
</ItemGroup>
<ItemGroup Condition="!Exists('..\..\..\KEFCore\KEFCore.csproj')">
<!--Outside GitHub repo-->
<PackageReference Include="MASES.EntityFrameworkCore.KNet" Version="0.10.1" IncludeAssets="All" PrivateAssets="None" />
</ItemGroup>
</Project>
9 changes: 9 additions & 0 deletions test/KEFCore.Test.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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}
Expand Down

0 comments on commit b11cc28

Please sign in to comment.