Category: books

RSCG–Template Rendering- part 17

 

name Transplator
nuget https://www.nuget.org/packages/Transplator/
link https://github.com/atifaziz/Transplator/
author Atif Aziz

The Transplator is a small fast rendering engine to allow you to make rendering from any class instance.   The code that you start with is


    {%

    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using Rendering;

    

    static partial class EmployeeRendering

    {

        public static string Render(params Employee[] employees)

        {

            var sb = new StringBuilder();

            int i= 0;

    -%}

    Number Employees: {% employees?.Length %}

        {%~ foreach (var emp in employees) { 

        i++;

        ~%}

        {% i %}. {% emp.Name %}  it is in {% emp.Department?.Name %}

        {%~ } ~%}

    {%

            return sb.ToString();

    

            void WriteText(string value) => sb.Append(value);

            void WriteValue(object value) => sb.Append(value);

        }

    }

    ~%}


The code that you will use is



    var IT = new Department();

    IT.Name = "IT";

    var e = new Employee();

    e.ID = 10;

    e.Name = "Andrei Ignat";

    e.Department = IT;

    var render = EmployeeRendering.Render(e);

    Console.WriteLine(render);

The code that is generated is


    using System.Collections.Generic;

    using System.Linq;

    using System.Text;

    using Rendering;

    

    static partial class EmployeeRendering

    {

        public static string Render(params Employee[] employees)

        {

            var sb = new StringBuilder();

            int i= 0;

    WriteText(@"Number Employees: ");

    WriteValue(employees?.Length);

    WriteText(@"

    ");

    foreach (var emp in employees) { 

        i++;

       WriteText(@"    ");

    WriteValue(i);

    WriteText(@". ");

    WriteValue(emp.Name);

    WriteText(@"  it is in ");

    WriteValue(emp.Department?.Name);

    WriteText(@"

    ");

    }

            return sb.ToString();

    

            void WriteText(string value) => sb.Append(value);

            void WriteValue(object value) => sb.Append(value);

        }

    }

Example Code: https://github.com/ignatandrei/RSCG_Examples/tree/main/TemplateRender

All RSCG

NrBlog Post
1RSCG–part 1
2RSCG- AppVersion–part 2
3http://msprogrammer.serviciipeweb.ro/2021/02/17/rsgc-enum-part-3/
4RSGC-JSON to Class- part 4
5RSGC-Constructor – Deconstructor – part 5
6RSGC – DTO Mapper – part 6
7RSGC – Skinny Controllers- part 7
8RSGC-Builder Design Pattern – part 8
9RSGC- MetadataFromObject – part 9
10RSGC- Dynamic Mock – part 10
11RSCG- Method Decorator – part 11
12RSCG – Curry – Partial function – part 12
13RSCG- part 13 – IFormattable
14RSCG- part 14 – DP_Decorator
15RSCG- part 15 – Expression Generator
16RSCG- part 16 – Many Others
17RSCG- the book
18RSCG–Template Rendering- part 17
19CI Version
20HttpClientGenerator
21Query from database
22AutoRegister
23TinyTypes
24Static2Interface
25AppSettings
26Properties
27
Roslyn Source Code Generators

Automate the generation of the e-book

What I have found important in composing the e-book with examples was automating the work of generating the e-book. I have had a json file ( 10 years ago I have used xml ) and some specific folders with the chapters content. I have had also a template for each example chapter – that was ensuring all chapters look the same.

As an example , you can look  at https://github.com/ignatandrei/RSCG_Examples/tree/main/ApplicationVersion  and at  https://github.com/ignatandrei/RSCG_Examples/tree/main/CopyConstructor

This is generated automatically with

var m = new MultiGenerator(folder);
             await m.GeneratePost();
             await m.GenerateReadMeForEach();
             await m.GenerateFrontReadMe();
             await m.GenerateForImages(Path.Combine(folder, “docs”, “images”));
             await m.GenerateForEmail();
         }

Also, pandoc ( see previous post ) it will generate the book from markdown.

Code as picture and PowerAutomateDesktop

I want to make an e-book from RCSG . For this I need to put the code into the book in a nice form. However , the Word document and the PDF and the HTML all have the ideas of formatting the code. How one can accommodate various formats ? Short answer: picture. What if I take a screenshot of the code , as it is formatted in VS / VS Code ? 

But how ? One idea is to open VS and take screenshot  = but it is too resource intensive.

Other idea is internet- I found 2 sites: https://ray.so/  and https://carbon.now.sh/  . What if I use those sites  ?

The obvious solution is Selenium . The other is iMacros . I was thinking to another solution – Power Automate Desktop . Even in preview, it can record the browser actions ( open, goto url, click buttons) and even execute javascript :

function ExecuteScript() {
document.getElementsByClassName(‘jsx-2004545632 ‘)[0].click();
document.getElementById(‘export-clipboard’).focus();
document.getElementById(‘export-clipboard’).click();

  }

 

So I have made a flow to execute https://carbon.now.sh/   and another to save the image in paint ( and crop )

You can find the end result here : https://ignatandrei.github.io/RSCG_Examples/#rscg-number-1—thisassembly

Making a book from (examples) markdown

I want to make a book from my RSCG examples  https://github.com/ignatandrei/RSCG_Examples . The easy way is to transform the .md files into separate chapters.

I have tried initially node with  markdown-pdf and  pdf-merger-js , but I have been going then full speed with pandoc . To generate both Word and Index.md I have used this:

pandoc.exe -d pandocHTML.yaml -o ../docs/index.md -t gfm

pandoc.exe -d pandocHTML.yaml -o ../docs/index.docx

The pandocHTML.yaml is here:

from: gfm

# reader: may be used instead of from:

# to: docx

# output-file:  index.docx

# to: gfm

# output-file:  ../docs/index.md

# writer: may be used instead of to:

# leave blank for output to stdout:

reference-doc: customWord.docx

# leave blank for input from stdin, use [] for no input:

input-files:

– ../book/about.md

– ../book/whatIs.md

– ../ApplicationVersion/README.md

– ../Enum/README.md

– ../JsonToClass/README.md

– ../CopyConstructor/README.md

– ../DTOMapper/readme.md

– ../SkinnyControllers/README.md

– ../DP_Builder/readme.md

– ../MetadataFromObject/README.md

– ../DynamicMocking/readme.md

– ../MethodDecorator/README.md

– ../PartiallyFunction/readme.md

– ../IFormattable/readme.md

– ../DP_Decorator/README.md

– ../PropertyExpressionGenerator/readme.md

– ../book/others.md

– ../book/conclusion.md

# or you may use input-file: with a single value

# defaults:

# – customWord.docx

standalone: true

self-contained: true

# metadata values specified here are parsed as literal

# string text, not markdown:

metadata:

title: RSCG Examples

author:

  – Andrei Ignat

# Note that these take files, not their contents:

include-before-body: []

include-after-body: []

include-in-header: []

resource-path: [“.”]

# ERROR, WARNING, or INFO

verbosity: INFO

log-file: log.json

table-of-contents: true

toc-depth: 3

# number-sections: true

# a list of offsets at each heading level

number-offset: [0,0,0,0,0,0]

# toc: may also be used instead of table-of-contents:

shift-heading-level-by: 1

section-divs: true

identifier-prefix: foo

title-prefix: “”

strip-empty-paragraphs: true

# lf, crlf, or native

eol: lf

strip-comments: false

indented-code-classes: []

ascii: true

default-image-extension: “.jpg”

fail-if-warnings: false

dump-args: false

ignore-args: false

trace: false

As you see , I have put the .md files to be processed. Another thing that I have the need is to have a custom word template – to put page breaks after Heading 2. You can download from https://github.com/ignatandrei/RSCG_Examples/blob/main/print/customWord.docx

RSCG- AppVersion–part 2

 

 

name ThisAssembly
nuget https://www.nuget.org/packages/ThisAssembly
link https://www.clarius.org/ThisAssembly/
author Daniel Cazzulino

The ThisAssembly.Info allows you access to the Assembly Information as constants, instead of going to reflection each time. I found useful to see the assembly version right away in any project that I have.

 

The code that you start with is in .csproj

<PropertyGroup>
<Version>2021.2.15.800</Version>
</PropertyGroup>

The code that you will use is

var strVersion = ThisAssembly.Info.Version;
Console.WriteLine(strVersion);

 

The code that is generated is

/// <summary>
/// Provides access to the current assembly information as pure constants, 
///  without requiring reflection.
/// </summary>
partial class ThisAssembly
{
    /// <summary>
    /// Gets the AssemblyInfo attributes.
    /// </summary>
    [GeneratedCode("ThisAssembly.AssemblyInfo", "1.0.0")]
    [CompilerGenerated]
    public static partial class Info
    {
        public const string Company = @"RSCG_Version";

        public const string Configuration = @"Debug";

        public const string FileVersion = @"2021.2.15.800";

        public const string InformationalVersion = @"2021.2.15.800";

        public const string Product = @"RSCG_Version";

        public const string Title = @"RSCG_Version";

        public const string Version = @"2021.2.15.800";

    }
}

Example Code: https://github.com/ignatandrei/RSCG_Examples/tree/main/ApplicationVersion

All RSCG

NrBlog Post
1RSCG–part 1
2RSCG- AppVersion–part 2
3http://msprogrammer.serviciipeweb.ro/2021/02/17/rsgc-enum-part-3/
4RSGC-JSON to Class- part 4
5RSGC-Constructor – Deconstructor – part 5
6RSGC – DTO Mapper – part 6
7RSGC – Skinny Controllers- part 7
8RSGC-Builder Design Pattern – part 8
9RSGC- MetadataFromObject – part 9
10RSGC- Dynamic Mock – part 10
11RSCG- Method Decorator – part 11
12RSCG – Curry – Partial function – part 12
13RSCG- part 13 – IFormattable
14RSCG- part 14 – DP_Decorator
15RSCG- part 15 – Expression Generator
16RSCG- part 16 – Many Others
17RSCG- the book
18RSCG–Template Rendering- part 17
19CI Version
20HttpClientGenerator
21Query from database
22AutoRegister
23TinyTypes
24Static2Interface
25AppSettings
26Properties
27
Roslyn Source Code Generators

Console2SAAS- post mortem

It was interesting to wrote the mini e-book Console2SAAS with Daniel Tila. We have meet , at non-COVID time , at coffee shops and  hubs and discussing about what each chapter should contain, why, and how to make more easy to read. In COVID times we met over Skype – it was slightly more difficult than meet in person. We have used also a Google Docs in order to wrote together  / finish our ideas

The initial commit was done at 19 March 2019  – so, basic, it took us a year and a half to get  things done ( Ok, I am exaggerating – we did not work full time)

In retrospective, it was fun doing  – but also difficult to clean the ideas and discussing about what it should contain.

Blog posts about this topic

Console2SAAS

A mini-e-book about how to transform a Console to a SAAS application
Download the book for free from https://ignatandrei.github.io/console_to_saas/consoleToSaas.pdf.html
Buy the book from Amazon , if you want to support me : https://www.amazon.com/dp/B08N56SD4D
NoBlog 
1Introduction
2Technical Details
3Console2SAAS-Chapter1
4Console2SAAS-Chapter2
5Console2SAAS-Chapter3
6Console2SAAS-Chapter4
7Console2SAAS-Chapter5
8Console2SAAS-Chapter6
9Console2SAAS-Chapter7
10Console2SAAS-PM

Console2SAAS – what I learned from seventh chapter

The 7th chapter of the Console2SAAS mini-e-book was the most interesting. The Web is a totally different beast from the Desktop application.

  1. The amount of work transforming a single user app to a web app ( not necessary a SAAS app) is not trivial.
  2. That is also a non trivial amount of work of thinking about how to get everything that was for granted ( e.g. folders) into the web.
  3. For load scenario, the architecture of the application should be re-think

You can read the 7th chapter at https://github.com/ignatandrei/console_to_saas/tree/master/Chapter07

Blog posts about this topic

Console2SAAS

A mini-e-book about how to transform a Console to a SAAS application
Download the book for free from https://ignatandrei.github.io/console_to_saas/consoleToSaas.pdf.html
Buy the book from Amazon , if you want to support me : https://www.amazon.com/dp/B08N56SD4D
NoBlog 
1Introduction
2Technical Details
3Console2SAAS-Chapter1
4Console2SAAS-Chapter2
5Console2SAAS-Chapter3
6Console2SAAS-Chapter4
7Console2SAAS-Chapter5
8Console2SAAS-Chapter6
9Console2SAAS-Chapter7
10Console2SAAS-PM

Console2SAAS – what I learned from sixth chapter

The 6th chapter of the mini e-book Console2SAAS it was about  demonstrating to  the reader the problems that has when having multiple clients using the Desktop application- and how to solve it.

That shows to me that an architect is needed to proper engineer and maybe refactor the solution – if it grows beyond expectations. And here there are multiple solutions to do this – depending on the  specific case that you have.

You can read the 6th chapter at https://github.com/ignatandrei/console_to_saas/tree/master/Chapter06

Blog posts about this topic

Console2SAAS

A mini-e-book about how to transform a Console to a SAAS application
Download the book for free from https://ignatandrei.github.io/console_to_saas/consoleToSaas.pdf.html
Buy the book from Amazon , if you want to support me : https://www.amazon.com/dp/B08N56SD4D
NoBlog 
1Introduction
2Technical Details
3Console2SAAS-Chapter1
4Console2SAAS-Chapter2
5Console2SAAS-Chapter3
6Console2SAAS-Chapter4
7Console2SAAS-Chapter5
8Console2SAAS-Chapter6
9Console2SAAS-Chapter7
10Console2SAAS-PM

Console2SAAS – what I learned from fifth chapter

In the chapter 5 of Console2SAAS I wanted to show the user the challenges of having a client . Any new client will come with some different use case scenario , even for the smallest assumption in the original project. And here the power of DI can be shown. I have had zero  problems trying to get a real life scenario from such a small example – parsing folder with multiple Word documents. The Zip file is the easy equivalent of a folder . That shows that even the small application, if released into the wild and used by someone, can have multiple changes.

You can find chapter 5 at https://github.com/ignatandrei/console_to_saas/tree/master/Chapter05

Blog posts about this topic

Console2SAAS

A mini-e-book about how to transform a Console to a SAAS application
Download the book for free from https://ignatandrei.github.io/console_to_saas/consoleToSaas.pdf.html
Buy the book from Amazon , if you want to support me : https://www.amazon.com/dp/B08N56SD4D
NoBlog 
1Introduction
2Technical Details
3Console2SAAS-Chapter1
4Console2SAAS-Chapter2
5Console2SAAS-Chapter3
6Console2SAAS-Chapter4
7Console2SAAS-Chapter5
8Console2SAAS-Chapter6
9Console2SAAS-Chapter7
10Console2SAAS-PM

Andrei Ignat weekly software news(mostly .NET)

* indicates required

Please select all the ways you would like to hear from me:

You can unsubscribe at any time by clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp's privacy practices here.