Skip to content

Commit

Permalink
Cleanup, convert ocntrol library to standard/core
Browse files Browse the repository at this point in the history
  • Loading branch information
xxbiohazrdxx committed Dec 6, 2021
1 parent ffcd38c commit 5d47b50
Show file tree
Hide file tree
Showing 103 changed files with 2,946 additions and 203 deletions.
9 changes: 4 additions & 5 deletions AmpAPI/AmpAPI.csproj
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<LangVersion>8.0</LangVersion>
</PropertyGroup>

<ItemGroup>
<Folder Include="wwwroot\" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" />
<PackageReference Include="Microsoft.AspNetCore.Razor.Design" Version="2.1.2" PrivateAssets="All" />
<PackageReference Include="Microsoft.AspNetCore.SignalR" Version="1.1.0" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="2.1.1" />
<PackageReference Include="System.IO.Ports" Version="4.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\MPRSGxZ\MPRSGxZ.csproj" />
<ProjectReference Include="..\NewLib\MPRSGxZ.csproj" />
</ItemGroup>

</Project>
14 changes: 14 additions & 0 deletions AmpAPI/Hubs/AmpHub.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using Microsoft.AspNetCore.SignalR;
using System.Threading.Tasks;
using AmpAPI.Models;

namespace AmpApi.Hubs
{
public class AmpHub : Hub
{
public async Task SendZoneUpdate(ZoneModel Zone)
{
await Clients.All.SendAsync("ReceiveZoneUpdate", Zone);
}
}
}
14 changes: 11 additions & 3 deletions AmpAPI/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.SignalR;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;

namespace AmpAPI
{
Expand All @@ -23,11 +25,12 @@ public void ConfigureServices(IServiceCollection services)
services.Configure<AmplifierStackSettings>(Configuration.GetSection("AmplifierStackSettings"));
services.AddSingleton<IAmplifierService, AmplifierService>();
//services.AddSingleton<IConfiguration>(Configuration);
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddRazorPages();
//services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_3_0);
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
public void Configure(IApplicationBuilder app, IHostEnvironment env)
{
if (env.IsDevelopment())
{
Expand All @@ -39,7 +42,12 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env)
}

app.UseHttpsRedirection();
app.UseMvc();
app.UseRouting();
//app.UseAuthorization();
app.UseEndpoints(endpoints =>
{
endpoints.MapRazorPages();
});
}
}
}
6 changes: 0 additions & 6 deletions AmpMonitor/AmpMonitor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\MPRSGxZ\MPRSGxZ.csproj">
<Project>{9f947c76-0ff2-4bbf-bd94-5afe9d0fa8a4}</Project>
<Name>MPRSGxZ</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Expand Down
7 changes: 7 additions & 0 deletions AmpWeb/AmpWeb.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,14 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="3.0.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="3.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.9.5" />
<PackageReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Design" Version="3.0.0" />
</ItemGroup>

<ItemGroup>
Expand Down
57 changes: 57 additions & 0 deletions AmpWeb/Controllers/SettingsController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
using AmpWeb.Services;
using AmpWeb.Settings;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Options;
using MPRSGxZ.Hardware;
using System.Collections.Generic;


namespace AmpWeb.Controllers
{
[Route("api/[controller]")]
[ApiController]
public class SettingsController : ControllerBase
{
private AmplifierStackSettings Settings;
private IAmplifierService AmplifierService;

public SettingsController(IOptions<AmplifierStackSettings> Settings, IAmplifierService AmplifierService)
{
this.Settings = Settings.Value;
this.AmplifierService = AmplifierService;
}

// GET: api/Settings
[HttpGet]
[ProducesResponseType(StatusCodes.Status200OK)]
public IActionResult Get()
{
return Ok(Settings);
}

// POST: api/Settings
[HttpPost]
[ProducesResponseType(StatusCodes.Status405MethodNotAllowed)]
public IActionResult Post([FromBody] string value)
{
return StatusCode(StatusCodes.Status405MethodNotAllowed);
}

// PUT: api/Settings/5
[HttpPut]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public void Put([FromBody] string value)
{
}

// DELETE: api/ApiWithActions/5
[HttpDelete("{id}")]
[ProducesResponseType(StatusCodes.Status405MethodNotAllowed)]
public IActionResult Delete(int id)
{
return StatusCode(StatusCodes.Status405MethodNotAllowed);
}
}
}
5 changes: 0 additions & 5 deletions AmpWeb/Pages/Index.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,3 @@

</body>
</html>

@page
@model AmpWeb.Pages.IndexModel
@{
}
33 changes: 26 additions & 7 deletions AmpWeb/Services/AmplifierService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,43 @@ public Source[] Sources
return AmplifierMiddleware.Sources;
}
}
private AmplifierStackSettings Settings;
private AmplifierStackSettings _Settings;

public AmplifierService(IOptions<AmplifierStackSettings> Settings)
{
this.Settings = Settings.Value;
_Settings = Settings.Value;

if (this.Settings.PortType == ConnectionType.Virtual)
if (_Settings.PortType == ConnectionType.Virtual)
{
AmplifierMiddleware = new AmplifierStack(this.Settings.PollingFrequency, this.Settings.AmplifierCount);
AmplifierMiddleware = new AmplifierStack(_Settings.PollingFrequency, _Settings.AmplifierCount);
}
else if (this.Settings.PortType == ConnectionType.Serial)
else if (_Settings.PortType == ConnectionType.Serial)
{
AmplifierMiddleware = new AmplifierStack(this.Settings.PortAddress, this.Settings.PollingFrequency, this.Settings.AmplifierCount);
AmplifierMiddleware = new AmplifierStack(_Settings.PortAddress, _Settings.PollingFrequency, _Settings.AmplifierCount);
}
else
else if (_Settings.PortType == ConnectionType.IP)
{
throw new NotImplementedException();
}
else
{
throw new InvalidOperationException();
}

for (int i = 0; i < 6; i++)
{
AmplifierMiddleware.Sources[i].Enabled = _Settings.Sources[i].Enabled;
AmplifierMiddleware.Sources[i].Name = _Settings.Sources[i].Name;
}

for (int i = 0; i < _Settings.AmplifierCount; i++)
{
for (int j = 0; j < 6; j++)
{
AmplifierMiddleware.Amplifiers[i].Zones[j].Enabled = _Settings.Amplifiers[i].Zones[j].Enabled;
AmplifierMiddleware.Amplifiers[i].Zones[j].Name = _Settings.Amplifiers[i].Zones[j].Name;
}
}

AmplifierMiddleware.Open();
}
Expand Down
7 changes: 6 additions & 1 deletion AmpWeb/Settings/ApplicationSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ public class AmplifierStackSettings
public string PortAddress { get; set; }
public int PollingFrequency { get; set; }
public int AmplifierCount { get; set; }
public ZoneSettings[] Zones { get; set; }
public AmplifierSettings[] Amplifiers { get; set; }
public SourceSettings[] Sources { get; set; }
}

public class AmplifierSettings
{
public ZoneSettings[] Zones { get; set; }
}

public class ZoneSettings
{
public string Name { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions AmpWeb/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
app.UseEndpoints(endpoints =>
{
endpoints.MapHub<AmpHub>("/amp");

endpoints.MapGet("/", async context =>
{
await context.Response.WriteAsync("Hello World!");
});

endpoints.MapControllerRoute("api", "{controller=Amplifier}/{action=Get}/{id?}");
});
}
Expand Down
Loading

0 comments on commit 5d47b50

Please sign in to comment.