Skip to content

Commit b7a203c

Browse files
authored
Merge pull request #83 from vchirikov/master
Add MemoryConfigurationProvider
2 parents e40eb51 + 8e84e7f commit b7a203c

File tree

10 files changed

+165
-155
lines changed

10 files changed

+165
-155
lines changed

IPPDotNetDevKitCSV3/Code/Directory.Build.props

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
<PackageOutputPath>$(SolutionDir)artifacts\nupkg</PackageOutputPath>
1414
<PackageIcon>$(MSBuildThisFileDirectory)logo.png</PackageIcon>
1515
<OutputPath>$(SolutionDir)artifacts\bin</OutputPath>
16-
<Copyright>Copyright © 2018 Intuit, Inc.</Copyright>
17-
<AssemblyVersion>8.0.0.0</AssemblyVersion>
18-
<FileVersion>8.0.0.0</FileVersion>
16+
<Copyright>Copyright © 2019 Intuit, Inc.</Copyright>
17+
<AssemblyVersion>8.0.0.1</AssemblyVersion>
18+
<FileVersion>8.0.0.1</FileVersion>
1919
<Company>Intuit</Company>
2020
<AppendTargetFrameworkToOutputPath>true</AppendTargetFrameworkToOutputPath>
2121
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
@@ -29,7 +29,7 @@
2929
<DefineConstants>NET472;NETFULL</DefineConstants>
3030

3131
</PropertyGroup>
32-
32+
3333
<PropertyGroup Condition="'$(Configuration)|$(TargetFramework)' == 'net461'">
3434
<DefineConstants>NET461;NETFULL</DefineConstants>
3535

@@ -43,7 +43,7 @@
4343

4444

4545

46-
47-
46+
47+
4848

4949
</Project>

IPPDotNetDevKitCSV3/Code/Intuit.Ipp.Core/Configuration/ApiSettings.cs

Lines changed: 0 additions & 71 deletions
This file was deleted.

