Skip to content

Commit db9feb4

Browse files
authored
feat: adding an AdditionalParameters property to specify anything the user may want outside of what is in the current parameters (#125)
1 parent 7a5ac70 commit db9feb4

File tree

33 files changed

+826
-18
lines changed

33 files changed

+826
-18
lines changed

clean-bin-and-obj.bat

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@Echo Off
2+
FOR /d /r .\ %%d IN (*) DO (
3+
@IF EXIST "%%d" (
4+
pushd %%d
5+
FOR /d /r %%t IN (bin\, obj\) DO (
6+
@IF EXIST "%%t" (
7+
ECHO "Removing %%t"
8+
rd /s /q "%%t"
9+
)
10+
)
11+
popd
12+
)
13+
)
14+
15+
pause

src/Geo.ArcGIS/Models/Parameters/GeocodingParameters.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace Geo.ArcGIS.Models.Parameters
1212
/// <summary>
1313
/// A parameters object for the geocoding ArcGIS request.
1414
/// </summary>
15-
public class GeocodingParameters : IClientCredentialsParameters
15+
public class GeocodingParameters : IClientCredentialsParameters, IAdditionalParameters
1616
{
1717
/// <summary>
1818
/// Gets a list of address attributes.
@@ -85,5 +85,8 @@ public class GeocodingParameters : IClientCredentialsParameters
8585

8686
/// <inheritdoc/>
8787
public string ClientSecret { get; set; }
88+
89+
/// <inheritdoc/>
90+
public IDictionary<string, string> AdditionalParameters { get; } = new Dictionary<string, string>();
8891
}
8992
}

src/Geo.ArcGIS/Models/Parameters/StorageParameters.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55

66
namespace Geo.ArcGIS.Models.Parameters
77
{
8+
using System.Collections.Generic;
9+
810
/// <summary>
911
/// A parameters object for the storage flag information in ArcGIS request.
1012
/// </summary>
11-
public class StorageParameters
13+
public class StorageParameters : IAdditionalParameters
1214
{
1315
/// <summary>
1416
/// Gets or sets a value indicating whether the results of the operation will be persisted.
@@ -31,5 +33,8 @@ public class StorageParameters
3133
/// (https://developers.arcgis.com/rest/geocode/api-reference/geocoding-free-vs-paid.htm).
3234
/// </summary>
3335
public bool ForStorage { get; set; } = false;
36+
37+
/// <inheritdoc/>
38+
public IDictionary<string, string> AdditionalParameters { get; } = new Dictionary<string, string>();
3439
}
3540
}

src/Geo.ArcGIS/Models/Parameters/SuggestParameters.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace Geo.ArcGIS.Models.Parameters
1313
/// <summary>
1414
/// A parameters object for the suggest ArcGIS request.
1515
/// </summary>
16-
public class SuggestParameters
16+
public class SuggestParameters : IAdditionalParameters
1717
{
1818
/// <summary>
1919
/// Gets or sets the input text entered by a user, which is used by the suggest operation to generate a list of possible matches.
@@ -65,5 +65,8 @@ public class SuggestParameters
6565
/// The default value is postal city.
6666
/// </summary>
6767
public PreferredLabelValue PreferredLabelValue { get; set; } = PreferredLabelValue.PostalCity;
68+
69+
/// <inheritdoc/>
70+
public IDictionary<string, string> AdditionalParameters { get; } = new Dictionary<string, string>();
6871
}
6972
}

