Skip to content

Commit

Permalink
initial
Browse files Browse the repository at this point in the history
  • Loading branch information
karay committed Jul 30, 2020
0 parents commit 1a16215
Show file tree
Hide file tree
Showing 37 changed files with 3,053 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# build
[Oo]bj/
[Bb]in/

# globs
*.DS_Store
.git
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# build
[Oo]bj/
[Bb]in/

# globs
*.DS_Store
launchSettings.json
Binary file not shown.
990 changes: 990 additions & 0 deletions .vs/MonacoEditorCSharp/config/applicationhost.config

Large diffs are not rendered by default.

Binary file added .vs/MonacoEditorCSharp/v16/.suo
Binary file not shown.
73 changes: 73 additions & 0 deletions Controllers/CompilerController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using Microsoft.AspNetCore.Mvc;
using monacoEditorCSharp.Models;

using System;

namespace monacoEditorCSharp.Controllers
{
[Route("api/compiler")]
public class CompilerController : Controller
{
[HttpGet("get")]
public dynamic Get()
{

var source = new SourceInfo();
return source;

}

[HttpPost("resolve")]
public dynamic Resolve([FromBody]SourceInfo source)
{

try
{

return CSharpScriptCompiler.CompileRos(source);

}
catch (Exception ex)
{
return ex.Message;
//throw;
}
}

[HttpPost("compile")]
public dynamic Compile([FromBody]SourceInfo source)
{

try
{

return CSharpScriptCompiler.Compile(source);

}
catch (Exception ex)
{
return ex.Message;
//throw;
}
}

[HttpPost("formatcode")]
public dynamic formatcode([FromBody]SourceInfo source)
{

try
{

return CSharpScriptCompiler.FormatCode(source);

}
catch (Exception ex)
{
return ex.Message;
//throw;
}
}


}
}
115 changes: 115 additions & 0 deletions DataHelpers/DownloadNugetPackages.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
//using NuGet;
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;

namespace monacoEditorCSharp.DataHelpers
{
public static class DownloadNugetPackages
{
private static string installationDirectory = Directory.GetCurrentDirectory() + "//NugetPackages//packages";

public static List<Assembly> LoadPackages(string packages)
{
List<Assembly> assemblies = new List<Assembly>();
if (!String.IsNullOrWhiteSpace(packages))
{

string[] npackages = packages.Split(';');
foreach (var item in npackages)
{
string downloadItem = "";
string version = "";
if (item.Contains(','))
{
downloadItem = item.Split(',')[0];
version = item.Split(',')[1];
}
else
{
downloadItem = item;

}
var path = $"{installationDirectory}//{downloadItem}";

var files = System.IO.Directory.GetFiles(path, "*.dll", SearchOption.AllDirectories);
foreach (var file in files)
{
try
{
var assembly = Assembly.LoadFile(file);
assemblies.Add(assembly);
}
catch (Exception)
{
// throw
}
}

}
}
return assemblies;
}
public static void DownloadAllPackages(string packages)
{
if (!String.IsNullOrWhiteSpace(packages))
{
string[] npackages = packages.Split(';');
foreach (var item in npackages)
{
if (!String.IsNullOrWhiteSpace(item))
{
string downloadItem = "";
string version = "";
if (item.Contains(','))
{
downloadItem = item.Split(',')[0];
version = item.Split(',')[1];
}
else
{
downloadItem = item;

}
if (!String.IsNullOrWhiteSpace(version))
{
DownloadPackage(downloadItem, version);
}
else
{
DownloadPackage(downloadItem, null);
}
}
}
}
}
public static void DownloadPackage(string packageName, string version)
{
string packageInstallationDirectory = installationDirectory + $"//{packageName}";
if (!System.IO.File.Exists($"{packageInstallationDirectory}//{packageName}.nuget"))
{
if (!System.IO.Directory.Exists(packageInstallationDirectory))
{
System.IO.Directory.CreateDirectory(packageInstallationDirectory);
}
//https://www.nuget.org/api/v2/package/NuGet.Core/2.14.0
string url = "https://packages.nuget.org/api/v2/package/" + $"{packageName}";
if (!String.IsNullOrWhiteSpace(version))
{
url += $"/{version}";
}


var wc = new System.Net.WebClient();
wc.DownloadFile(url, $"{packageInstallationDirectory}//{packageName}.nuget");

System.IO.Compression.ZipFile.ExtractToDirectory($"{packageInstallationDirectory}//{packageName}.nuget", packageInstallationDirectory, true);

}

}


}
}
21 changes: 21 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#
# A simple CSharpCompiler
#
#

FROM microsoft/aspnetcore-build:latest
LABEL author="Karay Akar "
LABEL version=1.0


# Web API listens at http://localhost:5000 in container
EXPOSE 5000

# Copy web app directory to image
RUN mkdir -pv $HOMEDIR
WORKDIR $HOMEDIR
COPY . $HOMEDIR

RUN ["dotnet", "restore"]
RUN ["dotnet", "build"]
CMD ["dotnet", "run"]
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2019 Karay Akar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
Loading

0 comments on commit 1a16215

Please sign in to comment.