Skip to content

Commit

Permalink
mazak: initial main program for the proxy
Browse files Browse the repository at this point in the history
  • Loading branch information
wuzzeb committed Sep 5, 2024
1 parent 4ebc691 commit 605d192
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 1 deletion.
52 changes: 52 additions & 0 deletions server/machines/mazak-proxy/Main.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
using MazakMachineInterface;

namespace BlackMaple.FMSInsight.Mazak.Proxy;

public class ProxyService : System.ServiceProcess.ServiceBase
{
private ICurrentLoadActions _load;
private IMazakDB _db;
private IHttpServer _server;

public static void Main()
{
System.ServiceProcess.ServiceBase.Run(new ProxyService());
}

protected override void OnStart(string[] args)
{
var cfg = new MazakConfig()
{
DBType = MazakDbType.MazakWeb,
SQLConnectionString = "Data Source=.;Initial Catalog=SeedTacticsMazak;Integrated Security=True",
LogCSVPath = @"C:\ProgramData\SeedTactics\Mazak\Logs",
LoadCSVPath = @"C:\ProgramData\SeedTactics\Mazak\Load",
};
_load = new LoadOperationsFromFile(cfg);
_db = new OpenDatabaseKitDB(cfg, _load);
_server = new HttpServer("http://*:5000/");

_server.AddLoadingHandler("/all-data", _db.LoadAllData);
_server.AddPostHandler<string, MazakAllDataAndLogs>("/all-data-and-logs", _db.LoadAllDataAndLogs);
_server.AddLoadingHandler("/programs", _db.LoadPrograms);
_server.AddLoadingHandler("/tools", _db.LoadTools);
_server.AddPostHandler<MazakWriteData, bool>(
"/save",
w =>
{
_db.Save(w);
return true;
}
);

_server.Start();
}

protected override void OnStop()
{
_server?.Dispose();
_load = null;
_db = null;
_server = null;
}
}
2 changes: 1 addition & 1 deletion server/machines/mazak-proxy/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace BlackMaple.FMSInsight.Mazak.Proxy
using System.Net;
using System.Threading;

public interface IHttpServer
public interface IHttpServer : IDisposable
{
void AddLoadingHandler<T>(string path, Func<T> handler);
void AddPostHandler<T, R>(string path, Func<T, R> handler);
Expand Down
1 change: 1 addition & 0 deletions server/machines/mazak-proxy/mazak-proxy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<Compile Include="../mazak/db/OpenDatabaseKit.cs" />

<Reference Include="System.ServiceModel.Web" />
<Reference Include="System.ServiceProcess" />
</ItemGroup>

</Project>

0 comments on commit 605d192

Please sign in to comment.