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

Added DateOnly as a known type, so it is used in the schema and when … #37

Merged
merged 3 commits into from
Sep 11, 2024
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
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>10.6.5</Version>
<Version>10.6.6</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
1 change: 1 addition & 0 deletions src/ODataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ private static Type GetColumnType(string columnTypeString)
case "Edm.Stream":
return typeof(Stream);
case "Edm.Date":
return typeof(DateOnly);
case "Edm.DateTimeOffset":
return typeof(DateTime);
case "Edm.Boolean":
Expand Down
7 changes: 4 additions & 3 deletions src/ODataSourceReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,9 @@
{
if (_mapping.SourceTable.Columns.Any(obj => obj.Name.Equals(delta, StringComparison.OrdinalIgnoreCase)))
{
dateTimeFilterName = _mapping.SourceTable.Columns.Where(obj => obj.Name.Equals(delta, StringComparison.OrdinalIgnoreCase)).First().Name;
var dateTimeFilterColumn = _mapping.SourceTable.Columns.Where(obj => obj.Name.Equals(delta, StringComparison.OrdinalIgnoreCase)).First();
isEdmDate = dateTimeFilterColumn.Type == typeof(DateOnly);
dateTimeFilterName = dateTimeFilterColumn.Name;
break;
}
}
Expand All @@ -295,11 +297,9 @@
{
case "Last_Date_Modified":
dateTimeFilterName = "Last_Date_Modified";
isEdmDate = true;
break;
case "Order_Date":
dateTimeFilterName = "Order_Date";
isEdmDate = true;
break;
case "LastDateTimeModified":
dateTimeFilterName = "LastDateTimeModified";
Expand All @@ -311,6 +311,7 @@
dateTimeFilterName = "modifiedon";
break;
}
isEdmDate = column.Type == typeof(DateOnly);
}
}

