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 / Program.cs
Created Jul 12, 2019
Grpc client application entry point.
View Program.cs
class Program
{
static void Main(string[] args)
{
// same host and port setting as server side
var host = "127.0.0.1";
var port = 50052;
var channel = new Channel($"{host}:{port}", ChannelCredentials.Insecure);
var client = new AlertService.AlertServiceClient(channel);
@tocalai
tocalai / App.cs
Created Jul 12, 2019
Class for start and initial Grpc service instance
View App.cs
public class App
{
private readonly Grpc.Core.Server _serverInstance;
public App(string host, int port, params ServerServiceDefinition[] services)
{
_serverInstance = new Grpc.Core.Server
{
Ports =
{
@tocalai
tocalai / Program.cs
Created Jul 12, 2019
Grpc service main entry.
View Program.cs
class Program
{
static async Task Main(string[] args)
{
var host = "127.0.0.1";
var port = 50052;
var builder = new HostBuilder()
.ConfigureAppConfiguration((hostingContext, config) =>
{
@tocalai
tocalai / AlertServiceImpl.cs
Created Jul 12, 2019
inherit AlertServiceBase for writing customize logic
View AlertServiceImpl.cs
// inherit AlertServiceBase
public class AlertServiceImpl : AlertService.AlertServiceBase
{
// write customize logic for the method
public override Task<AlertResponse> SendAlert(AlertRequest request, ServerCallContext context)
{
// print out want we recieved from request
Console.WriteLine($"[Alert Request], {request.DateTime}, Uid = {request.Uid}, Message = {request.MsgValue}.");
// do something .... and response
@tocalai
tocalai / service.proto
Last active Jul 11, 2019
IDL for service using Protocol Buffer
View service.proto
syntax = "proto3"; // used version proto3
package Demo.Message; // will be placed in a namespace matching the package name if csharp_namespace is not specified
option csharp_namespace = "Demo.Message";
import "message.proto";
// define alert service
service AlertService {
// method for sending alert
rpc SendAlert(AlertRequest) returns (AlertResponse);
@tocalai
tocalai / message.proto
Last active Jul 11, 2019
IDL for message using Protocol Buffer
View message.proto
syntax = "proto3"; // use version proto3
package Demo.Message; // will be placed in a namespace matching the package name if csharp_namespace is not specified
option csharp_namespace = "Demo.Message";
import "google/protobuf/timestamp.proto"; // for field of timestamp
// alert reuqest
message AlertRequest {
int32 Type =1;
string Uid =2;
@tocalai
tocalai / Program.cs
Created Jun 17, 2019
Continue With handle task excpetion(II)
View Program.cs
class Program
{
static void Main (string[] args)
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
var t1 = RunTaskWithException ();
@tocalai
tocalai / Program.cs
Created Jun 17, 2019
Demonstrate use continue with to handle task exception
View Program.cs
class Program
{
static void Main (string[] args)
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
var t1 = RunTaskWithException ();
@tocalai
tocalai / Program.cs
Created Jun 17, 2019
Register of global task unobserved task exception handler
View Program.cs
class Program
{
static void Main (string[] args)
{
// register of global domain unhandled exception hanlder
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
// register of global task unobserved task exception handler
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;
@tocalai
tocalai / Program.cs
Created Jun 17, 2019
Traditional handle task with try-catch block
View Program.cs
class Program
{
static async System.Threading.Tasks.Task Main (string[] args)
{
// register of global domain unhandled exception hanlder
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
// traditional handle task with try-catch block
var result = await RunTaskWithExceptionInnerTryCatch ();
You can’t perform that action at this time.