Skip to content

Auto reconnect #1

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

Open
wants to merge 6 commits into
base: main
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
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
.DS_Store
bin
obj
node_modules
publish.zip
PseudoEngine2-macOS
PseudoEngine2-CentOS
PseudoEngine2-v0.1-linux
wwwroot/css/output.css
Publish
.vs
20 changes: 20 additions & 0 deletions Controllers/AssemblerController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;

// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace Dev.Ide.Controllers
{
public class AssemblerController : Controller
{
// GET: /<controller>/
public IActionResult Index()
{
return View();
}
}
}

58 changes: 58 additions & 0 deletions Controllers/HomeController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using System.Diagnostics;
using Microsoft.AspNetCore.Mvc;
using Dev.Ide.Models;
using Dev.Ide.Pseudo;
using System.Text;

namespace Dev.Ide.Controllers;

public class HomeController : Controller
{
private readonly ILogger<HomeController> _logger;

public HomeController(ILogger<HomeController> logger)
{
_logger = logger;
}

public IActionResult Index()
{
return View();
}

public IActionResult Terminal()
{
return View();
}

[HttpPost]
public IActionResult Run([FromBody] RunCode run)
{
if(run == null || run.code == null || run.connectionId == null)
{
return BadRequest();
}
_logger.LogInformation(run.code);
PsuedoEngine.ExecuteCode(run);
return Ok();
}

[HttpPost]
public IActionResult Input([FromBody] TermInput input)
{
if (input == null || input.input == null || input.connectionId == null)
{
return BadRequest();
}
PsuedoEngine.Input(input);
_logger.LogInformation(input.input);
return Ok();
}

[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
public IActionResult Error()
{
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
}
}

50 changes: 50 additions & 0 deletions Dev.Ide.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<PropertyGroup>
<ServerGarbageCollection>true</ServerGarbageCollection>
</PropertyGroup>
<PropertyGroup Condition=" '$(RunConfiguration)' == 'Dev.Ide' " />
<Target Name="Tailwind" BeforeTargets="Build">
<Exec Command="npm run input:build" />
</Target>

<ItemGroup>
<None Remove="Hubs\" />
<None Remove="Worker\" />
<None Remove="Pseudo\" />
<None Remove="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" />
<None Remove="Temp\" />
<None Remove="Pseudo\PseudoEngine2-CentOS" />
<None Remove="Views\Assembler\" />
</ItemGroup>
<ItemGroup>
<Folder Include="Hubs\" />
<Folder Include="Worker\" />
<Folder Include="Pseudo\" />
<Folder Include="Temp\" />
<Folder Include="wwwroot\presets\" />
<Folder Include="Views\Assembler\" />
<Folder Include="wwwroot\assembly\" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation" Version="6.0.8" />
</ItemGroup>
<ItemGroup>
<Content Remove="wwwroot\presets\" />
<Content Remove="wwwroot\assembly\" />
</ItemGroup>
<ItemGroup>
<Content Include="Pseudo\PseudoEngine2-macOS">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Pseudo\PseudoEngine2-CentOS">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
</Project>
25 changes: 25 additions & 0 deletions Dev.Ide.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 25.0.1704.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dev.Ide", "Dev.Ide.csproj", "{E42EB305-3D8B-4B3A-ACD0-CC39C52D3A4F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{E42EB305-3D8B-4B3A-ACD0-CC39C52D3A4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E42EB305-3D8B-4B3A-ACD0-CC39C52D3A4F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E42EB305-3D8B-4B3A-ACD0-CC39C52D3A4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E42EB305-3D8B-4B3A-ACD0-CC39C52D3A4F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {893B1154-AF63-474E-80FE-BF346A7322BB}
EndGlobalSection
EndGlobal
24 changes: 24 additions & 0 deletions Hubs/TerminalHub.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using Microsoft.AspNetCore.SignalR;

namespace Dev.Ide.Hubs
{
public class TerminalHub : Hub
{
public async Task SendMessage(string user, string message)
{
await Clients.All.SendAsync("ReceiveMessage", user, message);
}

public async Task SendOutput(string connectionID, string output)
{
await Clients.Client(connectionID).SendAsync("Output", output);
}

public async Task Input(string connectionID, string output)
{
await Clients.Client(connectionID).SendAsync("Output", output);
}
}
}

9 changes: 9 additions & 0 deletions Models/ErrorViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Dev.Ide.Models;

public class ErrorViewModel
{
public string? RequestId { get; set; }

public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
}

10 changes: 10 additions & 0 deletions Models/RunCode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
namespace Dev.Ide.Models
{
public class RunCode
{
public string code { get; set; }
public string connectionId { get; set; }
}
}

10 changes: 10 additions & 0 deletions Models/TermInput.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System;
namespace Dev.Ide.Models
{
public class TermInput
{
public string input { get; set; }
public string connectionId { get; set; }
}
}

69 changes: 69 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System.Net;
using System.Reflection;
using Dev.Ide.Hubs;
using Microsoft.Extensions.DependencyInjection;
using Dev.Ide.Worker;
using static System.Net.WebRequestMethods;

Directory.CreateDirectory(System.IO.Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + "/Buffer");

var MyAllowSpecificOrigins = "_myAllowSpecificOrigins";

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews().AddRazorRuntimeCompilation();
builder.Services.AddSignalR();
builder.Services.AddHostedService<DbHostedService>();

builder.Services.AddCors(options =>
{
options.AddPolicy(name: MyAllowSpecificOrigins,
policy =>
{
policy.WithOrigins("https://oj.tech4good.tech/",
"https://oj-api.tech4good.tech/").AllowAnyHeader().AllowAnyMethod().WithMethods("GET", "POST")
.AllowCredentials().SetIsOriginAllowed(_ => true);
});
});

if (builder.Environment.IsDevelopment())
{

}
else
{
builder.WebHost.UseKestrel(options =>
{
options.Listen(IPAddress.Any, 10234);
});
}

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
app.UseExceptionHandler("/Home/Error");
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
app.UseHsts();
}


app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseCors(MyAllowSpecificOrigins);

app.UseAuthorization();

app.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");

app.MapHub<TerminalHub>("/terminalHub");

app.Run();

13 changes: 13 additions & 0 deletions Properties/PublishProfiles/FolderProfile.pubxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<WebPublishMethod>FileSystem</WebPublishMethod>
<LastUsedBuildConfiguration>Release</LastUsedBuildConfiguration>
<LastUsedPlatform>AnyCPU</LastUsedPlatform>
<publishUrl>bin/Release/net6.0/publish</publishUrl>
<DeleteExistingFiles>false</DeleteExistingFiles>
<TargetFramework>net6.0</TargetFramework>
<SelfContained>false</SelfContained>
<_IsPortable>true</_IsPortable>
</PropertyGroup>
</Project>
27 changes: 27 additions & 0 deletions Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:52349",
"sslPort": 44370
}
},
"profiles": {
"Dev.Ide": {
"commandName": "Project",
"launchBrowser": true,
"applicationUrl": "http://localhost:29373",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
Loading