src/Geo.ArcGIS/Services/ArcGISGeocoding.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ internal async Task<Uri> BuildAddressCandidateRequest(AddressCandidateParameters
420420
AddStorageParameter(parameters, ref query);
421421

422422
query = await AddArcGISToken(parameters, query, cancellationToken).ConfigureAwait(false);
423+
query = query.AddAdditionalParameters(parameters);
423424

424425
uriBuilder.AddQuery(query);
425426

@@ -597,6 +598,7 @@ internal async Task<Uri> BuildPlaceCandidateRequest(PlaceCandidateParameters par
597598
AddStorageParameter(parameters, ref query);
598599

599600
query = await AddArcGISToken(parameters, query, cancellationToken).ConfigureAwait(false);
601+
query = query.AddAdditionalParameters(parameters);
600602

601603
uriBuilder.AddQuery(query);
602604

@@ -686,6 +688,8 @@ internal Task<Uri> BuildSuggestRequest(SuggestParameters parameters, Cancellatio
686688
_logger.ArcGISWarning(Resources.Services.ArcGISGeocoding.Invalid_Preferred_Label_Value);
687689
}
688690

691+
query = query.AddAdditionalParameters(parameters);
692+
689693
uriBuilder.AddQuery(query);
690694

691695
return Task.FromResult<Uri>(uriBuilder.Uri);
@@ -765,6 +769,7 @@ internal async Task<Uri> BuildReverseGeocodingRequest(ReverseGeocodingParameters
765769
AddStorageParameter(parameters, ref query);
766770

767771
query = await AddArcGISToken(parameters, query, cancellationToken).ConfigureAwait(false);
772+
query = query.AddAdditionalParameters(parameters);
768773

769774
uriBuilder.AddQuery(query);
770775

@@ -884,6 +889,7 @@ internal async Task<Uri> BuildGeocodingRequest(GeocodingParameters parameters, C
884889
}
885890

886891
query = await AddArcGISToken(parameters, query, cancellationToken).ConfigureAwait(false);
892+
query = query.AddAdditionalParameters(parameters);
887893

888894
uriBuilder.AddQuery(query);
889895

src/Geo.Bing/Models/Parameters/BaseParameters.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55

66
namespace Geo.Bing.Models.Parameters
77
{
8+
using System.Collections.Generic;
89
using System.Globalization;
910

1011
/// <summary>
1112
/// Base parameters across all Bing geocoding APIs.
1213
/// </summary>
13-
public class BaseParameters
14+
public class BaseParameters : IAdditionalParameters
1415
{
1516
/// <summary>
1617
/// Gets or sets a value indicating whether or not to include the neighbourhood information.
@@ -34,5 +35,8 @@ public class BaseParameters
3435
/// Gets or sets the culture to use for the request.
3536
/// </summary>
3637
public CultureInfo Culture { get; set; }
38+
39+
/// <inheritdoc/>
40+
public IDictionary<string, string> AdditionalParameters { get; } = new Dictionary<string, string>();
3741
}
3842
}

src/Geo.Bing/Services/BingGeocoding.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ internal Uri BuildGeocodingRequest(GeocodingParameters parameters)
126126
BuildLimitedResultQuery(parameters, ref query);
127127

128128
AddBingKey(parameters, ref query);
129+
query = query.AddAdditionalParameters(parameters);
129130

130131
uriBuilder.AddQuery(query);
131132

@@ -197,6 +198,7 @@ internal Uri BuildReverseGeocodingRequest(ReverseGeocodingParameters parameters)
197198
BuildBaseQuery(parameters, ref query);
198199

199200
AddBingKey(parameters, ref query);
201+
query = query.AddAdditionalParameters(parameters);
200202

201203
uriBuilder.AddQuery(query);
202204

@@ -272,6 +274,7 @@ internal Uri BuildAddressGeocodingRequest(AddressGeocodingParameters parameters)
272274
BuildLimitedResultQuery(parameters, ref query);
273275

274276
AddBingKey(parameters, ref query);
277+
query = query.AddAdditionalParameters(parameters);
275278

276279
uriBuilder.AddQuery(query);
277280

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// <copyright file="IAdditionalParameters.cs" company="Geo.NET">
2+
// Copyright (c) Geo.NET.
3+
// Licensed under the MIT license. See the LICENSE file in the solution root for full license information.
4+
// </copyright>
5+
6+
namespace Geo
7+
{
8+
using System.Collections.Generic;
9+
10+
/// <summary>
11+
/// Parameters that allow additional key/value pairs to be appended to the request query string.
12+
/// </summary>
13+
public interface IAdditionalParameters
14+
{
15+
/// <summary>
16+
/// Gets the additional key/value pairs to be appended to the request query string.
17+
/// </summary>
18+
IDictionary<string, string> AdditionalParameters { get; }
19+
}
20+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// <copyright file="QueryStringExtensions.cs" company="Geo.NET">
2+
// Copyright (c) Geo.NET.
3+
// Licensed under the MIT license. See the LICENSE file in the solution root for full license information.
4+
// </copyright>
5+
6+
namespace Geo.Core.Extensions
7+
{
8+
using Geo;
9+
10+
/// <summary>
11+
/// Extension methods on the <see cref="QueryString"/> struct.
12+
/// </summary>
13+
public static class QueryStringExtensions
14+
{
15+
/// <summary>
16+
/// Adds any additional parameters from an <see cref="IAdditionalParameters"/> instance to the <see cref="QueryString"/>.
17+
/// Entries with a null value are skipped.
18+
/// </summary>
19+
/// <param name="query">The <see cref="QueryString"/> to add to.</param>
20+
/// <param name="parameters">The <see cref="IAdditionalParameters"/> to read additional key/value pairs from.</param>
21+
/// <returns>The <see cref="QueryString"/> with the additional parameters appended.</returns>
22+
public static QueryString AddAdditionalParameters(this QueryString query, IAdditionalParameters parameters)
23+
{
24+
if (parameters?.AdditionalParameters == null)
25+
{
26+
return query;
27+
}
28+
29+
foreach (var kvp in parameters.AdditionalParameters)
30+
{
31+
if (kvp.Value == null)
32+
{
33+
continue;
34+
}
35+
36+
query = query.Add(kvp.Key, kvp.Value);
37+
}
38+
39+
return query;
40+
}
41+
}
42+
}

src/Geo.Google/Models/Parameters/BaseParameters.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,20 @@
55

66
namespace Geo.Google.Models.Parameters
77
{
8+
using System.Collections.Generic;
89
using System.Globalization;
910

1011
/// <summary>
1112
/// The base parameters shared across all requests.
1213
/// </summary>
13-
public class BaseParameters
14+
public class BaseParameters : IAdditionalParameters
1415
{
1516
/// <summary>
1617
/// Gets or sets the language in which to return results.
1718
/// </summary>
1819
public CultureInfo Language { get; set; }
20+
21+
/// <inheritdoc/>
22+
public IDictionary<string, string> AdditionalParameters { get; } = new Dictionary<string, string>();
1923
}
2024
}

0 commit comments

Comments
 (0)