public IAzureServiceConfiguration GetConfig(string roleName) { var configFactory = new DictionaryAdapterFactory(); IAzureServiceConfiguration config; try { var rawAzureWebServiceConfig = new Dictionary<string, string>(); var rawAzureServiceConfig = GetConfigRaw(); if (rawAzureServiceConfig.Count > 0) { rawAzureWebServiceConfig = rawAzureServiceConfig[roleName]; } config = configFactory.GetAdapter<IAzureServiceConfiguration>(rawAzureWebServiceConfig); config = ComplementConfigurationFromConfigurationManager(config); } catch(Exception exception) { // happens in some projects when using Full Emulator // so we fallback to cloudconfigurationmanager // this is not bad since we have isolated it in configuration assembly Hashtable hashConfig = GetConfigFromConfigurationManager(); config = configFactory.GetAdapter<IAzureServiceConfiguration>(hashConfig); } return config; }
public void SetUp() #endif { factory = new DictionaryAdapterFactory(); GetAdapter <IPhone>(); GetAdapter <IAddress>(); }
public static string GetQueryStringFromModel <TInterface, TPoco>(TPoco request) where TPoco : TInterface { var requeststring = new StringBuilder(); DictionaryAdapterFactory factory = new DictionaryAdapterFactory(); IDictionary listDictionary = new ListDictionary(); AutoMapper.Mapper.Initialize(c => c.CreateMap <TPoco, TInterface>()); var adapter = factory.GetAdapter <TInterface>(listDictionary); AutoMapper.Mapper.Map(request, adapter); bool isFirst = true; foreach (DictionaryEntry dictionaryEntry in listDictionary) { if (dictionaryEntry.Value != null) { string seperator = isFirst ? "?" : "&"; requeststring.Append($"{seperator}{dictionaryEntry.Key}={dictionaryEntry.Value}"); isFirst = false; } } Mapper.Reset(); return(requeststring.ToString()); }
static void Main(string[] args) { var firstNames = new[] { "Tim", "Dave", "Craig", "Noah", "Mark", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; var lastNames = new[] { "Rayburn", "O'Hara", "Neuwirt", "Coad", "Mikaelis" }; var daf = new DictionaryAdapterFactory(); var da = daf.GetAdapter<IPatient>(new Document() .Add("FirstName", "Tim") .Add("LastName", "Rayburn") .Add("Address", new Document().Add("Line1","Dallas,TX"))); using (var mongo = new Mongo()) { var db = mongo.GetDatabase("StElmo"); var coll = db.GetCollection<Patient>().Linq().Select(p => p.FirstName == "Tim").ToList(); var query = from p in db.GetCollection<Patient>().Linq() where p.FirstName == "Tim" select p; } Console.WriteLine(da.FirstName); Console.WriteLine(da.Address.Line1); Console.WriteLine("Complete"); Console.ReadLine(); }
// github.com/samus/mongodb-csharp // github.com/atheken/norm // github.com/mongo/mongo-csharp-driver static void Main(string[] args) { try { var dict = new Dictionary<string, object>() { {"FirstName","Tim"}, {"LastName","Rayburn"}, {"MiddleName","John"} }; var da = new DictionaryAdapterFactory().GetAdapter<IPerson>(dict); Console.WriteLine(da.FirstName); Console.WriteLine(da.LastName); da.FirstName = "Chris"; da.Aliases = new List<string>() { "Bob", "Frank", "Henry" }; Console.WriteLine(dict["FirstName"]); Console.WriteLine(dict["Aliases"]); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } Console.WriteLine("Complete"); Console.ReadLine(); }
private static void RegisterSettings(IWindsorContainer container) { var factory = new DictionaryAdapterFactory(); var adapter = factory.GetAdapter <IConfigSetting>(ConfigurationManager.AppSettings); container.Register(Component.For <IConfigSetting>().Instance(adapter)); }
private static IAppSettings CreateSettings(System.Collections.IDictionary dictionary) { var factory = new DictionaryAdapterFactory(); var adapter = factory.GetAdapter <IAppSettings>(dictionary); return(adapter); }
public void Run() { var factory = new DictionaryAdapterFactory(); var config = factory.GetAdapter <ISimpleConfiguration>(ConfigurationManager.AppSettings); Console.WriteLine("Smtp Host: {0}", config.SmtpHost); Console.WriteLine("Port: {0}", config.Port); }
public void Run() { var factory = new DictionaryAdapterFactory(); var config = factory.GetAdapter<ISimpleConfiguration>(ConfigurationManager.AppSettings); Console.WriteLine("Smtp Host: {0}", config.SmtpHost); Console.WriteLine("Port: {0}", config.Port); }
public static void RegisterConfigSettings <TSettings>(this ContainerBuilder builder) { var factory = new DictionaryAdapterFactory(); builder.RegisterInstance((object)factory.GetAdapter <TSettings>(ConfigurationManager.AppSettings)) .As <TSettings>() .SingleInstance(); }
static void Main(string[] args) { //var factory = new DictionaryAdapterFactory(); //if you uncomment this line everything is fine, no leaks for (int i = 0; i < 1000000; i++) { var factory = new DictionaryAdapterFactory(); //if you uncomment this line program is reserving more and more memory without releasing it, even though objects are not used anymore var tmp = factory.GetAdapter <IYolo>(new Hashtable()); } Console.ReadKey(); }
public void Run() { IDictionary list = new Hashtable { {"Names", "Andy,Megan,Amber,Charlie,Michela"} }; var listSample = new DictionaryAdapterFactory().GetAdapter<IListSample>(list); foreach (var name in listSample.Names) { Console.WriteLine("Name: {0}", name); } }
protected override void Load(ContainerBuilder builder) { var factory = new DictionaryAdapterFactory(); var appSettingsAdapter = new NameValueCollectionAdapter(_appSettings); var descriptor = new PropertyDescriptor().AddBehavior(new SettingsBehavior()); foreach (var type in _assemblies.SelectMany(val => val.ExportedTypes) .Where(val => val.IsInterface && val.IsAssignableTo <ISettings>() && val != typeof(ISettings))) { builder.RegisterInstance(factory.GetAdapter(type, appSettingsAdapter, descriptor)).As(type); } }
public void Run() { IDictionary list = new Hashtable { { "Names", "Andy,Megan,Amber,Charlie,Michela" } }; var listSample = new DictionaryAdapterFactory().GetAdapter <IListSample>(list); foreach (var name in listSample.Names) { Console.WriteLine("Name: {0}", name); } }
public void Run() { IDictionary dictionary = new Hashtable { { "Title", "The Castle Manual" }, { "Price", "10.99" } }; var factory = new DictionaryAdapterFactory(); var settings = factory.GetAdapter <IProduct>(dictionary); Console.WriteLine("Title: {0}", settings.Title); Console.WriteLine("Price: £{0}", settings.Price); }
public void Run() { IDictionary dictionary = new Hashtable { {"MyName", "Andy"}, {"MyAge", "32"} }; var factory = new DictionaryAdapterFactory(); var person = factory.GetAdapter<IPerson>(dictionary); Console.WriteLine("Name: {0}", person.Name); Console.WriteLine("Age: {0}", person.Age); }
static void Main(string[] args) { var dict = new Dictionary <string, object>() { { "UserId", 1234567 }, { "UserFirstName", "Tim" }, { "UserLastName", "Rayburn" } }; IUserData data = new DictionaryAdapterFactory().GetAdapter <IUserData>(dict); Console.WriteLine(data.FirstName); Console.ReadLine(); }
public void Run() { IDictionary dictionary = new Hashtable { { "MyName", "Andy" }, { "MyAge", "32" } }; var factory = new DictionaryAdapterFactory(); var person = factory.GetAdapter <IPerson>(dictionary); Console.WriteLine("Name: {0}", person.Name); Console.WriteLine("Age: {0}", person.Age); }
static void Main(string[] args) { var dict = new Dictionary<string, object>() { { "UserId", 1234567 }, { "UserFirstName", "Tim" }, { "UserLastName", "Rayburn" } }; IUserData data = new DictionaryAdapterFactory().GetAdapter<IUserData>(dict); Console.WriteLine(data.FirstName); Console.ReadLine(); }
public static void Startup() { #pragma warning disable 618 // Create the container IoC.Container = new WindsorContainer(); // Add the Array Resolver, so we can take dependencies on T[] // while only registering T. IoC.Container.Kernel.Resolver.AddSubResolver(new ArrayResolver(IoC.Container.Kernel)); // Register the kernel and container, in case an installer needs it. IoC.Container.Register( Component.For<IKernel>().Instance(IoC.Container.Kernel), Component.For<IWindsorContainer>().Instance(IoC.Container) ); // Our configuration magic, register all interfaces ending in Config from // this assembly, and create implementations using DictionaryAdapter // from the AppSettings in our app.config. var daf = new DictionaryAdapterFactory(); IoC.Container.Register( Types .FromThisAssembly() .Where(type => type.IsInterface && type.Name.EndsWith("Config")) .Configure( reg => reg.UsingFactoryMethod( (k, m, c) => daf.GetAdapter(m.Implementation, ConfigurationManager.AppSettings) ) )); // Our session magic, register all interfaces ending in Session from // this assembly, and create implementations using DictionaryAdapter // from the current HttpSession IoC.Container.Register( Types .FromThisAssembly() .Where(type => type.IsInterface && type.Name.EndsWith("Session")) .Configure( reg => reg.UsingFactoryMethod( (k, m, c) => daf.GetAdapter(m.Implementation, new SessionDictionary(HttpContext.Current.Session) as IDictionary) ) ).LifestylePerWebRequest()); // Search for an use all installers in this application. IoC.Container.Install(FromAssembly.This()); #pragma warning restore 618 }
public static void Startup() { #pragma warning disable 618 // Create the container IoC.Container = new WindsorContainer(); // Add the Array Resolver, so we can take dependencies on T[] // while only registering T. IoC.Container.Kernel.Resolver.AddSubResolver(new ArrayResolver(IoC.Container.Kernel)); // Register the kernel and container, in case an installer needs it. IoC.Container.Register( Component.For <IKernel>().Instance(IoC.Container.Kernel), Component.For <IWindsorContainer>().Instance(IoC.Container) ); // Our configuration magic, register all interfaces ending in Config from // this assembly, and create implementations using DictionaryAdapter // from the AppSettings in our app.config. var daf = new DictionaryAdapterFactory(); IoC.Container.Register( Types .FromThisAssembly() .Where(type => type.IsInterface && type.Name.EndsWith("Config")) .Configure( reg => reg.UsingFactoryMethod( (k, m, c) => daf.GetAdapter(m.Implementation, ConfigurationManager.AppSettings) ) )); // Our session magic, register all interfaces ending in Session from // this assembly, and create implementations using DictionaryAdapter // from the current HttpSession IoC.Container.Register( Types .FromThisAssembly() .Where(type => type.IsInterface && type.Name.EndsWith("Session")) .Configure( reg => reg.UsingFactoryMethod( (k, m, c) => daf.GetAdapter(m.Implementation, new SessionDictionary(HttpContext.Current.Session) as IDictionary) ) ).LifestylePerWebRequest()); // Search for an use all installers in this application. IoC.Container.Install(FromAssembly.This()); #pragma warning restore 618 }
public void Run() { IDictionary dictionary = new Hashtable { {"Designation", "Square"}, {"Hue", "Red"}, {"Faces", "4"} }; var factory = new DictionaryAdapterFactory(); var shape = factory.GetAdapter<IShape>(dictionary); Console.WriteLine("Name: {0}", shape.Name); Console.WriteLine("Colour: {0}", shape.Colour); Console.WriteLine("Sides: {0}", shape.Sides); }
public void Run() { IDictionary dictionary = new Hashtable { {"Name", "RAM"}, }; var factory = new DictionaryAdapterFactory(); var part = factory.GetAdapter<IComputerPart>(dictionary); Console.WriteLine("Original Name: {0}", part.Name); part.Name = "Random Access Memory"; Console.WriteLine("New Name: {0}", dictionary["Name"]); }
public void Run() { IDictionary dictionary = new Hashtable { { "Name", "RAM" }, }; var factory = new DictionaryAdapterFactory(); var part = factory.GetAdapter <IComputerPart>(dictionary); Console.WriteLine("Original Name: {0}", part.Name); part.Name = "Random Access Memory"; Console.WriteLine("New Name: {0}", dictionary["Name"]); }
/// <summary> /// Running this installer will regester all interfaces that end in "Config" with the windsor container /// and provide a proxy implementation over the AppSettings /// </summary> public void Install(IWindsorContainer container, IConfigurationStore store) { var daf = new DictionaryAdapterFactory(); foreach (var assembly in _fromAssemblies) { container.Register( assembly .Where(type => type.IsInterface && type.Name.EndsWith("Config")) .Configure( reg => reg.UsingFactoryMethod( (k, m, c) => daf.GetAdapter(m.Implementation, ConfigurationManager.AppSettings) ) )); } }
public void Run() { IDictionary dictionary = new Hashtable { { "Designation", "Square" }, { "Hue", "Red" }, { "Faces", "4" } }; var factory = new DictionaryAdapterFactory(); var shape = factory.GetAdapter <IShape>(dictionary); Console.WriteLine("Name: {0}", shape.Name); Console.WriteLine("Colour: {0}", shape.Colour); Console.WriteLine("Sides: {0}", shape.Sides); }
private static IEnvironmentSettings GetLiveEnvironmentSettings(IKernel k, CreationContext c) { var envSet1 = Environment.CurrentDirectory; var envSet2 = Environment.OSVersion.Version.Major; var envSet3 = DateTime.UtcNow.Ticks; var envSet = new DictionaryAdapterFactory().GetAdapter<IEnvironmentSettings>( new Hashtable { {"EnvironmentSetting1", envSet1}, {"EnvironmentSetting2", envSet2}, {"EnvironmentSettingWhichChanges", envSet3} } ); return envSet; }
private static IEnvironmentSettings GetLiveEnvironmentSettings(IKernel k, CreationContext c) { var envSet1 = Environment.CurrentDirectory; var envSet2 = Environment.OSVersion.Version.Major; var envSet3 = DateTime.UtcNow.Ticks; var envSet = new DictionaryAdapterFactory().GetAdapter <IEnvironmentSettings>( new Hashtable { { "EnvironmentSetting1", envSet1 }, { "EnvironmentSetting2", envSet2 }, { "EnvironmentSettingWhichChanges", envSet3 } } ); return(envSet); }
public void Run() { IDictionary dictionary = new Hashtable { { "Item_Description", "Standard Tiles" }, { "Item_Quantity", "10" }, { "Customer_Name", "Mr Pike" }, { "Customer_Phone", "123 456 789" } }; var factory = new DictionaryAdapterFactory(); var order = factory.GetAdapter <IOrder>(dictionary); Console.WriteLine("Item Description: {0}", order.Item.Description); Console.WriteLine("Item Quantity: {0}", order.Item.Quantity); Console.WriteLine("Customer Name: {0}", order.Customer.Name); Console.WriteLine("Customer Phone: {0}", order.Customer.Phone); }
public void Run() { IDictionary dictionary = new Hashtable { {"Item_Description", "Standard Tiles"}, {"Item_Quantity", "10"}, {"Customer_Name", "Mr Pike"}, {"Customer_Phone", "123 456 789"} }; var factory = new DictionaryAdapterFactory(); var order = factory.GetAdapter<IOrder>(dictionary); Console.WriteLine("Item Description: {0}", order.Item.Description); Console.WriteLine("Item Quantity: {0}", order.Item.Quantity); Console.WriteLine("Customer Name: {0}", order.Customer.Name); Console.WriteLine("Customer Phone: {0}", order.Customer.Phone); }
/// <summary> /// Initializes a new instance of the <see cref="StubMonoRailServices"/> class. /// </summary> /// <param name="urlBuilder">The URL builder.</param> /// <param name="filterFactory">The filter factory.</param> /// <param name="viewEngineManager">The view engine manager.</param> /// <param name="actionSelector">The action selector.</param> /// <param name="dynamicActionProviderFactory">The dynamic action provider factory.</param> public StubMonoRailServices(IUrlBuilder urlBuilder, IFilterFactory filterFactory, IViewEngineManager viewEngineManager, IActionSelector actionSelector, IDynamicActionProviderFactory dynamicActionProviderFactory) { this.UrlBuilder = urlBuilder; this.FilterFactory = filterFactory; this.ViewEngineManager = viewEngineManager; this.ActionSelector = actionSelector; this.DynamicActionProviderFactory = dynamicActionProviderFactory; controllerTree = new DefaultControllerTree(); ControllerFactory = new DefaultControllerFactory(controllerTree); StaticResourceRegistry = new DefaultStaticResourceRegistry(); ControllerContextFactory = new DefaultControllerContextFactory(); ControllerDescriptorProvider = new DefaultControllerDescriptorProvider( new DefaultHelperDescriptorProvider(), new DefaultFilterDescriptorProvider(), new DefaultLayoutDescriptorProvider(), new DefaultRescueDescriptorProvider(), new DefaultResourceDescriptorProvider(), new DefaultTransformFilterDescriptorProvider(), new DefaultReturnBinderDescriptorProvider(), new DefaultDynamicActionProviderDescriptorProvider()); ResourceFactory = new DefaultResourceFactory(); ScaffoldingSupport = new StubScaffoldingSupport(); CacheProvider = new StubCacheProvider(); HelperFactory = new DefaultHelperFactory(); ServiceInitializer = new DefaultServiceInitializer(); ExtensionManager = new ExtensionManager(this); ValidatorRegistry = new CachedValidationRegistry(); JSONSerializer = new NewtonsoftJSONSerializer(); DictionaryAdapterFactory = new DictionaryAdapterFactory(); ScriptBuilder = new DefaultScriptBuilder(); }
/// <summary> /// 根据接口类型获取对应的数据 /// </summary> /// <typeparam name="T">接口类型</typeparam> private T GetDataByInterface <T>() { try { object dictionary = null; if (dictHashtable.ContainsKey(typeof(T))) { dictionary = dictHashtable[typeof(T)]; } else { var hs = new Hashtable(); dictionary = new DictionaryAdapterFactory().GetAdapter <T>(hs); dictHashtable[typeof(T)] = dictionary; } return((T)dictionary); } catch { return(default(T)); } }
public static void Startup() { // Add the array resolver, so we can resolve Foo[] and IEnumerable<Foo> IoC.Container.Kernel.Resolver.AddSubResolver(new ArrayResolver(IoC.Container.Kernel, true)); // Add all necessary facilities IoC.Container.AddFacility<LoggingFacility>(l => l.UseNLog("NLog.config")); IoC.Container.AddFacility<TypedFactoryFacility>(); // Our configuration magic, register all interfaces ending in Config from // this assembly, and create implementations using DictionaryAdapter // from the AppSettings in our app.config. var daf = new DictionaryAdapterFactory(); IoC.Container.Register( Types .FromThisAssembly() .Where(type => type.IsInterface && type.Name.EndsWith("Config")) .Configure( reg => reg.UsingFactoryMethod( (k, m, c) => daf.GetAdapter(m.Implementation, ConfigurationManager.AppSettings) ) )); }
public static void Startup() { // Add the array resolver, so we can resolve Foo[] and IEnumerable<Foo> IoC.Container.Kernel.Resolver.AddSubResolver(new ArrayResolver(IoC.Container.Kernel, true)); // Add all necessary facilities IoC.Container.AddFacility <LoggingFacility>(l => l.UseNLog("NLog.config")); IoC.Container.AddFacility <TypedFactoryFacility>(); // Our configuration magic, register all interfaces ending in Config from // this assembly, and create implementations using DictionaryAdapter // from the AppSettings in our app.config. var daf = new DictionaryAdapterFactory(); IoC.Container.Register( Types .FromThisAssembly() .Where(type => type.IsInterface && type.Name.EndsWith("Config")) .Configure( reg => reg.UsingFactoryMethod( (k, m, c) => daf.GetAdapter(m.Implementation, ConfigurationManager.AppSettings) ) )); }
public void SetUp() { dictionary = new Hashtable(); factory = new DictionaryAdapterFactory(); }
private static void RegisterSettings(IWindsorContainer container) { var factory = new DictionaryAdapterFactory(); var adapter = factory.GetAdapter<IConfigSetting>(ConfigurationManager.AppSettings); container.Register(Component.For<IConfigSetting>().Instance(adapter)); }
private static IMailerSettings GetCitadelsConfigurationAdapter() { var citadelsSettings = new DictionaryAdapterFactory().GetAdapter<IMailerSettings>(ConfigurationManager.AppSettings); return citadelsSettings; }
public void SetUp() { nameValueCollection = new NameValueCollection(); factory = new DictionaryAdapterFactory(); }
public void Setup() { _factory = new DictionaryAdapterFactory(); }
public void SetUp() #endif { nameValueCollection = new NameValueCollection(); factory = new DictionaryAdapterFactory(); }
private static IAppConfigSettings GetWebConfiuration(IKernel k, ComponentModel cm, CreationContext cc) { var webConfig = new DictionaryAdapterFactory().GetAdapter<IAppConfigSettings>(ConfigurationManager.AppSettings); return webConfig; }
public virtual void SetUp() { factory = new DictionaryAdapterFactory(); }
public void SetUp() { dictionary = new Hashtable(); factory = new DictionaryAdapterFactory(); }
public void Setup() { _factory = new DictionaryAdapterFactory(); }
private static IConnectionStrings GetConnectionStrings(IKernel k, ComponentModel cm, CreationContext cc) { var connectionStrings = ConfigurationManager.ConnectionStrings; Hashtable configHashtable = new Hashtable(); foreach (var connectionString in connectionStrings) { var connString = (ConnectionStringSettings)connectionString; configHashtable.Add(connString.Name, connString.ConnectionString); } IConnectionStrings connStrings = new DictionaryAdapterFactory().GetAdapter<IConnectionStrings>(configHashtable); return connStrings; }