Skip to content

Instantly share code, notes, and snippets.

@tocalai
tocalai / ProcessHandler.cs
Last active April 22, 2019 03:18
Use Win32 Api for create new process
// Ref: https://stackoverflow.com/questions/19776716/c-sharp-windows-service-creates-process-but-doesnt-executes-it
[SuppressUnmanagedCodeSecurity]
public class ProcessHandler
{
public const int GENERIC_ALL_ACCESS = 0x10000000;
//public const int CREATE_NO_WINDOW = 0x08000000;
public const int STARTF_USESHOWWINDOW = 0x00000001;
public const int SE_PRIVILEGE_ENABLED = 0x00000002;
public const string SE_INCREASE_QUOTA_NAME = "SeIncreaseQuotaPrivilege";
@tocalai
tocalai / Program.cs
Last active April 22, 2019 05:17
Passing arugs into Topshelf while service start
class Program
{
static void Main(string[] args)
{
const string REG_KEY_IMAGE_PATH = "ImagePath";
string env = string.Empty;
var hostBuilder = new HostBuilder()
.ConfigureAppConfiguration((hostContext, config) =>
{
@tocalai
tocalai / Program.cs
Created May 2, 2019 08:27
Introduce jaeger client to demo project
using CsvHelper;
using Jaeger;
using Jaeger.Samplers;
using OpenTracing;
using OpenTracing.Tag;
using OpenTracing.Util;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
@tocalai
tocalai / cefsharp.dependency.table.csv
Created May 16, 2019 00:30
CefSharp run time dependency table
CefSharp Version VC++ Redist Version .Net Framework Version
65.0.0 and above 2015 4.5.2
51.0.0 to 63.0.0 2013 4.5.2
45.0.0 to 49.0.0 2013 4.0.0
43.0.0 and below 2012 4.0.0
@tocalai
tocalai / DemoForm.cs
Created May 16, 2019 00:52
Demo form that use cefsharp
public partial class DemoForm : Form
{
public ChromiumWebBrowser ChromeBrowser;
// the target resource uri for browser rendering
private readonly string _address;
public DemoForm(string address)
{
_address = address;
@tocalai
tocalai / Program.cs
Created May 16, 2019 01:00
Main entry for cefsharp demo form
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
// passing uri resource from arugment
var address = !string.IsNullOrEmpty(args[0]) ? args[0] : "file:///xxxFolder//Error.html";
@tocalai
tocalai / BatchPopPushRedisList.cs
Created May 27, 2019 06:05
Batch pop/push from redis list
private static IDatabase _db;
private static ConnectionMultiplexer _connection;
// create connection to redis instance
// ...
public void BatchPushListRight(string key, IEnumerable<string> values, int expiredSeconds = 300)
{
var batch = _db.CreateBatch();
List<Task> tasks = new List<Task>();
@tocalai
tocalai / BlobService.cs
Created May 29, 2019 01:12
Demonstrate how to sync source blob to destination blob
// Copy source blob to destination blob
// Source file path might looks like: root_folder/sub_folder/.../source.txt for exmaple
public void SyncSourceBlobToDestBlob (string sourceConnString, string destConnString, string sourceFilePath, string prefixSource = "", string prefixTarget = "")
{
try
{
// initial source blob client resource
CloudStorageAccount.TryParse sourceConnString, out var sourceStorageAccount);
var sourceBlobClient = sourceStorageAccount..CreateCloudBlobClient();
var sourceBlobContainer = sourceBlobClient.GetContainerReference("Your source blob name");
@tocalai
tocalai / Program.cs
Created May 29, 2019 02:15
Demonstrate how to fire sync source blob to destination blob example
class Program
{
static void Main (string[] args)
{
// suppose we have collection that filled of source file(s) path
var sources = List<string>()
{
"root/text/demo1.txt",
"root/text/demo2.txt",
"root/text/demo3.txt",
@tocalai
tocalai / ExcelServiceWriter.cs
Last active June 6, 2019 07:12
Demonstrate how to write data via excel template
// Dto class for object mapping to excel template
class ReportDto
{
public string ParentItem { get; set; }
public string Description { get; set; }
public string Branch { get; set; }
public IEnumerable<Record> Records { get; set; }
}
class Record