Skip to content

Commit

Permalink
Merge pull request #35 from dynamicweb/mss/20085
Browse files Browse the repository at this point in the history
moved logic for adding $top to url into a function. used this functio…
  • Loading branch information
frederik5480 authored Jun 17, 2024
2 parents 3bce085 + 86b4eb9 commit cd916b0
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.0.22</Version>
<Version>10.0.23</Version>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<Title>OData Provider</Title>
<Description>The Odata Provider lets you fetch and map data from or to any OData endpoint.</Description>
Expand Down
6 changes: 3 additions & 3 deletions src/ODataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ public override string ValidateSourceSettings()
{
return "Credentials not set for endpoint, please add credentials before continue.";
}
var endpointStatusCode = GetEndpointResponse(_endpoint.Url, out string _endpointResponse, out Exception exception);
var endpointStatusCode = GetEndpointResponse(ODataSourceReader.GetEndpointUrlWithTop(_endpoint.Url), out string _endpointResponse, out Exception exception);
if (exception != null)
{
return $"{exception.Message}";
Expand All @@ -480,7 +480,7 @@ public override string ValidateDestinationSettings()
{
return "Credentials not set for endpoint, please add credentials before continue.";
}
var endpointStatusCode = GetEndpointResponse(_endpoint.Url, out string _endpointResponse, out Exception exception);
var endpointStatusCode = GetEndpointResponse(ODataSourceReader.GetEndpointUrlWithTop(_endpoint.Url), out string _endpointResponse, out Exception exception);
if (exception != null)
{
return $"{exception.Message}";
Expand Down Expand Up @@ -827,7 +827,7 @@ private bool IsFOEnpoint(string url)
private bool IsCRMEndpoint(string url)
{
bool result = false;
HttpStatusCode response = GetEndpointResponse(url, out string _endpointResponse, out _);
HttpStatusCode response = GetEndpointResponse(ODataSourceReader.GetEndpointUrlWithTop(url), out string _endpointResponse, out _);
if (new HttpResponseMessage(response).IsSuccessStatusCode && !string.IsNullOrEmpty(_endpointResponse))
{
if (_endpointResponse.Contains("<title>Microsoft Dynamics 365</title>", StringComparison.OrdinalIgnoreCase))
Expand Down
17 changes: 11 additions & 6 deletions src/ODataSourceReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -655,25 +655,30 @@ public bool IsDone()
}
}

private bool CheckIfEndpointIsReadyForUse(string url)
internal static string GetEndpointUrlWithTop(string url)
{
string checkUrl = url;
if (url.Contains("?"))
if (url.Contains('?'))
{
bool urlContainsTop = url.Contains("$top=", StringComparison.OrdinalIgnoreCase);
if (new Uri(url).Query.Any() && !urlContainsTop)
{
checkUrl += "&$top=1";
return $"{url}&$top=1";
}
else if (!urlContainsTop)
{
checkUrl += "$top=1";
return $"{url}$top=1";
}
return url;
}
else
{
checkUrl += "?$top=1";
return $"{url}?$top=1";
}
}

private bool CheckIfEndpointIsReadyForUse(string url)
{
string checkUrl = GetEndpointUrlWithTop(url);
_logger?.Info($"Checking if endpoint: '{_endpoint.Name}' is ready for use on URL: '{checkUrl}'");
bool result = false;
Task task;
Expand Down

0 comments on commit cd916b0

Please sign in to comment.