Skip to content

Instantly share code, notes, and snippets.

Danny Lai tocalai

Block or report user

Report or block tocalai

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tocalai
tocalai / EventReceiverService.cs
Created Sep 5, 2019
Demonstrate sending message to specific client(s) according group.
View EventReceiverService.cs
using Microsoft.AspNetCore.SignalR;
using Newtonsoft.Json;
using SignalR.Lab.Web.Hubs;
using SignalR.Lab.Web.Models;
using System;
using System.Timers;
namespace SignalR.Lab.Web.Services
{
public class EventReceiverService
@tocalai
tocalai / EventHub.cs
Created Sep 5, 2019
Demonstrate bi-direction communication between server and client.
View EventHub.cs
using Microsoft.AspNetCore.SignalR;
using Microsoft.AspNetCore.SignalR;
namespace SignalR.Lab.Web.Hubs
{
public interface IEventHub
{
// here place some method(s) for message from server to client(s) (broadcast)
Task SendNoticeEventToClient(string message);
@tocalai
tocalai / EventReceiverService.cs
Created Sep 2, 2019
Service for broadcast sending all mock events to client(s)
View EventReceiverService.cs
using Microsoft.AspNetCore.SignalR;
using Newtonsoft.Json;
using SignalR.Lab.Web.Hubs;
using SignalR.Lab.Web.Models;
using System;
using System.Timers;
namespace SignalR.Lab.Web.Services
{
public class EventReceiverService
@tocalai
tocalai / Startup.cs
Last active Sep 2, 2019
DI for SignalR in ASP.NET.Core
View Startup.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.DependencyInjection;
using SignalR.Lab.Web.Hubs;
using SignalR.Lab.Web.Services;
@tocalai
tocalai / EventHub.cs
Created Sep 2, 2019
Demonstrate Hub for signalR
View EventHub.cs
using Microsoft.AspNetCore.SignalR;
using Microsoft.AspNetCore.SignalR;
namespace SignalR.Lab.Web.Hubs
{
public interface IEventHub
{
// here place some method(s) for message from server to client
Task SendNoticeEventToClient(string message);
@tocalai
tocalai / index.html
Last active Sep 5, 2019
SignalR client side demonstration.
View index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>SignalR Lab</title>
<script src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.12.4.min.js"></script>
<script type="text/javascript" src="lib/signalr.min.js"></script>
</head>
<body>
<div>
@tocalai
tocalai / ExcelExport.cs
Created Aug 8, 2019
Demonstrate how to export data to excel file through ClosedXML
View ExcelExport.cs
using ClosedXML.Excel;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
namespace Demo.Excel.Export
{
class Program
@tocalai
tocalai / bogus_demo.cs
Created Aug 8, 2019
Demonstrate how to generate mock/testing data via BOGUS
View bogus_demo.cs
using Newtonsoft.Json;
using System;
using System.Linq;
namespace Bogus.Lab.ConsoleApp
{
class Program
{
static void Main(string[] args)
{
@tocalai
tocalai / Startup.cs
Created Jul 31, 2019
Demo how to use prefix using path base
View Startup.cs
public void Configure (IApplicationBuilder app, IHostingEnvironment env)
{
// [HMR] http://www.c-sharpcorner.com/article/using-hot-module-replacement-feature-of-webpack-in-asp-net-core/
if (env.IsDevelopment ())
{
// ...
}
else
{
@tocalai
tocalai / Startup.cs
Last active Jul 31, 2019
Setup centralize route from Startup.cs
View Startup.cs
public void ConfigureServices (IServiceCollection services)
{
// model that mapping to appsettings.json
services.Configure<ConfigModel> (Configuration);
// ....
services.AddMvc (options =>
{
// assume that we want our api all prefix route with APIBaseInfo.BasePath=DEV_API_V1 for development phrase.
// we also could switch appsettings to Qas/Release that prefix route with different path:
// QAS_API_V1/RELEASE_API_V1
You can’t perform that action at this time.