Ejemplo n.º 1
0
        public static DynamiConfiguration HttpUrl(this LocationSources sources, string url, bool optional = false)
        {
            var str = string.Empty;

            try
            {
                using (var client = new HttpClient())
                    using (var response = client.GetAsync(url).Result)
                        using (var content = response.Content)
                        {
                            str = content.ReadAsStringAsync().Result;
                        }
            }
            catch (Exception)
            {
                if (!optional)
                {
                    throw;
                }
            }

            var conf = sources.Interpreter.ParseConfiguration(str);

            sources.RegisterConfiguration(conf);

            return(sources.Configuration);
        }
Ejemplo n.º 2
0
        public static DynamiConfiguration AzureBlockBlob(this LocationSources provider,
                                                         Func <dynamic, dynamic> connectionStringSelector,
                                                         Func <dynamic, dynamic> containerSelector,
                                                         Func <dynamic, dynamic> blobPathSelector,
                                                         bool optional = false)
        {
            try
            {
                return(AzureBlockBlob(provider,
                                      connectionStringSelector.Invoke(provider.Configuration.GetConfiguration()) as string,
                                      containerSelector.Invoke(provider.Configuration.GetConfiguration()) as string,
                                      blobPathSelector.Invoke(provider.Configuration.GetConfiguration()) as string,
                                      optional
                                      ));
            }
            catch (Exception)
            {
                if (!optional)
                {
                    throw;
                }
            }

            return(provider.Configuration);
        }
Ejemplo n.º 3
0
        public static DynamiConfiguration EmbeddedResources(this LocationSources provider, IEnumerable <Assembly> assemblies, string resourcePostfix = "default.conf")
        {
            var resources = GetExpandoFromAssemblies(assemblies, resourcePostfix, provider.Interpreter);

            provider.RegisterConfiguration(resources);
            return(provider.Configuration);
        }
Ejemplo n.º 4
0
        public static DynamiConfiguration String(this LocationSources sources, string str)
        {
            var conf = sources.Interpreter.ParseConfiguration(str);

            sources.RegisterConfiguration(conf);

            return(sources.Configuration);
        }
Ejemplo n.º 5
0
        public static DynamiConfiguration ChainedHierarchy(this LocationSources provider, string resourcePostfix = "settings.conf")
        {
            var executionPath = AppDomain.CurrentDomain.BaseDirectory;

            provider.RegisterConfiguration(LoadAllFilesFromChain(executionPath, resourcePostfix, provider.Interpreter));

            return(provider.Configuration);
        }
Ejemplo n.º 6
0
        public static DynamiConfiguration File(this LocationSources provider, Func <dynamic, dynamic> pathSelector, Encoding encoding, bool optional = false)
        {
            try
            {
                return(File(provider, pathSelector.Invoke(provider.Configuration.GetConfiguration()) as string, encoding, optional));
            }
            catch (Exception)
            {
                if (!optional)
                {
                    throw;
                }
            }

            return(provider.Configuration);
        }
Ejemplo n.º 7
0
        public static DynamiConfiguration HttpUrl(this LocationSources provider, Func <dynamic, dynamic> urlSelector, bool optional = false)
        {
            try
            {
                return(HttpUrl(provider, urlSelector.Invoke(provider.Configuration.GetConfiguration()) as string, optional));
            }
            catch (Exception)
            {
                if (!optional)
                {
                    throw;
                }
            }

            return(provider.Configuration);
        }
Ejemplo n.º 8
0
        public static DynamiConfiguration EmbeddedResources(this LocationSources provider, string resourcePostfix = "default.conf")
        {
            var entryAssembly = Assembly.GetEntryAssembly();
            var assemblies    = AppDomain.CurrentDomain.GetAssemblies();

            var referencedAssemblies = assemblies.SelectMany(c => c.GetReferencedAssemblies());

            var assemblyQueue = new Queue <AssemblyName>(referencedAssemblies);
            var assemblyList  = new List <Assembly>();
            var assemblyHash  = new HashSet <string>();

            while (assemblyQueue.Count > 0)
            {
                var referencedAssembly = assemblyQueue.Dequeue();

                if (assemblyHash.Contains(referencedAssembly.FullName))
                {
                    continue;
                }

                var assembly = Assembly.Load(referencedAssembly);

                foreach (var aa in assembly.GetReferencedAssemblies())
                {
                    assemblyQueue.Enqueue(aa);
                }

                assemblyList.Add(assembly);
                assemblyHash.Add(assembly.FullName);
            }

            var resources = GetExpandoFromAssemblies(assemblies.Union(assemblyList), resourcePostfix, provider.Interpreter);

            if (entryAssembly != null)
            {
                resources = resources.UpdateWith(GetExpandoFromAssemblies(new[] { entryAssembly }, resourcePostfix, provider.Interpreter));
            }

            provider.RegisterConfiguration(resources);
            return(provider.Configuration);
        }
Ejemplo n.º 9
0
        public static DynamiConfiguration File(this LocationSources sources, string path, bool optional = false)
        {
            var str = string.Empty;

            try
            {
                str = System.IO.File.ReadAllText(path);
            }
            catch (IOException)
            {
                if (!optional)
                {
                    throw;
                }
            }

            var conf = sources.Interpreter.ParseConfiguration(str);

            sources.RegisterConfiguration(conf);

            return(sources.Configuration);
        }
Ejemplo n.º 10
0
        public static DynamiConfiguration AzureBlockBlob(this LocationSources provider, string connectionString, string container, string blobPath, bool optional = false)
        {
            var blobClient = CloudStorageAccount.Parse(connectionString).CreateCloudBlobClient();
            var bcontainer = blobClient.GetContainerReference(container);

            var str = string.Empty;

            try
            {
                var blockBlob = bcontainer.GetBlockBlobReference(blobPath);
                str = blockBlob.DownloadText();
            }
            catch (Exception)
            {
                if (!optional)
                {
                    throw;
                }
            }

            provider.RegisterConfiguration(provider.Interpreter.ParseConfiguration(str));

            return(provider.Configuration);
        }
Ejemplo n.º 11
0
 public LocationFinder(InterpreterSources sources, IConfigurationInterpreter configurationInterpreter)
 {
     From = new LocationSources(sources, configurationInterpreter);
 }
Ejemplo n.º 12
0
 public LocationFinder(InterpreterSources sources, IConfigurationInterpreter configurationInterpreter)
 {
     From = new LocationSources(sources, configurationInterpreter);
 }