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

Update NuGet packages, Replace Newtonsoft. #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
46 changes: 31 additions & 15 deletions Controllers/VideoIndexerController.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using VideoIndexerApi.Models;
using System;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.Threading.Tasks;
using System.IO;
using System.Text;
Expand All @@ -17,6 +15,7 @@
using System.Net.Http;
using System.Collections.Generic;
using System.Linq;
using System.Text.Json;

namespace VideoIndexerApi.Controllers
{
Expand Down Expand Up @@ -74,8 +73,8 @@ public async Task<IActionResult> Post()

private async Task<IActionResult> HandleCloudEvent(string jsonContent)
{
var details = JsonConvert.DeserializeObject<CloudEvent<dynamic>>(jsonContent);
var eventData = JObject.Parse(jsonContent);
var details = JsonSerializer.Deserialize<CloudEvent<dynamic>>(jsonContent);
var eventData = JsonDocument.Parse(jsonContent);

if (details.Type == "Microsoft.Storage.BlobCreated" &&
details.Subject.StartsWith("/blobServices/default/containers"))
Expand Down Expand Up @@ -110,9 +109,10 @@ private async Task UploadToCosmosDbAsync(string stateStoreKey)
var videoIndexState = await this._daprClient.GetStateEntryAsync<string>(StateKey, stateStoreKey);

// Attempt to read one JSON object.
var partialVideoIndex = JsonConvert.DeserializeObject<VideoIndex<dynamic>>(videoIndexState.Value);
var partialVideoIndex = JsonSerializer.Deserialize<VideoIndex<dynamic>>(videoIndexState.Value);

JObject o = JObject.FromObject(new
// TODO: Missing API function in System.Text.Json
var jsonContent = JsonSerializer.Serialize(new
{
data = new
{
Expand All @@ -126,7 +126,22 @@ private async Task UploadToCosmosDbAsync(string stateStoreKey)
}
);

var jsonContent = JsonConvert.SerializeObject(o);
/* JObject o = JObject.FromObject(new
{
data = new
{
key = "id",
id = partialVideoIndex.VideoId,
name = partialVideoIndex.Name,
created = partialVideoIndex.Created,
duration = partialVideoIndex.DurationInSeconds,
summary = partialVideoIndex.Summary
}
}
); */

//var jsonContent = JsonSerializer.Serialize(o);

var content = new StringContent(jsonContent, Encoding.UTF8, "application/json");
var dapr_port = _configuration["DAPR_HTTP_PORT"];

Expand Down Expand Up @@ -216,7 +231,7 @@ private async Task<string> GetVideoIndex(string fileName,
});
HttpResponseMessage result = await client.GetAsync($"{apiUrl}/auth/trial/Accounts?{queryParams}");
var json = await result.Content.ReadAsStringAsync();
var accounts = JsonConvert.DeserializeObject<AccountContractSlim[]>(json);
var accounts = JsonSerializer.Deserialize<AccountContractSlim[]>(json);

// take the relevant account, here we simply take the first,
// you can also get the account via accounts.First(account => account.Id == <GUID>);
Expand Down Expand Up @@ -259,7 +274,7 @@ private async Task<string> UploadVideoAndIndex(string fileName, string videoUrl)
});
HttpResponseMessage result = await client.GetAsync($"{apiUrl}/auth/trial/Accounts?{queryParams}");
var json = await result.Content.ReadAsStringAsync();
var accounts = JsonConvert.DeserializeObject<AccountContractSlim[]>(json);
var accounts = JsonSerializer.Deserialize<AccountContractSlim[]>(json);

// take the relevant account, here we simply take the first,
// you can also get the account via accounts.First(account => account.Id == <GUID>);
Expand Down Expand Up @@ -288,7 +303,7 @@ private async Task<string> UploadVideoAndIndex(string fileName, string videoUrl)
var uploadResult = await uploadRequestResult.Content.ReadAsStringAsync();

// get the video ID from the upload result
string videoId = JsonConvert.DeserializeObject<dynamic>(uploadResult)["id"];
string videoId = JsonSerializer.Deserialize<dynamic>(uploadResult)["id"];
Console.WriteLine("Uploaded");
Console.WriteLine("Video ID:");
Console.WriteLine(videoId);
Expand All @@ -308,7 +323,7 @@ private async Task<string> UploadVideoAndIndex(string fileName, string videoUrl)
var videoGetIndexRequestResult = await client.GetAsync($"{apiUrl}/{accountInfo.Location}/Accounts/{accountInfo.Id}/Videos/{videoId}/Index?{queryParams}");
var videoGetIndexResult = await videoGetIndexRequestResult.Content.ReadAsStringAsync();

string processingState = JsonConvert.DeserializeObject<dynamic>(videoGetIndexResult)["state"];
string processingState = JsonSerializer.Deserialize<dynamic>(videoGetIndexResult)["state"];

Console.WriteLine("");
Console.WriteLine("State:");
Expand All @@ -319,8 +334,8 @@ private async Task<string> UploadVideoAndIndex(string fileName, string videoUrl)
{
if (processingState == "Failed")
{
string failureCode = JsonConvert.DeserializeObject<dynamic>(videoGetIndexResult)["failureCode"];
string failureMessage = JsonConvert.DeserializeObject<dynamic>(videoGetIndexResult)["failureMessage"];
string failureCode = JsonSerializer.Deserialize<dynamic>(videoGetIndexResult)["failureCode"];
string failureMessage = JsonSerializer.Deserialize<dynamic>(videoGetIndexResult)["failureMessage"];
Console.WriteLine("Indexing failed!");
Console.WriteLine("failureCode: " + failureCode);
Console.WriteLine("failureMessage: " + failureMessage);
Expand Down Expand Up @@ -384,10 +399,11 @@ private static bool IsCloudEvent(string jsonContent)
try
{
// Attempt to read one JSON object.
var eventData = JObject.Parse(jsonContent);
var eventData = JsonDocument.Parse(jsonContent);

// Check for the spec version property.
var version = eventData["specversion"].Value<string>();
var version = eventData.RootElement.GetProperty("specversion").GetString();
// var version = eventData["specversion"].Value<string>();
if (!string.IsNullOrEmpty(version)) return true;
}
catch (Exception e)
Expand Down
4 changes: 2 additions & 2 deletions HealthChecks/ReadinessHealthCheck.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Diagnostics.HealthChecks;
using Microsoft.Extensions.Logging;
using Newtonsoft.Json;
using VideoIndexerApi.Models;

namespace VideoIndexerApi.HealthChecks
Expand Down Expand Up @@ -66,7 +66,7 @@ private async Task<bool> TestConnectivityToVideoApi()
{
HttpResponseMessage result = await client.GetAsync($"{apiUrl}/auth/trial/Accounts?{queryParams}");
var json = await result.Content.ReadAsStringAsync();
var accounts = JsonConvert.DeserializeObject<AccountContractSlim[]>(json);
var accounts = JsonSerializer.Deserialize<AccountContractSlim[]>(json);
var accountInfo = accounts.First();

return !string.IsNullOrEmpty(accountInfo.AccessToken);
Expand Down
16 changes: 8 additions & 8 deletions Models/CloudEvent.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace VideoIndexerApi.Models
{
Expand All @@ -7,25 +7,25 @@ namespace VideoIndexerApi.Models

public class CloudEvent<T> where T : class
{
[JsonProperty("id")]
[JsonPropertyName("id")]
public string Id { get; set; }

[JsonProperty("source")]
[JsonPropertyName("source")]
public string Source { get; set; }

[JsonProperty("specversion")]
[JsonPropertyName("specversion")]
public string SpecVersion { get; set; }

[JsonProperty("type")]
[JsonPropertyName("type")]
public string Type { get; set; }

[JsonProperty("subject")]
[JsonPropertyName("subject")]
public string Subject { get; set; }

[JsonProperty("time")]
[JsonPropertyName("time")]
public string Time { get; set; }

[JsonProperty("data")]
[JsonPropertyName("data")]
public T Data { get; set; }
}
}
12 changes: 6 additions & 6 deletions Models/VideoIndex.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace VideoIndexerApi.Models
{
public class VideoIndex<T> where T : class
{
[JsonProperty("id")]
[JsonPropertyName("id")]
public string VideoId { get; set; }

[JsonProperty("name")]
[JsonPropertyName("name")]
public string Name { get; set; }

[JsonProperty("created")]
[JsonPropertyName("created")]
public string Created { get; set; }

[JsonProperty("durationInSeconds")]
[JsonPropertyName("durationInSeconds")]
public int DurationInSeconds { get; set; }

[JsonProperty("summarizedInsights")]
[JsonPropertyName("summarizedInsights")]
public T Summary { get; set; }
}
}
2 changes: 1 addition & 1 deletion Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
DotEnv.Config();
DotEnv.Load();
app.UseDeveloperExceptionPage();
}

Expand Down
13 changes: 6 additions & 7 deletions VideoIndexerApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Azure.Identity" Version="1.1.1" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.4.2" />
<PackageReference Include="Dapr.AspNetCore" Version="0.7.0-preview01" />
<PackageReference Include="dotenv.net" Version="2.1.0" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="3.1.4" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="3.1.4" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="Azure.Identity" Version="1.3.0" />
<PackageReference Include="Azure.Storage.Blobs" Version="12.8.0" />
<PackageReference Include="Dapr.AspNetCore" Version="1.0.0" />
<PackageReference Include="dotenv.net" Version="3.0.0" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="5.0.4" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="5.0.0" />
</ItemGroup>


Expand Down