Skip to content

Instantly share code, notes, and snippets.

public void Execute() {
var employee = PayrollDatabase.Instance.GetEmployee(_empId);
if(employee!=Employee.NotFound) {
Change(employee);
}
}
public void Execute() {
EmployeeResult result = PayrollDatabase.Instance.GetEmployee(_empId);
if(result!=EmployeeResult.NotFound) {
Change(result.Employee);
}
}
string PrintMaxValue() {
int maxValue = intSet.Max();
if(maxValue == 0) {
return "Not available";
}
return maxValue.ToString();
}
public AddCommissionedEmployee(int empId,string name,string address,decimal salary,decimal commissionRate)
: base(empId, name,address) {
_salary = salary;
_commissionRate = commissionRate;
}
public AddCommissionedEmployee(EmployeeId empId,Name name, Address address, Salary salary, CommissionRate commissionRate)
: base(empId, name,address) {
_salary = salary;
_commissionRate = commissionRate;
}
@FreekPaans
FreekPaans / PFXGenerator.cs
Last active August 29, 2015 14:18
Class to generate X.509 certificates using Mono.Security
public class PFXGenerator {
//adapted from https://github.com/mono/mono/blob/master/mcs/tools/security/makecert.cs
public static byte[] GeneratePfx(string certificateName,string password) {
byte[] sn = GenerateSerialNumber();
string subject = string.Format("CN={0}",certificateName);
DateTime notBefore = DateTime.Now;
DateTime notAfter = DateTime.Now.AddYears(20);
RSA subjectKey = new RSACryptoServiceProvider(2048);
@FreekPaans
FreekPaans / generatepfxcer.cs
Created April 7, 2015 14:13
Generate PFX + cer
const string password= "testpassword";
var pfx= PFXGenerator.GeneratePfx("testcertificate", password);
File.WriteAllBytes("cert.pfx", pfx);
File.WriteAllBytes("cert.cer", PFXGenerator.GetCertificateForBytes(pfx,password));
@FreekPaans
FreekPaans / printservicepointconnections.cs
Created July 7, 2015 06:48
This prints the connections currently open in a servicepoint
private static void PrintServicePointConnections(ServicePoint sp) {
var spType = sp.GetType();
var privateOrPublicInstanceField = System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance;
var connectionGroupField = spType.GetField("m_ConnectionGroupList",privateOrPublicInstanceField);
var value = (Hashtable)connectionGroupField.GetValue(sp);
foreach(var key in value.Keys) {
var connectionGroup = value[key];
var groupType = connectionGroup.GetType();
var listField = groupType.GetField("m_ConnectionList",privateOrPublicInstanceField);
var listValue = (ArrayList)listField.GetValue(connectionGroup);
@FreekPaans
FreekPaans / ServicePointMonitor.cs
Last active August 29, 2015 14:24
monitors the servicepointmanager
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
namespace WadGraphEs.MetricsEndpoint.Console {
using System.Reflection;
class Vector {
private readonly double _x;
private readonly double _y;
public Vector(double x, double y) {
_x = x;
_y = y;
}
public Vector Add(Vector addend) {