Initial commit

This commit is contained in:
2014-04-30 16:57:42 -04:00
commit 5c4a1c8b4c
126 changed files with 52769 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
using System;
using System.Reflection;
using System.Security.AccessControl;
using System.Security.Principal;
using System.Threading;
namespace Common.Helpers
{
public static class ApplicationIsolation
{
public static IDisposable GetIsolationHandle()
{
string applicationName = Assembly.GetEntryAssembly().GetName().Name;
return GetIsolationHandle(applicationName);
}
public static IDisposable GetIsolationHandle(string applicationName)
{
// Create mutex security settings
MutexSecurity mutexSecurity = new MutexSecurity();
// Create a world security identifier
SecurityIdentifier securityIdentifier = new SecurityIdentifier(WellKnownSidType.WorldSid, null);
// Create an access rule for the mutex
MutexAccessRule mutexAccessRule = new MutexAccessRule(securityIdentifier, MutexRights.FullControl, AccessControlType.Allow);
// Add the access rule to the mutex security settings
mutexSecurity.AddAccessRule(mutexAccessRule);
// Create the mutex and see if it was newly created
bool createdNew;
Mutex mutex = new Mutex(false, applicationName, out createdNew, mutexSecurity);
// Return the mutex if it is new
return createdNew ? mutex : null;
}
}
}

36
Helpers/DelayedMethod.cs Normal file
View File

@@ -0,0 +1,36 @@
using System.Timers;
using System.Windows.Threading;
namespace Common.Helpers
{
public class DelayedMethod
{
public delegate void DelayedMethodDelegate();
private readonly Timer _delayTimer;
private readonly DelayedMethodDelegate _methodDelegate;
private readonly Dispatcher _dispatcher;
public DelayedMethod(int interval, DelayedMethodDelegate methodDelegate)
{
_dispatcher = Dispatcher.CurrentDispatcher;
_methodDelegate = methodDelegate;
_delayTimer = new Timer(interval) { AutoReset = false };
_delayTimer.Elapsed += handleDelayTimerElapsed;
}
public void Reset()
{
_delayTimer.Stop();
_delayTimer.Start();
}
private void handleDelayTimerElapsed(object sender, ElapsedEventArgs e)
{
// Make sure we're on the right thread
if (!_dispatcher.CheckAccess())
_dispatcher.Invoke(_methodDelegate);
}
}
}

18
Helpers/Reflection.cs Normal file
View File

@@ -0,0 +1,18 @@
using System;
using System.Linq.Expressions;
namespace Common.Helpers
{
public static class Reflection
{
public static string GetPropertyName<T>(Expression<Func<T>> propertyExpression)
{
MemberExpression memberExpression = (propertyExpression.Body as MemberExpression);
if (memberExpression == null)
return null;
return memberExpression.Member.Name;
}
}
}