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;
        }
 private T GetAdapter <T>() where T : class
 {
     return((T)factory.GetAdapter(
                typeof(T),
                new Hashtable(),
                new PropertyDescriptor().AddBehaviors(
                    XmlMetadataBehavior.Default,
                    new MemberwiseEqualityHashCodeStrategy()
                    )
                ));
 }
        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
        }
示例#4
0
        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 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());
        }
示例#6
0
        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 Lazy <T, TMetadata> CreateLazyWithMetadata <T, TMetadata>(Meta <Lazy <T>, IDictionary <string, object> > metaFactory)
        {
            if (metaFactory == null || metaFactory.Value == null)
            {
                return(null);
            }

            if (typeof(TMetadata) == typeof(IDictionary <string, object>))
            {
                return(new Lazy <T, TMetadata>(() => metaFactory.Value.Value, (TMetadata)(metaFactory.Metadata)));
            }

            if (metaFactory.Metadata == null)
            {
                return(null);
            }

            var metadata = metaFactory.Metadata.Values.OfType <TMetadata>().FirstOrDefault();

            if (metadata != null)
            {
                return(new Lazy <T, TMetadata>(() => metaFactory.Value.Value, metadata));
            }

            if (!typeof(T).IsInterface)
            {
                return(null);
            }

            var genMetadata = DictionaryAdapterFactory.GetAdapter <TMetadata, object>(metaFactory.Metadata);

            return(new Lazy <T, TMetadata>(() => metaFactory.Value.Value, genMetadata));
        }
示例#8
0
        private static IAppSettings CreateSettings(System.Collections.IDictionary dictionary)
        {
            var factory = new DictionaryAdapterFactory();
            var adapter = factory.GetAdapter <IAppSettings>(dictionary);

            return(adapter);
        }
示例#9
0
        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();
        }
示例#10
0
        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);
        }
示例#11
0
        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();
        }
示例#13
0
 private T CreateXmlAdapter <T>(string xml, ref XmlDocument document)
 {
     document = document ?? new XmlDocument();
     if (xml != null)
     {
         document.LoadXml(xml);
     }
     return(factory.GetAdapter <T>(document));
 }
示例#14
0
 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();
 }
示例#15
0
        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);
            }
        }
示例#16
0
        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);
        }
示例#17
0
        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);
        }
示例#18
0
        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);
        }
示例#19
0
        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);
        }
示例#20
0
        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);
        }
示例#21
0
        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"]);
        }
示例#22
0
        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"]);
        }
示例#23
0
        /// <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)
                            )
                        ));
            }
        }
示例#24
0
        public static List <T> ParseSearchResponse <T>(string response)
        {
            var queryResults = new List <T>();

            if (!string.IsNullOrEmpty(response))
            {
                string[] results = response.Replace("\n", "").Split('|');

                Dictionary <string, string> valuePairs;

                foreach (string resultItem in results)
                {
                    valuePairs = new Dictionary <string, string>();

                    foreach (string property in resultItem.Split(';').ToList())
                    {
                        // Do workaround for dates in response

                        string[] propertyPair = property.Split(':');
                        if (propertyPair.Length == 2)
                        {
                            valuePairs.Add(propertyPair[0], propertyPair[1]);
                        }
                        else if (propertyPair.Length == 4)
                        {
                            var dateBuilder = new StringBuilder();
                            dateBuilder.Append(propertyPair[1]);
                            // Workaround to parse dates correctly
                            for (int i = 2; i < propertyPair.Length; i++)
                            {
                                dateBuilder.Append(":").Append(propertyPair[i]);
                            }
                            valuePairs.Add(propertyPair[0], dateBuilder.ToString());
                        }
                    }

                    if (valuePairs.Count != 0)
                    {
                        var wrapper = factory.GetAdapter <T>(valuePairs);
                        queryResults.Add(wrapper);
                    }
                }
            }

            return(queryResults);
        }
示例#25
0
        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 ConfigurationReader SetupConfigOf <T>()
        {
            var cnfg = typeof(T);

            var config = configTypes[cnfg.Name];

            var configurationForT = config.Properties.GetValuesDictionary();

            var configConverter = new ConfigConverter(typeof(T), CustomConversions);

            var convertedConfiguration = configConverter.ConvertConfigProperties(configurationForT);

            configBrowser.AddConfigAdapter(
                typeof(T),
                dictionaryAdapterFactory.GetAdapter <T>(convertedConfiguration));

            return(this);
        }
示例#27
0
        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 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)
                        )
                    ));
        }
 private T GetAdapter <T>() where T : class
 {
     return((T)factory.GetAdapter(typeof(T), new Hashtable(), new DictionaryDescriptor()
                                  .AddBehavior(XPathBehavior.Instance)
                                  .AddBehavior(new MemberwiseEqualityHashCodeStrategy())));
 }
示例#31
0
 public T GetConfiguration <T>()
 {
     return(_factory.GetAdapter <T>(ConfigurationMap));
 }
示例#32
0
 private static void RegisterSettings(IWindsorContainer container)
 {
     var factory = new DictionaryAdapterFactory();
     var adapter = factory.GetAdapter<IConfigSetting>(ConfigurationManager.AppSettings);
     container.Register(Component.For<IConfigSetting>().Instance(adapter));
 }
		public void CreateAdapter_NoPrefixPropertiesOnly_WorksFine()
		{
			var person = factory.GetAdapter<IPerson>(dictionary);
			Assert.IsNotNull(person);
		}