Skip to content

Commit

Permalink
Fix GetModules call error using RFC3339 DateTime format. (Azure#4293)
Browse files Browse the repository at this point in the history
Fix issue calling GetModuleLogs using DirectMethod with a payload that contains parameters using RF3339 DateTime format.
  • Loading branch information
pmzara committed Jan 29, 2021
1 parent 02f1832 commit 8d9a8e0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ namespace Microsoft.Azure.Devices.Edge.Agent.Core.Requests
using System.Threading.Tasks;
using Microsoft.Azure.Devices.Edge.Storage;
using Microsoft.Azure.Devices.Edge.Util;
using Newtonsoft.Json;
using Prometheus;

public abstract class RequestHandlerBase<TU, TV> : IRequestHandler
Expand Down Expand Up @@ -35,7 +36,8 @@ protected virtual Option<TU> ParsePayload(Option<string> payloadJson)
{
try
{
return payloadJson.Map(p => p.FromJson<TU>());
var jsonSerializerSettings = new JsonSerializerSettings { DateParseHandling = DateParseHandling.None };
return payloadJson.Map(p => p.FromJson<TU>(jsonSerializerSettings));
}
catch (Exception ex)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace Microsoft.Azure.Devices.Edge.Storage

public static class SerDeExtensions
{
public static T FromJson<T>(this string json)
public static T FromJson<T>(this string json, JsonSerializerSettings jsonSerializerSettings = null)
{
if (string.IsNullOrWhiteSpace(json))
{
Expand All @@ -17,7 +17,7 @@ public static T FromJson<T>(this string json)

return typeof(T) == typeof(string)
? (T)(object)json
: JsonConvert.DeserializeObject<T>(json);
: JsonConvert.DeserializeObject<T>(json, jsonSerializerSettings);
}

public static string ToJson(this object value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ public async Task TestGetModuleLogs()
}, token);
await Task.Delay(30000);

var request = new ModuleLogsRequest("1.0", new List<LogRequestItem> { new LogRequestItem(moduleName, new ModuleLogFilter(Option.None<int>(), Option.None<string>(), Option.None<string>(), Option.None<int>(), Option.None<string>())) }, LogsContentEncoding.None, LogsContentType.Text);
string since = DateTime.Now.AddDays(-1).ToString("yyyy-MM-dd'T'HH:mm:sZ");
string until = DateTime.Now.AddDays(+1).ToString("yyyy-MM-dd'T'HH:mm:sZ");

var request = new ModuleLogsRequest("1.0", new List<LogRequestItem> { new LogRequestItem(moduleName, new ModuleLogFilter(Option.Some(10), Option.Some(since), Option.Some(until), Option.None<int>(), Option.None<string>())) }, LogsContentEncoding.None, LogsContentType.Text);

var result = await this.iotHub.InvokeMethodAsync(this.runtime.DeviceId, ConfigModuleName.EdgeAgent, new CloudToDeviceMethod("GetModuleLogs", TimeSpan.FromSeconds(300), TimeSpan.FromSeconds(300)).SetPayloadJson(JsonConvert.SerializeObject(request)), token);

Expand Down

0 comments on commit 8d9a8e0

Please sign in to comment.