Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

7 - Storing settings in the config file #8

Merged
merged 3 commits into from
Oct 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions code/FsComposite/Composite.Test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DataSourceConfigs/*.json
12 changes: 8 additions & 4 deletions code/FsComposite/Composite.Test/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8"?>

<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
</startup>
<appSettings>
<add key="GithubConfigPath" value="..\..\DataSourceConfigs\github_config.json" />
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this one is interesting. where does it come from?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the ProcessSample project there is same setting in the app.config file.

</appSettings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7" />
</startup>
</configuration>
6 changes: 6 additions & 0 deletions code/FsComposite/Composite.Test/Composite.Test.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<Compile Include="AssemblyInfo.fs" />
<None Include="App.config" />
<Content Include="packages.config" />
<Compile Include="DataSourceConfigurationManager.fs" />
<Compile Include="Program.fs" />
</ItemGroup>
<ItemGroup>
Expand All @@ -70,7 +71,12 @@
<AssemblyName>FSharp.Core.dll</AssemblyName>
<HintPath>$(MSBuildProgramFiles32)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\$(TargetFSharpCoreVersion)\FSharp.Core.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Configuration" />
<Reference Include="System.Core" />
<Reference Include="System.Numerics" />
<Reference Include="System.ValueTuple">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"user": "[username]",
"password": "[password]",
"repository": "[name]"
}
23 changes: 23 additions & 0 deletions code/FsComposite/Composite.Test/DataSourceConfigurationManager.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Composite.Test

open System.IO
open System.Configuration

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 = getJsonValueFromConfig "user"
member this.Password = getJsonValueFromConfig "password"
member this.Repository = getJsonValueFromConfig "repository"
2 changes: 2 additions & 0 deletions code/FsComposite/Composite.Test/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ module Program =
[<EntryPoint>]
let main argv =

let github_config = DataSourceConfigurationManager.Github.Config ()
let inputSimple = Composite ([Value C; Value D] |> LazyList.ofList)
printfn "Input seq: %A" (inputSimple |> toString)

let expanded = ana [v expandSimple] inputSimple
printfn "Expanded seq: %A" (expanded |> toString)


let collapseScn = [find_and_transform_BC ()]
let transformed = cata collapseScn (expanded |> flat)

Expand Down
1 change: 1 addition & 0 deletions code/FsComposite/Composite.Test/packages.config
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ExtCore" version="0.8.46" targetFramework="net47" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net47" />
<package id="System.ValueTuple" version="4.3.0" targetFramework="net47" />
</packages>