-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added first template project and package (#117)
- Loading branch information
1 parent
1a4616f
commit b11cc28
Showing
11 changed files
with
218 additions
and
2 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
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 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,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. |
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 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 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 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,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> |
12 changes: 12 additions & 0 deletions
12
src/net/templates/templates/kefcoreApp/.template.config/template.json
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,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" | ||
} | ||
} |
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,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
14
src/net/templates/templates/kefcoreApp/knetConnectSink.csproj
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,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> |
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