Skip to content

Instantly share code, notes, and snippets.

View tkouba's full-sized avatar

Tomas Kouba tkouba

  • Prague, Czech Republic
View GitHub Profile
@tkouba
tkouba / RSAKeys.cs
Created June 16, 2021 14:50 — forked from therightstuff/RSAKeys.cs
Import and export RSA Keys between C# and PEM format using BouncyCastle
using Org.BouncyCastle.Crypto;
using Org.BouncyCastle.Crypto.Parameters;
using Org.BouncyCastle.OpenSsl;
using Org.BouncyCastle.Security;
using System;
using System.IO;
using System.Security.Cryptography;
namespace MyProject.Data.Encryption
{
@tkouba
tkouba / Extensions.GetAttributeValue.cs
Created January 28, 2021 13:25
Simple get attribute value helper extension
public static TValue GetAttributeValue<TAttribute, TValue>(this Type type, Func<TAttribute, TValue> valueSelector) where TAttribute : Attribute
{
var att = type.GetCustomAttributes(typeof(TAttribute), true).FirstOrDefault() as TAttribute;
if (att != null)
{
return valueSelector(att);
}
return default(TValue);
}
@tkouba
tkouba / UserDialogsImplWPF.cs
Created November 26, 2020 16:25
Acr.UserDialog WPF implementation preview
namespace Acr.UserDialogs
{
using System;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;
using System.Windows.Threading;
using Acr.UserDialogs.Infrastructure;
using SAPXamarinTransporter.WPF.UserDialogs;
using Xamarin.Forms.Platform.WPF.Controls;
@tkouba
tkouba / MainActivity.cs
Created November 26, 2020 09:09
Show indicator workaround for Xamarin.Forms.PageIs.IsBusy
// Android MainActivity
using Android.App;
using Android.Content.PM;
using Android.OS;
using AndroidHUD; // https://github.com/redth-org/AndHUD
namespace ThemingDemo.Droid
{
[Activity(Label = "ThemingDemo", Icon = "@mipmap/icon", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
@tkouba
tkouba / Reinstaller.cs
Created September 14, 2020 16:57
ClickOnce application migration tool
/* ClickOnceReinstaller v 1.1.0
* - Author: Tomas Kouba (tomas.kouba@gmail.com)*
* - Changes:
* - add reinstall file extension .txt
* - using log4net
* - migration should be cancelled by user
* - TODO
* - add cancellation message to reinstall.txt file
*
* v 1.0.0
@tkouba
tkouba / TrayIconApplicationContext.cs
Created August 27, 2020 10:52
System.Windows.Forms.ApplicationContext enhancement with tray icon and menu.
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MyVpnManager.Base
{
/// <summary>
/// Specifies the contextual information about an application thread with <see cref="Icon"/> and <see cref="ContextMenuStrip"/>
@tkouba
tkouba / FontImageButtonRenderrer.WPF.cs
Created February 25, 2020 13:24
Xamarin custom button renderrer for buttons with FontImagesource
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Xamarin.Forms;
using Xamarin.Forms.Platform.WPF;
using MyDemo.WPF.Renderers;
@tkouba
tkouba / InstallClickOnceApp.cs
Created October 18, 2019 06:07 — forked from josheinstein/InstallClickOnceApp.cs
Install ClickOnce application programmatically (C#)
using System;
using System.Collections.Generic;
using System.Deployment.Application;
using System.Linq;
using System.Text;
using System.Threading;
namespace InstallClickOnceApp
{
@tkouba
tkouba / CreateName.cs
Created June 28, 2018 12:19
Create valid variable name in PascalCase from any text - remove invalid characters, add underscore prefix if needed
public static string CreateName(this string s) {
s = s.Normalize(NormalizationForm.FormD);
StringBuilder sb = new StringBuilder();
bool upper = true;
for (int i = 0; i < s.Length; i++)
{
var cat = System.Globalization.CharUnicodeInfo.GetUnicodeCategory(s[i]);
//Console.WriteLine(cat);
if (cat == System.Globalization.UnicodeCategory.DecimalDigitNumber && sb.Length == 0)
sb.Append('_');
@tkouba
tkouba / IEnumStringToArray.cs
Created August 29, 2017 17:31
COM interface IEnumString to string array
private string[] IEnumStringToArray(IEnumString enumerator)
{
const int S_OK = 0x00000000;
List<string> lst = new List<string>();
if (enumerator != null)
{
int cft;
string[] strF = new string[100];
int hresult;
IntPtr intPtr = Marshal.AllocCoTaskMem(sizeof(int));