diff --git a/src/Microsoft.Azure.EventHubs.Processor/AzureStorageCheckpointLeaseManager.cs b/src/Microsoft.Azure.EventHubs.Processor/AzureStorageCheckpointLeaseManager.cs old mode 100644 new mode 100755 index 045b14c..f782d8d --- a/src/Microsoft.Azure.EventHubs.Processor/AzureStorageCheckpointLeaseManager.cs +++ b/src/Microsoft.Azure.EventHubs.Processor/AzureStorageCheckpointLeaseManager.cs @@ -1,6 +1,8 @@ // Copyright (c) Microsoft. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. +using Microsoft.Azure.EventHubs.Processor.Options; + namespace Microsoft.Azure.EventHubs.Processor { using System; @@ -257,7 +259,7 @@ public async Task CreateLeaseIfNotExistsAsync(string partitionId) // thro { CloudBlockBlob leaseBlob = GetBlockBlobReference(partitionId); returnLease = new AzureBlobLease(partitionId, leaseBlob); - string jsonLease = JsonConvert.SerializeObject(returnLease); + string jsonLease = JsonConvert.SerializeObject(returnLease, JsonConvertOptions.GetOptions()); ProcessorEventSource.Log.AzureStorageManagerInfo( this.host.Id, @@ -338,7 +340,7 @@ async Task AcquireLeaseCoreAsync(AzureBlobLease lease) lease.Token = newToken; lease.Owner = this.host.HostName; lease.IncrementEpoch(); // Increment epoch each time lease is acquired or stolen by a new host - await leaseBlob.UploadTextAsync(JsonConvert.SerializeObject(lease), null, AccessCondition.GenerateLeaseCondition(lease.Token), null, null).ConfigureAwait(false); + await leaseBlob.UploadTextAsync(JsonConvert.SerializeObject(lease, JsonConvertOptions.GetOptions()), null, AccessCondition.GenerateLeaseCondition(lease.Token), null, null).ConfigureAwait(false); } catch (StorageException se) { @@ -390,7 +392,7 @@ async Task ReleaseLeaseCoreAsync(AzureBlobLease lease) Token = string.Empty, Owner = string.Empty }; - await leaseBlob.UploadTextAsync(JsonConvert.SerializeObject(releasedCopy), null, AccessCondition.GenerateLeaseCondition(leaseId), null, null).ConfigureAwait(false); + await leaseBlob.UploadTextAsync(JsonConvert.SerializeObject(releasedCopy, JsonConvertOptions.GetOptions()), null, AccessCondition.GenerateLeaseCondition(leaseId), null, null).ConfigureAwait(false); await leaseBlob.ReleaseLeaseAsync(AccessCondition.GenerateLeaseCondition(leaseId)).ConfigureAwait(false); } catch (StorageException se) @@ -428,7 +430,7 @@ async Task UpdateLeaseCoreAsync(AzureBlobLease lease) CloudBlockBlob leaseBlob = lease.Blob; try { - string jsonToUpload = JsonConvert.SerializeObject(lease); + string jsonToUpload = JsonConvert.SerializeObject(lease, JsonConvertOptions.GetOptions()); ProcessorEventSource.Log.AzureStorageManagerInfo(this.host.Id, lease.PartitionId, $"Raw JSON uploading: {jsonToUpload}"); await leaseBlob.UploadTextAsync(jsonToUpload, null, AccessCondition.GenerateLeaseCondition(token), null, null).ConfigureAwait(false); } @@ -445,7 +447,7 @@ async Task DownloadLeaseAsync(string partitionId, CloudBlockBlob string jsonLease = await blob.DownloadTextAsync().ConfigureAwait(false); ProcessorEventSource.Log.AzureStorageManagerInfo(this.host.Id, partitionId, "Raw JSON downloaded: " + jsonLease); - AzureBlobLease rehydrated = (AzureBlobLease)JsonConvert.DeserializeObject(jsonLease, typeof(AzureBlobLease)); + AzureBlobLease rehydrated = (AzureBlobLease)JsonConvert.DeserializeObject(jsonLease, typeof(AzureBlobLease), JsonConvertOptions.GetOptions()); AzureBlobLease blobLease = new AzureBlobLease(rehydrated, blob); return blobLease; } diff --git a/src/Microsoft.Azure.EventHubs.Processor/Microsoft.Azure.EventHubs.Processor.csproj b/src/Microsoft.Azure.EventHubs.Processor/Microsoft.Azure.EventHubs.Processor.csproj old mode 100644 new mode 100755 index 605b42e..3524777 --- a/src/Microsoft.Azure.EventHubs.Processor/Microsoft.Azure.EventHubs.Processor.csproj +++ b/src/Microsoft.Azure.EventHubs.Processor/Microsoft.Azure.EventHubs.Processor.csproj @@ -1,11 +1,10 @@  - This is the next generation Azure Event Hubs .NET Standard Event Processor Host library. For more information about Event Hubs, see https://azure.microsoft.com/en-us/services/event-hubs/ Microsoft.Azure.EventHubs.Processor 2.0.0 Microsoft - net461;netstandard2.0;uap10.0; + netstandard2.0 true Microsoft.Azure.EventHubs.Processor ../../build/keyfile.snk @@ -27,32 +26,25 @@ 2.0.0.0 2.0.0.0 - UAP,Version=v10.0 UAP 10.0.14393.0 10.0.10240.0 .NETCore - v5.0 - - - - - - + \ No newline at end of file diff --git a/src/Microsoft.Azure.EventHubs.Processor/Options/JsonConvertOptions.cs b/src/Microsoft.Azure.EventHubs.Processor/Options/JsonConvertOptions.cs new file mode 100644 index 0000000..04d32b1 --- /dev/null +++ b/src/Microsoft.Azure.EventHubs.Processor/Options/JsonConvertOptions.cs @@ -0,0 +1,26 @@ +using System.Collections.Generic; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; + +namespace Microsoft.Azure.EventHubs.Processor.Options +{ + /// + /// JsonConvert Options + /// + public static class JsonConvertOptions + { + /// + /// Get the JsonConvert formatting options. so it's not conflicting / dependent upon the user's code. + /// + /// + public static JsonSerializerSettings GetOptions() + { + return new JsonSerializerSettings + { + Formatting = Formatting.Indented, + ContractResolver = new CamelCasePropertyNamesContractResolver(), + NullValueHandling = NullValueHandling.Ignore + }; + } + } +} \ No newline at end of file diff --git a/src/Microsoft.Azure.EventHubs/Microsoft.Azure.EventHubs.csproj b/src/Microsoft.Azure.EventHubs/Microsoft.Azure.EventHubs.csproj old mode 100644 new mode 100755 index d54f33b..adb01e7 --- a/src/Microsoft.Azure.EventHubs/Microsoft.Azure.EventHubs.csproj +++ b/src/Microsoft.Azure.EventHubs/Microsoft.Azure.EventHubs.csproj @@ -5,7 +5,7 @@ Microsoft.Azure.EventHubs 2.0.0 Microsoft - net461;netstandard2.0;uap10.0 + netstandard2.0 true Microsoft.Azure.EventHubs ../../build/keyfile.snk