This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal static string GetQuotedValue(string value) | |
{ | |
try | |
{ | |
if (!value.Contains("\"")) return string.Empty; | |
var values = from Match match in Regex.Matches(value, "\"([^\"]*)\"") select match.ToString(); | |
var resultArray = values as string[] ?? values.ToArray(); | |
return !resultArray.Any() ? string.Empty : resultArray.First().Replace("\"", ""); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected override CreateParams CreateParams | |
{ | |
get | |
{ | |
var cp = base.CreateParams; | |
// turn on WS_EX_TOOLWINDOW style bit | |
cp.ExStyle |= 0x80; | |
return cp; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Log.Logger = new LoggerConfiguration() | |
.MinimumLevel.Debug() | |
.WriteTo.Console() | |
.WriteTo.File("logfile.log", rollingInterval: RollingInterval.Day, restrictedToMinimumLevel: LogEventLevel.Information) | |
.WriteTo.CoderrSeriLogSink() | |
.CreateLogger(); | |
public class CoderrSeriLogSink : ILogEventSink |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Security; | |
using System.Security.Cryptography; | |
using System.Text; | |
public static class PasswordGenerator | |
{ | |
public static string Generate(int length) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal static void DeleteFolderRecursively(string rootMap) | |
{ | |
var created = DateTime.MinValue; | |
try | |
{ | |
created = Directory.GetCreationTime(rootMap); | |
foreach (var map in Directory.GetDirectories(rootMap)) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void DeleteAllFilesInFolder(string path) | |
{ | |
try | |
{ | |
if (!Directory.Exists(path)) return; | |
var di = new DirectoryInfo(path); | |
foreach (var file in di.GetFiles()) | |
{ | |
try |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static bool IsRunning() | |
{ | |
var proc = Assembly.GetExecutingAssembly().GetName().Name; | |
var processes = Process.GetProcesses().ToList(); | |
var activeProcs = processes.Where(x => x.ProcessName.ToLower() == proc).ToList(); | |
return activeProcs.Count > 1; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.DirectoryServices.AccountManagement; | |
using (var pc = new PrincipalContext(ContextType.Machine)) | |
{ | |
var up = UserPrincipal.FindByIdentity(pc, IdentityType.SamAccountName, "gebruiker2"); | |
var userExists = (up != null); | |
if (userExists) Console.WriteLine("user exists"); | |
else Console.WriteLine("user not found"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
internal static bool CheckForInternetConnection() | |
{ | |
try | |
{ | |
using (var client = new WebClient()) | |
using (client.OpenRead("http://google.com/generate_204")) | |
{ | |
return true; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using (var s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, System.Net.Sockets.ProtocolType.Udp)) | |
{ | |
s.Bind(new IPEndPoint(IPAddress.Any, 0)); | |
s.Connect("google.com", 0); | |
var ipaddr = s.LocalEndPoint as IPEndPoint; | |
var addr = ipaddr?.Address?.ToString() ?? ""; | |
Console.WriteLine(addr); | |
} |
NewerOlder