Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
# Conflicts:
#	.github/workflows/contrast_security_app.yaml
  • Loading branch information
jmecosta committed Sep 3, 2024
2 parents 271acfe + 5d6e2e7 commit b3b3297
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/contrast_security_app.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# DISCLAIMER: This workflow file has been auto-generated and committed to the repo by the GitHub App from Contrast Security.
# Manual edits to this file could cause the integration to produce unexpected behavior or break.
# Version: 1.0.0
# Last updated: 2024-08-29T13:59:40.264448756Z
# Last updated: 2024-08-29T13:35:04.300742640Z
name: Contrast Security App Workflow
on:
workflow_dispatch:
Expand Down
16 changes: 6 additions & 10 deletions TeklaGrpcApiService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ namespace TeklaGrpcApiService

class Program
{

static int RunAndReturnExitCode(Options options)
{


using ILoggerFactory loggerFactory = LoggerFactory.Create(builder =>
builder.AddSimpleConsole(options =>
{
Expand All @@ -32,8 +29,6 @@ static int RunAndReturnExitCode(Options options)
options.TimestampFormat = "HH:mm:ss ";
}));


ILogger logger = loggerFactory.CreateLogger("TeklaGrpcApiService");
Trace.Listeners.Add(new TextWriterTraceListener(options.Log));
Trace.AutoFlush = true; // Ensure each write is flushed immediately

Expand All @@ -47,20 +42,21 @@ static int RunAndReturnExitCode(Options options)
try
{
var modelInfo = new Model().GetInfo();
logger.LogInformation($"{modelInfo.ModelName} : {modelInfo.ModelPath}");
Trace.WriteLine($"{modelInfo.ModelName} : {modelInfo.ModelPath}");
return 0;
}
catch (Exception ex)
{
logger.LogInformation($"Failed to connect to TS: {ex.Message}");
Trace.WriteLine($"Failed to connect to TS: {ex.Message}");
return 1;
}
}

var sessionName = Environment.GetEnvironmentVariable("SESSIONNAME");

logger.LogInformation($"Tekla Api Server Requested to start with Port : {options.Port} => Log: {options.Log}");
Trace.WriteLine($"Tekla Api Server Requested to start with Port : {options.Port} => Log: {options.Log} => SESSIONNAME = '{sessionName}'" );

var apiService = new TeklaGrpcApiService(logger);
var apiService = new TeklaGrpcApiService();

Server server = new()
{
Expand All @@ -71,7 +67,7 @@ static int RunAndReturnExitCode(Options options)
};
apiService.Server = server;
server.Start();
logger.LogInformation($"server listening on port {options.Port}");
Trace.WriteLine($"server listening on port {options.Port}");

// Block the main thread until the server is requested to shut down
WaitForShutdownAsync(server).Wait();
Expand Down
17 changes: 8 additions & 9 deletions TeklaGrpcApiService/Services/TeklaGrpcApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,45 +12,44 @@

public class TeklaGrpcApiService : TeklaServiceApi.TeklaServiceApiBase
{
private readonly ILogger logger;

public TeklaGrpcApiService(ILogger logger)
public TeklaGrpcApiService()
{
this.logger = logger;
}

public Server? Server { get; set; }

public override Task<StringReply> Ping(StringRequest request, ServerCallContext context)
{
logger.LogInformation($"Ping: {request.Name}");
Trace.WriteLine($"Ping: {request.Name}");
return System.Threading.Tasks.Task.FromResult(new StringReply { Message = $"Hello, {request.Name} im node: {Process.GetCurrentProcess().Id}" });
}

public override Task<StringReply> GetOpenModel(StringRequest request, ServerCallContext context)
{
logger.LogInformation($"GetOpenModel: {request.Name}");
Trace.WriteLine($"GetOpenModel: {request.Name}");
try
{
var modelInfo = new Model().GetInfo();
Trace.WriteLine($"GetOpenModel Ok: {modelInfo.ModelName} : {modelInfo.ModelPath}");
return System.Threading.Tasks.Task.FromResult(new StringReply { Message = $"{modelInfo.ModelName} : {modelInfo.ModelPath}" });
}
catch (Exception)
catch (Exception ex)
{
Trace.WriteLine($"GetOpenModel Failed: {ex.Message}");
return System.Threading.Tasks.Task.FromResult(new StringReply { Message = $"Tekla Structures not running" });
}
}

public override async Task<StringReply> StopServer(StringRequest request, ServerCallContext context)
{
logger.LogInformation("Shutdown request received.");
Trace.WriteLine("Shutdown request received.");
if (Server != null)
{
await Server.ShutdownAsync();
return new StringReply { Message = "Server is shutting down." };
}

logger.LogInformation("Shutdown not handled, Server not configued correctly");
Trace.WriteLine("Shutdown not handled, Server not configued correctly");
return new StringReply { Message = "Server cannot be shut down." };
}
}
Expand Down

0 comments on commit b3b3297

Please sign in to comment.