Skip to content

Commit

Permalink
Release new version - a release candidate #80
Browse files Browse the repository at this point in the history
- improved errors handling mechanism
  • Loading branch information
mpostol committed Apr 19, 2022
1 parent 67a9278 commit a64b8b1
Showing 1 changed file with 36 additions and 27 deletions.
63 changes: 36 additions & 27 deletions ModelCompilerUI/EntryPoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,53 +47,62 @@ private static void Main(string[] args)
private void MainExecute(string[] args)
{
Task heartbeatTask = Heartbeat();
Run(args).Wait();
ProcessingTask(args).Wait();
Running = false;
heartbeatTask.Wait();
}

internal async Task Run(string[] args)
internal async Task ProcessingTask(string[] args)
{
await Task.Run(() => Processing(args));
}

private void Processing(string[] args)
{
try
{
await Task.Run(() => Processing(args));
ParserResult<object> result = Parser.Default.ParseArguments<CompilerOptions, DotNetStackOptions, UnitsOptions, UpdateHeadersOptions>(args);
CompilerOptions compilerOptions = null;
DotNetStackOptions dotNetStackOptions = null;
UnitsOptions unitsOptions = null;
UpdateHeadersOptions updateHeadersOptions = null;
IEnumerable<Error> error = null;
result.WithParsed<CompilerOptions>(options => compilerOptions = options).
WithParsed<DotNetStackOptions>(options => dotNetStackOptions = options).
WithParsed<UnitsOptions>(options => unitsOptions = options).
WithParsed<UpdateHeadersOptions>(options => updateHeadersOptions = options).
WithNotParsed(errors => error = errors);
Compile(compilerOptions);
GenerateStack(dotNetStackOptions);
Units(unitsOptions);
UpdateHeaders(updateHeadersOptions);
if (error != null)
throw new InvalidOperationException(error.ToString());
}
catch (Exception ex)
{
string errorMessage = $"Processing stopped by the exception {ex.GetType().Name}: {ex.Message}";
string errorMessage = $"Processing stopped by the exception {ex.GetType().Name}: {ex.Message} {Environment.NewLine}{ex.StackTrace}";
Console.WriteLine(errorMessage);
Log.WriteTraceMessage(TraceMessage.BuildErrorTraceMessage(BuildError.NonCategorized, errorMessage), 552021345);
}
}

private void Processing(string[] args)
{
ParserResult<object> result = Parser.Default.ParseArguments<CompilerOptions, DotNetStackOptions, UnitsOptions, UpdateHeadersOptions>(args);
CompilerOptions compilerOptions = null;
DotNetStackOptions dotNetStackOptions = null;
UnitsOptions unitsOptions = null;
UpdateHeadersOptions updateHeadersOptions = null;
IEnumerable<Error> error = null;
result.WithParsed<CompilerOptions>(options => compilerOptions = options).
WithParsed<DotNetStackOptions>(options => dotNetStackOptions = options).
WithParsed<UnitsOptions>(options => unitsOptions = options).
WithParsed<UpdateHeadersOptions>(options => updateHeadersOptions = options).
WithNotParsed(errors => error = errors);
Compile(compilerOptions);
GenerateStack(dotNetStackOptions);
Units(unitsOptions);
UpdateHeaders(updateHeadersOptions);
if (error != null)
throw new InvalidOperationException(error.ToString());
}

private void Compile(CompilerOptions options)
{
if (options == null)
return;
Log.WriteTraceMessage(TraceMessage.DiagnosticTraceMessage($"Started {nameof(Compile)} with parameters {options}"), 499457465);
options.ValidateOptionsConsistency();
ModelDesignCompiler.BuildModel(options);
try
{
options.ValidateOptionsConsistency();
ModelDesignCompiler.BuildModel(options);
}
catch (Exception ex)
{
string errorMessage = $"Compilation ended with error {ex.GetType().Name}: {ex.Message} {Environment.NewLine}{ex.StackTrace}";
Console.WriteLine(errorMessage);
Log.WriteTraceMessage(TraceMessage.BuildErrorTraceMessage(BuildError.NonCategorized, errorMessage), 552021345);
}
}

private static void GenerateStack(DotNetStackOptions options)
Expand Down

0 comments on commit a64b8b1

Please sign in to comment.