Expand Down Expand Up @@ -579,11 +580,11 @@
if (endpointAuthentication.IsTokenBased())
{
string token = GetToken(_endpoint, endpointAuthentication);
task = RetryHelper.RetryOnExceptionAsync<Exception>(10, async () => { _httpRestClient.GetAsync(url, HandleStream, token, (Dictionary<string, string>)headers).Wait(new CancellationTokenSource(_timeoutInMilliseconds).Token); }, _logger);

Check warning on line 583 in src/ODataSourceReader.cs

View workflow job for this annotation

GitHub Actions / call-workflow / Build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 583 in src/ODataSourceReader.cs

View workflow job for this annotation

GitHub Actions / call-workflow / Build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
}
else
{
task = RetryHelper.RetryOnExceptionAsync<Exception>(10, async () => { _httpRestClient.GetAsync(url, HandleStream, endpointAuthentication, (Dictionary<string, string>)headers).Wait(new CancellationTokenSource(_timeoutInMilliseconds).Token); }, _logger);

Check warning on line 587 in src/ODataSourceReader.cs

View workflow job for this annotation

GitHub Actions / call-workflow / Build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 587 in src/ODataSourceReader.cs

View workflow job for this annotation

GitHub Actions / call-workflow / Build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
}
if (task.IsCanceled)
{
Expand Down Expand Up @@ -700,11 +701,11 @@
if (endpointAuthentication.IsTokenBased())
{
string token = GetToken(_endpoint, endpointAuthentication);
task = RetryHelper.RetryOnExceptionAsync<Exception>(10, async () => { _httpRestClient.GetAsync(checkUrl, HandleResponse, token, (Dictionary<string, string>)GetAllHeaders()).Wait(new CancellationTokenSource(_timeoutInMilliseconds).Token); }, _logger);

Check warning on line 704 in src/ODataSourceReader.cs

View workflow job for this annotation

GitHub Actions / call-workflow / Build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 704 in src/ODataSourceReader.cs

View workflow job for this annotation

GitHub Actions / call-workflow / Build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
}
else
{
task = RetryHelper.RetryOnExceptionAsync<Exception>(10, async () => { _httpRestClient.GetAsync(checkUrl, HandleResponse, endpointAuthentication, (Dictionary<string, string>)GetAllHeaders()).Wait(new CancellationTokenSource(_timeoutInMilliseconds).Token); }, _logger);

Check warning on line 708 in src/ODataSourceReader.cs

View workflow job for this annotation

GitHub Actions / call-workflow / Build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 708 in src/ODataSourceReader.cs

View workflow job for this annotation

GitHub Actions / call-workflow / Build

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
}
if (task.IsCanceled)
{
Expand Down
50 changes: 32 additions & 18 deletions src/ODataWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ public void Write(Dictionary<string, object> Row)
{
primaryKeyColumnValuesForPatch.Add($"{item.Key}={GetTheDateTimeInZeroTimeZone(item.Value, false)}");
}
else if (columnKeyType == typeof(DateOnly))
{
primaryKeyColumnValuesForPatch.Add($"{item.Key}={GetTheDateTimeInZeroTimeZone(item.Value, true)}");
}
else
{
primaryKeyColumnValuesForPatch.Add($"{item.Key}={item.Value}");
Expand Down Expand Up @@ -272,6 +276,10 @@ internal List<string> GetKeyColumnValuesForFilter(Dictionary<string, object> row
{
keyColumnValues.Add($"{keyMapping.DestinationColumn.Name} eq {GetTheDateTimeInZeroTimeZone(keyMapping.ConvertInputValueToOutputValue(row[keyMapping.SourceColumn?.Name]), false)}");
}
else if (keyMapping.DestinationColumn.Type == typeof(DateOnly))
{
keyColumnValues.Add($"{keyMapping.DestinationColumn.Name} eq {GetTheDateTimeInZeroTimeZone(keyMapping.ConvertInputValueToOutputValue(row[keyMapping.SourceColumn?.Name]), true)}");
}
else
{
keyColumnValues.Add($"{keyMapping.DestinationColumn.Name} eq {keyMapping.ConvertInputValueToOutputValue(row[keyMapping.SourceColumn?.Name] ?? null)}");
Expand Down Expand Up @@ -307,6 +315,9 @@ internal string MapValuesToJSon(Dictionary<string, object> row, bool isPatchRequ
case "datetime":
jsonObject.Add(columnMapping.DestinationColumn.Name, GetTheDateTimeInZeroTimeZone(columnValue, false));
break;
case "dateonly":
jsonObject.Add(columnMapping.DestinationColumn.Name, GetTheDateTimeInZeroTimeZone(columnValue, true));
break;
default:
jsonObject.Add(columnMapping.DestinationColumn.Name, Converter.ToString(columnValue));
break;
Expand All @@ -318,27 +329,30 @@ internal string MapValuesToJSon(Dictionary<string, object> row, bool isPatchRequ

public static string GetTheDateTimeInZeroTimeZone(object dateTimeObject, bool isEdmDate)
{
DateTime dateTime = (dateTimeObject is not null && dateTimeObject is DateTime) ? (DateTime)dateTimeObject : Converter.ToDateTime(dateTimeObject);
DateTime dateTimeInUtc;
if (SqlDateTime.MinValue.Value == dateTime || DateTime.MinValue == dateTime)
var inputString = Convert.ToString(dateTimeObject, CultureInfo.InvariantCulture);
if (DateTime.TryParse(inputString, CultureInfo.InvariantCulture, out var dateTime) ||
DateTime.TryParseExact(inputString, "dd-MM-yyyy HH:mm:ss:fff", CultureInfo.InvariantCulture, DateTimeStyles.None, out dateTime))
{
return null;
}
else if (SqlDateTime.MaxValue.Value == dateTime || DateTime.MaxValue == dateTime)
{
return DateTime.MaxValue.ToString("yyyy-MM-dd");
}

dateTimeInUtc = TimeZoneInfo.ConvertTimeToUtc(dateTime);
if (dateTime <= SqlDateTime.MinValue.Value || dateTime <= DateTime.MinValue)
{
return null;
}
else if (dateTime >= SqlDateTime.MaxValue.Value || dateTime >= DateTime.MaxValue)
{
return null;
}

if (dateTimeInUtc.TimeOfDay.TotalMilliseconds > 0 && !isEdmDate)
{
return dateTimeInUtc.ToString("yyyy-MM-ddTHH:mm:ss.fff", CultureInfo.InvariantCulture) + "z";
}
else
{
return dateTimeInUtc.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
if (!isEdmDate)
{
var dateTimeInUtc = TimeZoneInfo.ConvertTimeToUtc(dateTime);
return dateTimeInUtc.ToString("yyyy-MM-ddTHH:mm:ss.fff", CultureInfo.InvariantCulture) + "z";
}
else
{
return dateTime.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
}
}
return null;
}

public void Dispose() { }
Expand Down
Loading