Skip to content

ChrisMCy/Blazor.Console

 
 

Repository files navigation

Blazor.Console

The goal of this project is to make it easy to move existing console application to blazor web assembly.

Console.Extensions package in get-the-solution feed in Azure Artifacts Blazor.Console package in get-the-solution feed in Azure Artifacts

Sample Demo

using System;

namespace ConsoleApp1
{
    //dont forget to make Program public
    public class Program
    {
        //dont forget to make Main public
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            Logic();
        }

        public static void Logic()
        {
            Console.WriteLine("Please enter something:");

            string v = Console.ReadLine();

            System.Console.WriteLine($"You enterted {v}");

        }
    }
}
  1. Exchange using System; to using console = Console.Extensions.Console;

  2. Replace Console.WriteLine to console.WriteLine

  3. Replace string v = Console.ReadLine(); to string v = await console.ReadLineAsync();

  4. Exchanging this function will still call the orignal methods of System.Console

  5. Create the razor page

  6. Include the console component for example:

<p><button @onclick="OnStartConsoleAppClick">start console app</button></p>

<p><Blazor.Console.BlazorConsole Name="fooTest" @ref="c" /></p>


@code
{
    BlazorConsole c;

    private void OnStartConsoleAppClick(MouseEventArgs mouseEventArgs)
    {
        InvokeAsync(ConsoleTest.StartAsync).ContinueWith(a =>
        {
            if (a.Exception != null)
            {
                _logger.LogError(a.Exception, nameof(OnStartConsoleAppClick));
            }
        });
    }

    protected async override Task OnAfterRenderAsync(bool firstRender)
    {
        await base.OnAfterRenderAsync(firstRender);
    }
}

done.

About

Move your console application to blazor webassembly

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 91.0%
  • HTML 5.1%
  • JavaScript 2.4%
  • CSS 1.5%