Skip to content

Instantly share code, notes, and snippets.

View redis.cs
private static Lazy<ConnectionMultiplexer> lazyConnection = new Lazy<ConnectionMultiplexer>(() =>
{
return ConnectionMultiplexer.Connect("{redis connection string}");
});
public static ConnectionMultiplexer Connection => lazyConnection.Value;
private static IDatabase Cache => Connection.GetDatabase();
private T getCacheObj<T>(string key)
{
@timgabrhel
timgabrhel / web.config
Created Apr 19, 2016
redis asp.net session provider
View web.config
<system.web>
<sessionState mode="Custom" customProvider="RedisSessionProvider">
<providers>
<add name="RedisSessionProvider"
type="Microsoft.Web.Redis.RedisSessionStateProvider"
port="6379"
host="abc.redis.cache.windows.net"
accessKey="abc"
ssl="false"
connectionTimeoutInMilliseconds="15000"
@timgabrhel
timgabrhel / links.txt
Created Mar 12, 2016
NEWCodeCamp2016 Resources
View links.txt
@timgabrhel
timgabrhel / example.cs
Created Mar 12, 2016
Mini Redis Cache Transient Exception Handling
View example.cs
/// <summary>
/// A simple implementation to automatically retry transient connection error's to cache. Runs for a maximum of 10 seconds before timing out.
/// </summary>
protected TResult AttemptCacheCall<TResult>(Func<TResult> codeFunc)
{
var timeout = false;
var timer = new Timer(10000);
timer.Elapsed += (sender, args) => timeout = true;
timer.AutoReset = false;
timer.Start();
@timgabrhel
timgabrhel / Logger.cs
Created Feb 24, 2016
Application Insights basic logger
View Logger.cs
public class Logger
{
private static TelemetryClient telemetry = null;
public Logger(string instrumentationKey)
{
Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.Active.InstrumentationKey = instrumentationKey;
telemetry = new TelemetryClient();
telemetry.Context.InstrumentationKey = instrumentationKey;
}
@timgabrhel
timgabrhel / FlyoutBase.ShowAttachedFlyout
Created Nov 14, 2014
FlyoutBase.ShowAttachedFlyout
View FlyoutBase.ShowAttachedFlyout
private void ListingPreview_Holding(object sender, HoldingRoutedEventArgs e)
{
FlyoutBase.ShowAttachedFlyout(ListingPreviewStackPanel);
}
View MenuFlyout
<MenuFlyout x:Key="WintsyListingPreviewFlyout"
MenuFlyoutPresenterStyle="{StaticResource WintsyMenuFlyoutPresenterStyle}"
Placement="Bottom">
<MenuFlyoutItem Text="favorite"
Command="{Binding FavoriteListingCommand, Mode=OneWay}" />
<MenuFlyoutItem Text="view shop" />
</MenuFlyout>
View FlyoutBase.AttachedFlyout
<StackPanel x:Name="ListingPreviewStackPanel"
IsHoldingEnabled="True"
Holding="ListingPreview_Holding"
FlyoutBase.AttachedFlyout="{StaticResource WintsyListingPreviewFlyout}"
Tapped="ListingPreview_Tapped">
</StackPanel>
View WintsyMenuFlyoutPresenter
<Style TargetType="MenuFlyoutPresenter" x:Key="WintsyMenuFlyoutPresenterStyle">
<Setter Property="Background" Value="{ThemeResource WintsyFlyoutBackground}" />
<Setter Property="Foreground" Value="{ThemeResource WintsyFlyoutForeground}" />
<Setter Property="BorderThickness" Value="0" />
<Setter Property="ScrollViewer.HorizontalScrollMode" Value="Disabled" />
<Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
<Setter Property="ScrollViewer.VerticalScrollMode" Value="Auto" />
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
<Setter Property="ScrollViewer.IsHorizontalRailEnabled" Value="False" />
<Setter Property="ScrollViewer.IsVerticalRailEnabled" Value="False" />
@timgabrhel
timgabrhel / CloudConfigurationManagerHelper
Last active Aug 29, 2015
CloudConfigurationManager.GetSetting Helper
View CloudConfigurationManagerHelper
public static bool GetSetting<T>(string key, ref T output)
{
var value = CloudConfigurationManager.GetSetting(key);
if (string.IsNullOrWhiteSpace(value) == false)
{
try
{
output = (T) Convert.ChangeType(value, typeof (T));
return true;
}