Skip to content

Instantly share code, notes, and snippets.

@maxfridbe
maxfridbe / file.cs
Created November 1, 2012 22:54
Autofac Bootstrap and logging
public class LogInjectionModule : Module
{
protected override void Load(ContainerBuilder builder)
{
//log4net added by extension
log4net.Config.XmlConfigurator.Configure();
builder.Register<ILogger>((c, p) => new Log4NetLog(p.TypedAs<Type>()));
}
protected override void AttachToComponentRegistration(IComponentRegistry registry, IComponentRegistration registration)
{
@maxfridbe
maxfridbe / file.cs
Created November 1, 2012 22:55
Reading File From Resource Stream
using (var stream = Assembly.GetExecutingAssembly() .GetManifestResourceStream("SalesForce.Tests.Required_AccountNames.txt"))
{
using (var reader = new StreamReader(stream))
{
embededFile = reader.ReadToEnd();
}
}
@maxfridbe
maxfridbe / file.cs
Created November 1, 2012 22:56
Modify Running App Config
var config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
config.AppSettings.Settings.Remove("CurrentUICulture");
config.AppSettings.Settings.Add("CurrentUICulture", name);
config.Save(ConfigurationSaveMode.Modified, true);
// Force a reload of a changed section.
ConfigurationManager.RefreshSection("appSettings");
@maxfridbe
maxfridbe / rsa.cs
Created November 15, 2012 16:31
RSA ENCRYPT-DECRYPT
public static class RSAClass
{
private static UnicodeEncoding _encoder = new UnicodeEncoding();
public static string Decrypt(string data, string xmlPrivateKey)
{
var rsa = new RSACryptoServiceProvider();
var dataArray = data.Split(new char[] { ',' });
var dataByte = new byte[dataArray.Length];
for (int i = 0; i < dataArray.Length; i++)
@maxfridbe
maxfridbe / inheritance ef.cs
Created November 15, 2012 16:43
EF Inheritance
class Program
{
static void Main(string[] args)
{
var ctx = new Testctx();
var usr = new User() {username = "bob"};
ctx.Users.Add(usr);
ctx.SaveChanges();
@maxfridbe
maxfridbe / mvvm.cs
Created November 15, 2012 17:14
MVVM Published Locators
public class ViewSelector : DataTemplateSelector
{
public override DataTemplate SelectTemplate(object item, DependencyObject container)
{
/*
<Window.Resources>
<Selectors:ViewSelector x:Key="ViewSelector">
</Selectors:ViewSelector>
</Window.Resources>
<DockPanel Name="pnlDockMain" >
@maxfridbe
maxfridbe / shared.cs
Created November 15, 2012 17:36
Shared Resources
/*
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="../../Resources/StringResources.xaml"/>
</ResourceDictionary.MergedDictionaries>
or
@maxfridbe
maxfridbe / autofacmodules.cs
Created November 15, 2012 17:38
AutoFac Modules dll loading
public static class ModuleBootstrapper
{
public static string GetModuleTitle(IViewModel instance)
{
var title = from a in instance.GetType().GetCustomAttributes(typeof(PublishedViewAttribute), false)
let pva = a as PublishedViewAttribute
select pva.Title;
return title.FirstOrDefault();
}
public static Uri GetCurrentUICultureSource(string resourceName, Type containingModule)
@maxfridbe
maxfridbe / pubsubconsole.js
Created November 15, 2012 19:01
Console and Pub Sub
(function(NS, $, undefined) {
//idea gleaned from https://gist.github.com/661855
var o = $({});
NS.Events = {};
NS.Events.subscribe = function () {
console.log('Subscribing to ' + arguments[0]);
o.on.apply(o, arguments);
};
NS.Events.unsubscribe = function () {
console.log('UnSubscribing from ' + arguments[0]);
@maxfridbe
maxfridbe / log4net.xml
Last active October 12, 2015 20:08
Log4Net w/Console
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
</configSections>
<log4net>
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
<file value="log.txt" />
<appendToFile value="true" />
<rollingStyle value="Size" />
<maxSizeRollBackups value="5" />
<maximumFileSize value="1000KB" />