Skip to content

Instantly share code, notes, and snippets.

@epetrie
epetrie / ReflectionExtensions.cs
Last active August 29, 2015 14:21
Reflection / Compiled Lambda Extensions
public static class Reflection
{
public static ConstructorInfo GetDefaultConstructor(this Type type)
{
return type.GetConstructor(Type.EmptyTypes);
}
public static T CreateInstance<T>(this Type type, params object[] args) where T : class
{
return CreateInstance(type, args) as T;
internal static class AuthSessionManager
{
private static readonly TimeSpan DefaultRenewInterval = TimeSpan.FromSeconds(300);
private static readonly int AuthCheckMultiplier = 3;
private static readonly TimeoutDispatcher _dispatcher = new TimeoutDispatcher();
private static readonly Dictionary<string, AuthSession> _sessions = new Dictionary<string, AuthSession>();
private static readonly object LoginLock = new object();
private const int DefaultTokenValue = 1000;
private static readonly Dictionary<int, bool> TokenTable = new Dictionary<int, bool>();
public static class XmlFileManager<T> where T : class, IXmlSerializable<T>, new()
{
private static readonly Dictionary<XmlFileId<T>, XmlFileSet<T>> FileSets = new Dictionary<XmlFileId<T>, XmlFileSet<T>>();
private static readonly TimeSpan SaveCacheInterval = TimeSpan.FromSeconds(3);
private static readonly TimeoutDispatcher Dispatcher = new TimeoutDispatcher();
static XmlFileManager()
{
Dispatcher.AddRepeating(SaveAllCached, EventLogger.LogException, SaveCacheInterval);
}
@epetrie
epetrie / 1OE.cs
Last active December 18, 2015 02:29
Over Engineered?
private readonly object _rviewLock = new object();
public bool ValidateCredentials(string user, string pass)
{
return DoReadTask(() =>
{
var authenticated = RViewConnectionTask(con => con.IsConnected, user, pass, true, "ValidateCredentials");
return authenticated;
}, _rviewLock);
}
@epetrie
epetrie / SsdpSearch.cs
Created August 23, 2012 20:42
ssdpsearch changes
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Net;
using System.Threading;
using System.IO;
using PelcoAPI.Integration.Common;
using PelcoAPI.Integration.Threading;
@epetrie
epetrie / miscnetwork
Created May 11, 2012 16:34
misc network
/// <summary>
/// Gets the next available open port for use with RTP Video Streams. Range is evenly numbered UDP ports between 9000 and 9999.
/// </summary>
/// <param name="localAddress">The local address.</param>
/// <returns></returns>
public static int GetOpenPort(IPAddress localAddress)
{
return GetOpenPort(localAddress, 9000, 9999, 2, true, true);
}
@epetrie
epetrie / ServiceType.cs
Created April 27, 2012 16:18
String Enum Replacement
/// <summary>
/// Represents all Service types.
/// </summary>
public class ServiceType
{
#region Values
/// <remarks/>
public static readonly ServiceType AlarmArrayConfiguration = "urn:schemas-pelco-com:service:AlarmArrayConfiguration:1";
/// <remarks/>