Skip to content

Commit

Permalink
icon.png, README.md, README_NUGET.md, LICENSE & build properties
Browse files Browse the repository at this point in the history
  • Loading branch information
carl-andersson-at-westermo committed Jun 11, 2024
1 parent 2cc8b4d commit 5b056d3
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 1 deletion.
24 changes: 24 additions & 0 deletions Directory.Build.Props
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project>
<PropertyGroup>
<EnablePackageValidation>true</EnablePackageValidation>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<PackageReadmeFile>README_NUGET.md</PackageReadmeFile>
<PackageProjectUrl>https://github.com/westermo/DotnetYang</PackageProjectUrl>
<RepositoryUrl>https://github.com/westermo/DotnetYang</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageIcon>icon.png</PackageIcon>
<PackageTags>roslyn, yang, compile-time, network, xml, netconf</PackageTags>
<CurrentYear>$([System.DateTime]::Now.ToString(yyyy))</CurrentYear>
<Company>Westermo Network Technologies AB</Company>
<Copyright>Copyright © Westermo Network Technologies AB $(CurrentYear)</Copyright>
<Authors>Westermo Network Technologies AB</Authors>
<Description>dotnetYang is a source generator for converting .yang files into C# Code</Description>
</PropertyGroup>

<ItemGroup>
<None Include="$(ProjectDir)../README_NUGET.md" Link="README.md" Pack="true" PackagePath="/" Condition="Exists('$(ProjectDir)../README.md')"/>
<None Include="$(ProjectDir)../icon.png" Link="icon.png" Pack="true" PackagePath="/" Condition="Exists('$(ProjectDir)../icon.png')"/>
<None Include="$(ProjectDir)../LICENSE" Link="LICENSE" Pack="true" PackagePath="/" Condition="Exists('$(ProjectDir)../LICENSE')"/>
</ItemGroup>

</Project>
19 changes: 19 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Copyright (c) 2024 Westermo Network Technologies AB

Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
107 changes: 106 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,106 @@
TODO
[![Nuget (Generator)](https://img.shields.io/nuget/v/dotnetYang?style=flat-square)](https://www.nuget.org/packages/dotnetYang/)
[![Build](https://img.shields.io/github/actions/workflow/status/westermo/dotnetYang/build.yml?branch=main&style=flat-square)](https://github.com/westermo/dotnetYang/actions)
[![License](https://img.shields.io/github/license/westermo/dotnetYang?style=flat-square)](https://github.com/westermo/dotnetYang/blob/develop/LICENSE)

dotnetYang is a [Roslyn](https://github.com/dotnet/roslyn) source generator for using the .yang language to generate C# code, providing access to data models, ease-of-use asynchronous RPC, Action & Notification calls directly from code and generated server interfaces.

## Features

- **Drop-and-go:** Add your .yang files to a C# project as additional files that references this generator, that is it, your .yang defined RPC's and more are now available directly in that C# projects code
- **Server-interface:** Want to implement a server that responds to NETCONF calls? Look no further than the generated interface `IYangServer` and it's extension method `async Task Recieve(this IYangServer server, Stream input, Stream output);` which provides a framework for implementing your own server without having to worry about serializing and parsing NETCONF directly, but instead work with well defined C# Datatypes.

## Documentation

### Getting Started

In order to start using `dotnetYang` on a new .csproj project, start by adding the nuget packages by, for example, using the dotnet CLI in your project directory:
`dotnet add package dotnetYang`

Afterwards, create or add a .yang file to said project:
`some-module.yang`
```yang
module some-module {
yang-version 1.1;
namespace "urn:dotnet:yang:some:module";
prefix sm;
identity someIdentity;
identity someOtherIdentity
{
base someIdentity;
}
rpc doSomething {
input {
leaf the-big-leaf
{
type uint32;
default "4";
description "The value that is the input of the doSomething rpc";
}
}
output {
leaf response
{
type identityref
{
base someIdentity;
}
default "someOtherIdentity";
description "The identity that is the output of the doSomething rpc";
}
}
}
}
```
And then add it as an additional file to your .csproj file
```xml
<Project Sdk="Microsoft.NET.Sdk">
<!--Other parts of the .csproj file -->
<ItemGroup>
<AdditionalFiles Include="some-module.yang" />
</ItemGroup>
<!--Other parts of the .csproj file -->
</Project>
```
Now the generated C# code from `some-module.yang` will be available, with it's naming conventions adjusted to be C# compliant
```csharp
namespace MyProject;
public class Program
{
public static async Task Main()
{
IChannel channel = //...Code for setting up whatever channel you want to send the rpc over
int messageID = //...Code for getting message id;
//Set up the rpc input, not the slight name changes
Some.Module.YangNode.DoSomethingInput input = new Some.Module.YangNode.DoSomethingInput
{
TheBigLeaf = 123
};
//Call the rpc function, note the slight name changes and the asynchronous nature of the call
Some.Module.YangNode.DoSomethingOutput output = await Some.Module.YangNode.DoSomething(channel, message, input);
//Write the "response" leaf of the output to console.
Console.WriteLine(output.Response);
}
}
```

### Server creation
Say that you want to create a server that can response to calls defined in `some-module.yang`, then you would create a class that implementes the generated `IYangServer` interface, which might look something like this:

```csharp
using Some.Module;
namespace MyProject;
public class Server : IYangServer
{
public async Task<YangNode.DoSomethingOutput> OnDoSomething(YangNode.DoSomethingInput input)
{
//Do whatever it is the server is expected to do when told to "doSomething"...
//Await something, do something else, the options are endless...
//Create the output, not nessecarily like this..
YangNode.DoSomethingOutput output = new YangNode.DoSomethingOutput();
return output;
}
}
```

Of course, if there are a lot of yang modules in a project, `IYangServer` runs the risk of becoming rather big. In such a case, it is recommended to split it's implementation into several `partial` server classes in order to maintain readability.
7 changes: 7 additions & 0 deletions README_NUGET.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
dotnetYang is a [Roslyn](https://github.com/dotnet/roslyn) source generator for using the .yang language to generate C# code, providing access to data models, ease-of-use asynchronous RPC, Action & Notification calls directly from code and generated server interfaces.

## Features

- **Drop-and-go:** Add your .yang files to a C# project as additional files that references this generator, that is it, your .yang defined RPC's and more are now available directly in that C# projects code
- **Server-interface:** Want to implement a server that responds to NETCONF calls? Look no further than the generated interface `IYangServer` and it's extension method `async Task Recieve(this IYangServer server, Stream input, Stream output);` which provides a framework for implementing your own server without having to worry about serializing and parsing NETCONF directly, but instead work with well defined C# Datatypes.
he risk of becoming rather big. In such a case, it is recommended to split it's implementation into several `partial` server classes in order to maintain readability.
2 changes: 2 additions & 0 deletions YangParser/YangParser.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
<LangVersion>latest</LangVersion>
<Nullable>enable</Nullable>
<EnforceExtendedAnalyzerRules>true</EnforceExtendedAnalyzerRules>
<IncludeBuildOutput>false</IncludeBuildOutput>
<!-- <SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>-->
</PropertyGroup>

<ItemGroup>
Expand Down
Binary file added icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5b056d3

Please sign in to comment.