IPPDotNetDevKitCSV3/Code/Intuit.Ipp.Core/Configuration/BaseUrl.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ namespace Intuit.Ipp.Core.Configuration
2626
/// </summary>
2727
public class BaseUrl
2828
{
29-
30-
3129
/// <summary>
3230
/// Gets or sets the url for QuickBooks Online Rest Service.
3331
/// </summary>

IPPDotNetDevKitCSV3/Code/Intuit.Ipp.Core/Configuration/IApiSettings.cs

Lines changed: 0 additions & 10 deletions
This file was deleted.

IPPDotNetDevKitCSV3/Code/Intuit.Ipp.Core/Configuration/LocalConfigReader.cs renamed to IPPDotNetDevKitCSV3/Code/Intuit.Ipp.Core/Configuration/JsonFileConfigurationProvider.cs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
////*********************************************************
2-
// <copyright file="LocalConfigReader.cs" company="Intuit">
2+
// <copyright file="JsonFileConfigurationProvider.cs" company="Intuit">
33
/*******************************************************************************
44
* Copyright 2016 Intuit
55
*
@@ -11,12 +11,12 @@
1111
*
1212
* Unless required by applicable law or agreed to in writing, software
1313
* distributed under the License is distributed on an "AS IS" BASIS,
14-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implieC:\Users\nshrivastava\Documents\Git\QuickBooks-V3-DotNET-SDK\IPPDotNetDevKitCSV3\Code\Intuit.Ipp.Core\Configuration\LocalConfigReader.csd.
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*******************************************************************************/
1818
//
19-
// <summary>This file contains Local Config Reader.</summary>
19+
// <summary>This file contains Json file config Reader.</summary>
2020
////*********************************************************
2121

2222

@@ -28,7 +28,7 @@ namespace Intuit.Ipp.Core.Configuration
2828
using System.IO;
2929
using Intuit.Ipp.Diagnostics;
3030
using Intuit.Ipp.Exception;
31-
//using Intuit.Ipp.Retry;
31+
//using Intuit.Ipp.Retry;
3232
using Intuit.Ipp.Security;
3333
using Intuit.Ipp.Utility;
3434

@@ -37,30 +37,30 @@ namespace Intuit.Ipp.Core.Configuration
3737
using Microsoft.Extensions.Configuration;
3838
#endif
3939

40-
40+
4141

4242
/// <summary>
43-
/// Specifies the Default Configuration Reader implmentation used by the SDK.
43+
/// Specifies the Default Json file configuration provider implementation used by the SDK.
44+
/// By default reads "appsettings.json" file.
4445
/// </summary>
45-
public class LocalConfigReader : IConfigReader
46+
public class JsonFileConfigurationProvider : Core.IConfigurationProvider
4647
{
4748

4849
#if NETSTANDARD2_0
4950
public string logPath { get; set; }
5051
IConfigurationRoot builder;
51-
public LocalConfigReader(string path)
52+
public JsonFileConfigurationProvider(string path)
5253
{
5354
builder = new ConfigurationBuilder()
54-
.SetBasePath(Directory.GetCurrentDirectory())
55-
.AddJsonFile(path)
55+
.AddJsonFile(path, optional: true)
5656
.Build();
5757
//var builder = new ConfigurationBuilder()
5858
// .AddJsonFile(path)
5959
// .Build();
6060

61-
//// First way
61+
//// First way
6262
//string value1 = _iconfiguration.GetSection("Data").GetSection("ConnectionString").Value;
63-
//// Second way
63+
//// Second way
6464
//string value2 = _iconfiguration.GetValue<string>("Data:ConnectionString");
6565

6666

@@ -79,26 +79,26 @@ public LocalConfigReader(string path)
7979

8080

8181
}
82-
public LocalConfigReader() : this("appsettings.json")
82+
public JsonFileConfigurationProvider() : this("appsettings.json")
8383
{
8484
}
8585

8686

8787
#endif
8888

8989
/// <summary>
90-
/// Reads the configuration from the config file and converts it to custom
90+
/// Reads the configuration from the config file and converts it to custom
9191
/// config objects which the end developer will use to get or set the properties.
9292
/// </summary>
9393
/// <returns>The custom config object.</returns>
94-
public IppConfiguration ReadConfiguration()
94+
public IppConfiguration GetConfiguration()
9595
{
9696

9797

9898
IppConfiguration ippConfig = new IppConfiguration();
9999

100100
#if !NETSTANDARD2_0
101-
101+
102102
IppConfigurationSection ippConfigurationSection = IppConfigurationSection.Instance;
103103
if (ippConfigurationSection == null)
104104
{
@@ -196,7 +196,7 @@ public IppConfiguration ReadConfiguration()
196196
break;
197197
}
198198

199-
//// TODO : This will not be used now.
199+
//// TODO : This will not be used now.
200200
////if (!string.IsNullOrEmpty(ippConfigurationSection.Message.CustomSerializer.Name) && !string.IsNullOrEmpty(ippConfigurationSection.Message.CustomSerializer.Type) && ippConfigurationSection.Message.CustomSerializer.Enable)
201201
////{
202202
//// Type customSerializerType = Type.GetType(ippConfigurationSection.Message.CustomSerializer.Type);
@@ -277,7 +277,7 @@ public IppConfiguration ReadConfiguration()
277277
break;
278278
}
279279

280-
280+
281281
switch (ippConfigurationSection.Retry.Mode)
282282
{
283283
case RetryMode.Linear:
@@ -336,7 +336,7 @@ public IppConfiguration ReadConfiguration()
336336

337337
ippConfig.VerifierToken = new VerifierToken();
338338
ippConfig.VerifierToken.Value = ippConfigurationSection.WebhooksService.WebhooksVerifier.Value;
339-
339+
340340
#endif
341341
#if NETSTANDARD2_0
342342

@@ -447,7 +447,7 @@ public IppConfiguration ReadConfiguration()
447447
}
448448
else if (securityCustomSettings["Enable"] == "true")
449449
{
450-
if (!string.IsNullOrEmpty(securityCustomSettings["Name"]) && !string.IsNullOrEmpty(securityCustomSettings["Type"]) && Convert.ToBoolean(securityCustomSettings["Enable"]) == true)
450+
if (!string.IsNullOrEmpty(securityCustomSettings["Name"]) && !string.IsNullOrEmpty(securityCustomSettings["Type"]))
451451
{
452452
Type customSecurityType = Type.GetType(securityCustomSettings["Type"]);
453453
if (!string.IsNullOrEmpty(securityCustomSettings["Params"]))
@@ -585,7 +585,7 @@ public IppConfiguration ReadConfiguration()
585585
}
586586
}
587587
}
588-
588+
589589

590590
//ippConfig.BaseUrl = new BaseUrl();
591591

@@ -602,7 +602,7 @@ public IppConfiguration ReadConfiguration()
602602

603603
//ippConfig.VerifierToken = new VerifierToken();
604604
ippConfig.VerifierToken.Value = webhooksVerifierTokenSettings["Value"];
605-
605+
606606
#endif
607607
//#if NETSTANDARD2_0
608608
// //IppConfiguration ippConfig = new IppConfiguration();
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
////*********************************************************
2+
// <copyright file="MemoryConfigurationProvider.cs" company="Intuit">
3+
/*******************************************************************************
4+
* Copyright 2016 Intuit
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*******************************************************************************/
18+
//
19+
// <summary>This file contains config provider, that returns user IppConfiguration.</summary>
20+
////*********************************************************
21+
22+
23+
24+
namespace Intuit.Ipp.Core.Configuration
25+
{
26+
using Intuit.Ipp.Diagnostics;
27+
28+
29+
/// <summary>
30+
/// Specifies the configuration provider, that returns user provided <see cref="IppConfiguration"/>
31+
/// </summary>
32+
public class MemoryConfigurationProvider : IConfigurationProvider
33+
{
34+
private readonly IppConfiguration configuration;
35+
36+
/// <summary>
37+
/// Check given new <see cref="IppConfiguration"/> and fill some properties if they isn't setted.
38+
/// </summary>
39+
/// <param name="cfg"></param>
40+
public MemoryConfigurationProvider(IppConfiguration cfg)
41+
{
42+
if (cfg.Logger == null)
43+
{
44+
cfg.Logger = new Logger
45+
{
46+
CustomLogger = new TraceLogger(),
47+
RequestLog = new RequestLog
48+
{
49+
EnableRequestResponseLogging = false,
50+
ServiceRequestLoggingLocation = System.IO.Path.GetTempPath()
51+
}
52+
};
53+
}
54+
if (cfg.Message == null)
55+
{
56+
cfg.Message = new Message
57+
{
58+
Request = new Request
59+
{
60+
CompressionFormat = CompressionFormat.GZip,
61+
SerializationFormat = SerializationFormat.Json
62+
},
63+
Response = new Response
64+
{
65+
CompressionFormat = CompressionFormat.GZip,
66+
SerializationFormat = SerializationFormat.Json
67+
}
68+
};
69+
}
70+
if (cfg.BaseUrl == null)
71+
{
72+
cfg.BaseUrl = new BaseUrl()
73+
;
74+
}
75+
if (cfg.MinorVersion == null)
76+
{
77+
cfg.MinorVersion = new MinorVersion();
78+
}
79+
;
80+
if (cfg.VerifierToken == null)
81+
{
82+
cfg.VerifierToken = new VerifierToken();
83+
}
84+
configuration = cfg;
85+
}
86+
87+
/// <summary>
88+
/// Returns given configuration
89+
/// </summary>
90+
public IppConfiguration GetConfiguration() => configuration;
91+
92+
}
93+
}
94+

0 commit comments

Comments
 (0)