Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 7 additions & 5 deletions src/Microsoft.Azure.EventHubs.Processor/AzureStorageCheckpointLeaseManager.cs
100644 → 100755
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -257,7 +259,7 @@ public async Task<Lease> 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,
Expand Down Expand Up @@ -340,7 +342,7 @@ async Task<bool> 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)
{
Expand Down Expand Up @@ -392,7 +394,7 @@ async Task<bool> 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)
Expand Down Expand Up @@ -430,7 +432,7 @@ async Task<bool> 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);
}
Expand All @@ -447,7 +449,7 @@ async Task<AzureBlobLease> 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;
}
Expand Down
12 changes: 2 additions & 10 deletions src/Microsoft.Azure.EventHubs.Processor/Microsoft.Azure.EventHubs.Processor.csproj
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<Description>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/</Description>
<AssemblyTitle>Microsoft.Azure.EventHubs.Processor</AssemblyTitle>
<VersionPrefix>2.0.0</VersionPrefix>
<Authors>Microsoft</Authors>
<TargetFrameworks>net461;netstandard2.0;uap10.0;</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AssemblyName>Microsoft.Azure.EventHubs.Processor</AssemblyName>
<AssemblyOriginatorKeyFile>../../build/keyfile.snk</AssemblyOriginatorKeyFile>
Expand All @@ -27,32 +26,25 @@
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<FileVersion>2.0.0.0</FileVersion>
</PropertyGroup>

<PropertyGroup Condition="'$(TargetFramework)' == 'uap10.0'">
<NugetTargetMoniker>UAP,Version=v10.0</NugetTargetMoniker>
<TargetPlatformIdentifier>UAP</TargetPlatformIdentifier>
<TargetPlatformVersion>10.0.14393.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.10240.0</TargetPlatformMinVersion>
<TargetFrameworkIdentifier>.NETCore</TargetFrameworkIdentifier>
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.Azure.EventHubs\Microsoft.Azure.EventHubs.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="10.0.2" />
<PackageReference Include="WindowsAzure.Storage" Version="8.1.1" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'net461' ">
<Reference Include="System" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'uap10.0' ">
<PackageReference Include="Microsoft.NETCore.UniversalWindowsPlatform " Version="5.2.3" />
</ItemGroup>

</Project>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using System.Collections.Generic;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;

namespace Microsoft.Azure.EventHubs.Processor.Options
{
/// <summary>
/// JsonConvert Options
/// </summary>
public static class JsonConvertOptions
Copy link
Member

@serkantkaraca serkantkaraca Feb 7, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JsonConvertOptions [](start = 24, length = 18)

Instead of this, can you create a static instance of JsonSerializer?

JsonSerializer.Create Method
Creates a new JsonSerializer instance. The JsonSerializer will not use default settings from DefaultSettings.

https://www.newtonsoft.com/json/help/html/M_Newtonsoft_Json_JsonSerializer_Create.htm #Closed

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, though you're creating a custom JsonSerializerSettings obj to be able to use the JsonConvert.SerializeObject function.

I just checked another Azure library, they wrapped the entire json settings into a class, resulting pretty much the same I think...

We cannot create a non-default variant of the JsonConvert unfortunately. We could go for the webjob's implementation although we have to add the ContractResolver property otherwise I'm still conflicting with the snake case my code uses. (because they use JsonSerializer.CreateDefault it reuses the default AND the custom settings of the lib) Looking forward to your opinion on this :)

{
/// <summary>
/// Get the JsonConvert formatting options. so it's not conflicting / dependent upon the user's code.
/// </summary>
/// <returns></returns>
public static JsonSerializerSettings GetOptions()
Copy link
Member

@serkantkaraca serkantkaraca Feb 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

JsonSerializerSettings [](start = 22, length = 22)

Allow custom settings as well. Like getter/setter, allow clients to customize their casing. If not set, return the default.

{
return new JsonSerializerSettings
{
Formatting = Formatting.Indented,
ContractResolver = new CamelCasePropertyNamesContractResolver(),
NullValueHandling = NullValueHandling.Ignore
};
}
}
}
2 changes: 1 addition & 1 deletion src/Microsoft.Azure.EventHubs/Microsoft.Azure.EventHubs.csproj
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<AssemblyTitle>Microsoft.Azure.EventHubs</AssemblyTitle>
<VersionPrefix>2.0.0</VersionPrefix>
<Authors>Microsoft</Authors>
<TargetFrameworks>net461;netstandard2.0;uap10.0</TargetFrameworks>
<TargetFrameworks>netstandard2.0</TargetFrameworks>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<AssemblyName>Microsoft.Azure.EventHubs</AssemblyName>
<AssemblyOriginatorKeyFile>../../build/keyfile.snk</AssemblyOriginatorKeyFile>
Expand Down