Skip to content

Commit

Permalink
fix async controller error, target C# 9
Browse files Browse the repository at this point in the history
  • Loading branch information
kentico-ericd committed Jan 16, 2024
1 parent 42dd6e5 commit 268dfaf
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 34 deletions.
1 change: 1 addition & 0 deletions KenticoInspector.Actions/KenticoInspector.Actions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>9.0</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>

<LangVersion>7.1</LangVersion>
<LangVersion>9.0</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion KenticoInspector.Core/KenticoInspector.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>7.1</LangVersion>
<LangVersion>9.0</LangVersion>
<Version />
<PackageVersion />
<AssemblyVersion />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>

<LangVersion>9.0</LangVersion>
<IsPackable>false</IsPackable>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>7.1</LangVersion>
<LangVersion>9.0</LangVersion>
<Version />
<PackageVersion />
<AssemblyVersion />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>

<IsPackable>false</IsPackable>

<LangVersion>7.1</LangVersion>
<LangVersion>9.0</LangVersion>
<Version />
<PackageVersion />
<AssemblyVersion />
Expand Down
2 changes: 1 addition & 1 deletion KenticoInspector.Reports/KenticoInspector.Reports.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<LangVersion>7.1</LangVersion>
<LangVersion>9.0</LangVersion>
<Version />
<PackageVersion />
<AssemblyVersion />
Expand Down
16 changes: 7 additions & 9 deletions KenticoInspector.WebApplication/Controllers/ActionsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;

using KenticoInspector.Core.Models;
using KenticoInspector.Core.Modules;
Expand All @@ -23,20 +24,17 @@ public ActionsController(IModuleService moduleService)
}

[HttpGet("{instanceGuid}")]
public ActionResult<IEnumerable<IAction>> Get(Guid instanceGuid)
public Task<IEnumerable<IAction>> Get(Guid instanceGuid)
{
return Ok(moduleService.GetActions(instanceGuid));
return Task.FromResult(moduleService.GetActions(instanceGuid));
}

// POST api/values
[HttpPost("{codename}/execute/{instanceGuid}")]
public ActionResult<ActionResults> Excecute(string codename, Guid instanceGuid)
public async Task<ActionResults> Excecute(string codename, Guid instanceGuid)
{
using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
{
var optionsJson = reader.ReadToEnd();
return moduleService.ExecuteAction(codename, instanceGuid, optionsJson);
}
using StreamReader reader = new(Request.Body, Encoding.UTF8);
var optionsJson = await reader.ReadToEndAsync();
return moduleService.ExecuteAction(codename, instanceGuid, optionsJson);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

using KenticoInspector.Core.Models;
using KenticoInspector.Core.Services.Interfaces;
Expand All @@ -21,9 +22,9 @@ public InstancesController(IInstanceService instanceService)
}

[HttpGet("details/{instanceGuid}")]
public ActionResult<InstanceDetails> Details(Guid instanceGuid)
public Task<InstanceDetails> Details(Guid instanceGuid)
{
return _instanceService.GetInstanceDetails(instanceGuid);
return Task.FromResult(_instanceService.GetInstanceDetails(instanceGuid));
}

[HttpDelete("{instanceGuid}")]
Expand All @@ -33,22 +34,22 @@ public void Delete(Guid instanceGuid)
}

[HttpGet]
public ActionResult<IEnumerable<Instance>> Get()
public Task<List<Instance>> Get()
{
var instances = _instanceService.GetInstances();
return instances.ToList();
return Task.FromResult(instances.ToList());
}

[HttpGet("{instanceGuid}")]
public ActionResult<Instance> Get(Guid instanceGuid)
public Task<Instance> Get(Guid instanceGuid)
{
return _instanceService.GetInstance(instanceGuid);
return Task.FromResult(_instanceService.GetInstance(instanceGuid));
}

[HttpPost]
public Instance Post([FromBody] Instance instance)
public Task<Instance> Post([FromBody] Instance instance)
{
return _instanceService.UpsertInstance(instance);
return Task.FromResult(_instanceService.UpsertInstance(instance));
}
}
}
10 changes: 5 additions & 5 deletions KenticoInspector.WebApplication/Controllers/ReportsController.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;

using KenticoInspector.Core.Models;
using KenticoInspector.Core.Modules;
Expand All @@ -21,16 +22,15 @@ public ReportsController(IModuleService moduleService)
}

[HttpGet("{instanceGuid}")]
public ActionResult<IEnumerable<IReport>> Get(Guid instanceGuid)
public Task<IEnumerable<IReport>> Get(Guid instanceGuid)
{
return Ok(moduleService.GetReports(instanceGuid));
return Task.FromResult(moduleService.GetReports(instanceGuid));
}

// POST api/values
[HttpGet("{codename}/results/{instanceGuid}")]
public ActionResult<ReportResults> Get(string codename, Guid instanceGuid)
public Task<ReportResults> Get(string codename, Guid instanceGuid)
{
return moduleService.GetReportResults(codename, instanceGuid);
return Task.FromResult(moduleService.GetReportResults(codename, instanceGuid));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net8.0</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
<StartupObject></StartupObject>
<LangVersion>7.1</LangVersion>
<LangVersion>9.0</LangVersion>
<Version />
<PackageVersion />
<AssemblyVersion />
Expand Down
4 changes: 3 additions & 1 deletion KenticoInspector.WebApplication/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

using System;

namespace KenticoInspector.WebApplication
Expand Down Expand Up @@ -50,7 +52,7 @@ private IServiceProvider ConfigureAutofac(IServiceCollection services)
return new AutofacServiceProvider(container);
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
Expand Down

0 comments on commit 268dfaf

Please sign in to comment.