From d74ef52efc127fd2ba7bad26dbeeadec80f6722e Mon Sep 17 00:00:00 2001 From: Vladimir Ilin Date: Sun, 3 Sep 2017 00:30:58 +0300 Subject: [PATCH 1/2] Added class for reading from config file. --- code/FsComposite/Composite.Test/.gitignore | 1 + code/FsComposite/Composite.Test/App.config | 12 ++++++++---- .../Composite.Test/Composite.Test.fsproj | 6 ++++++ .../DataSourceConfigs/github_config.template | 4 ++++ .../DataSourceConfigurationManager.fs | 18 ++++++++++++++++++ code/FsComposite/Composite.Test/Program.fs | 3 +++ .../FsComposite/Composite.Test/packages.config | 1 + 7 files changed, 41 insertions(+), 4 deletions(-) create mode 100644 code/FsComposite/Composite.Test/.gitignore create mode 100644 code/FsComposite/Composite.Test/DataSourceConfigs/github_config.template create mode 100644 code/FsComposite/Composite.Test/DataSourceConfigurationManager.fs diff --git a/code/FsComposite/Composite.Test/.gitignore b/code/FsComposite/Composite.Test/.gitignore new file mode 100644 index 0000000..491b209 --- /dev/null +++ b/code/FsComposite/Composite.Test/.gitignore @@ -0,0 +1 @@ +DataSourceConfigs/*.json \ No newline at end of file diff --git a/code/FsComposite/Composite.Test/App.config b/code/FsComposite/Composite.Test/App.config index 5744095..7c6b932 100644 --- a/code/FsComposite/Composite.Test/App.config +++ b/code/FsComposite/Composite.Test/App.config @@ -1,6 +1,10 @@ - + + - - - + + + + + + \ No newline at end of file diff --git a/code/FsComposite/Composite.Test/Composite.Test.fsproj b/code/FsComposite/Composite.Test/Composite.Test.fsproj index b3912bb..a142688 100644 --- a/code/FsComposite/Composite.Test/Composite.Test.fsproj +++ b/code/FsComposite/Composite.Test/Composite.Test.fsproj @@ -57,6 +57,7 @@ + @@ -70,7 +71,12 @@ FSharp.Core.dll $(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\$(TargetFSharpCoreVersion)\FSharp.Core.dll + + ..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll + True + + diff --git a/code/FsComposite/Composite.Test/DataSourceConfigs/github_config.template b/code/FsComposite/Composite.Test/DataSourceConfigs/github_config.template new file mode 100644 index 0000000..3899fe1 --- /dev/null +++ b/code/FsComposite/Composite.Test/DataSourceConfigs/github_config.template @@ -0,0 +1,4 @@ +{ + "user": "[username]", + "repository": "[name]" +} diff --git a/code/FsComposite/Composite.Test/DataSourceConfigurationManager.fs b/code/FsComposite/Composite.Test/DataSourceConfigurationManager.fs new file mode 100644 index 0000000..d04874a --- /dev/null +++ b/code/FsComposite/Composite.Test/DataSourceConfigurationManager.fs @@ -0,0 +1,18 @@ +namespace Composite.Test + +open System.IO +open System.Configuration + +open Newtonsoft.Json.Linq + +module DataSourceConfigurationManager = + + module Github = + + let config_path = ConfigurationManager.AppSettings.["GithubConfigPath"] + + type Config () = + let config = JObject.Parse(File.ReadAllText(config_path)) + + member this.Username = config.SelectToken("$.user") |> string + member this.Repository = config.SelectToken("$.repository") |> string diff --git a/code/FsComposite/Composite.Test/Program.fs b/code/FsComposite/Composite.Test/Program.fs index c052f3b..8693d57 100644 --- a/code/FsComposite/Composite.Test/Program.fs +++ b/code/FsComposite/Composite.Test/Program.fs @@ -1,6 +1,7 @@ namespace Composite.Test open System + open Composite.Simple.Data open Composite.Core.Composite @@ -20,6 +21,8 @@ module Program = [] let main argv = + let github_config = DataSourceConfigurationManager.Github.Config () + //let ccc = transform2TypesSmart whatWeSearch howToTransform whereWeSearch |> Array.ofSeq // let expanded = ana [ v expand ] (Composite ([Value A; Value A]|> LazyList.ofList)) diff --git a/code/FsComposite/Composite.Test/packages.config b/code/FsComposite/Composite.Test/packages.config index e12e4c8..a050230 100644 --- a/code/FsComposite/Composite.Test/packages.config +++ b/code/FsComposite/Composite.Test/packages.config @@ -1,5 +1,6 @@  + \ No newline at end of file From 4fe0db402819f5c16f3090ba16113381acf7bcbf Mon Sep 17 00:00:00 2001 From: Vladimir Ilin Date: Sun, 3 Sep 2017 17:39:57 +0300 Subject: [PATCH 2/2] Added the password field to the config template. --- .../DataSourceConfigs/github_config.template | 1 + .../Composite.Test/DataSourceConfigurationManager.fs | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/code/FsComposite/Composite.Test/DataSourceConfigs/github_config.template b/code/FsComposite/Composite.Test/DataSourceConfigs/github_config.template index 3899fe1..195b63e 100644 --- a/code/FsComposite/Composite.Test/DataSourceConfigs/github_config.template +++ b/code/FsComposite/Composite.Test/DataSourceConfigs/github_config.template @@ -1,4 +1,5 @@ { "user": "[username]", + "password": "[password]", "repository": "[name]" } diff --git a/code/FsComposite/Composite.Test/DataSourceConfigurationManager.fs b/code/FsComposite/Composite.Test/DataSourceConfigurationManager.fs index d04874a..31d0ca1 100644 --- a/code/FsComposite/Composite.Test/DataSourceConfigurationManager.fs +++ b/code/FsComposite/Composite.Test/DataSourceConfigurationManager.fs @@ -7,12 +7,17 @@ open Newtonsoft.Json.Linq module DataSourceConfigurationManager = + let getJsonValue (config: JObject) key = + config.SelectToken(sprintf "$.%s" key) |> string + module Github = let config_path = ConfigurationManager.AppSettings.["GithubConfigPath"] type Config () = let config = JObject.Parse(File.ReadAllText(config_path)) + let getJsonValueFromConfig = getJsonValue config - member this.Username = config.SelectToken("$.user") |> string - member this.Repository = config.SelectToken("$.repository") |> string + member this.Username = getJsonValueFromConfig "user" + member this.Password = getJsonValueFromConfig "password" + member this.Repository = getJsonValueFromConfig "repository"