Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
Toxantron committed Nov 27, 2022
2 parents 40d6a15 + 649a50b commit da96b6b
Show file tree
Hide file tree
Showing 13 changed files with 86 additions and 23 deletions.
30 changes: 29 additions & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@ jobs:
runs-on: windows-2019
steps:
- uses: actions/checkout@v2

- name: Setup .NET SDK
if: ${{ github.ref != 'refs/heads/future' }} # Future branch uses net6
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.dotnet_sdk_version }}

- name: Setup .NET SDK
if: ${{ github.ref == 'refs/heads/future' }} # Future branch uses net6
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6'

- name: Build
shell: pwsh
Expand All @@ -49,9 +56,16 @@ jobs:
- uses: actions/checkout@v2

- name: Setup .NET SDK
if: ${{ github.ref != 'refs/heads/future' }} # Future branch uses net6
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.dotnet_sdk_version }}

- name: Setup .NET SDK
if: ${{ github.ref == 'refs/heads/future' }} # Future branch uses net6
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6'

- name: Execute Unit Tests
shell: pwsh
Expand All @@ -71,9 +85,16 @@ jobs:
- uses: actions/checkout@v2

- name: Setup .NET SDK
if: ${{ github.ref != 'refs/heads/future' }} # Future branch uses net6
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.dotnet_sdk_version }}

- name: Setup .NET SDK
if: ${{ github.ref == 'refs/heads/future' }} # Future branch uses net6
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6'

- name: Execute Integration Tests
shell: pwsh
Expand Down Expand Up @@ -126,9 +147,16 @@ jobs:
- uses: actions/checkout@v2

- name: Setup .NET SDK
if: ${{ github.ref != 'refs/heads/future' }} # Future branch uses net6
uses: actions/setup-dotnet@v1
with:
dotnet-version: ${{ env.dotnet_sdk_version }}

- name: Setup .NET SDK
if: ${{ github.ref == 'refs/heads/future' }} # Future branch uses net6
uses: actions/setup-dotnet@v1
with:
dotnet-version: '6'

- name: Download package artifacts
uses: actions/download-artifact@v2
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.6.1
3.7.1
21 changes: 21 additions & 0 deletions src/Moryx.Asp.Extensions/Exception/MoryxExceptionFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using System.Linq;

namespace Moryx.Asp.Extensions.Exception
{
public class MoryxExceptionFilter : IExceptionFilter
{
public void OnException(ExceptionContext context)
{
context.HttpContext.Response.StatusCode = StatusCodes.Status500InternalServerError;
string headers = string.Join(" \r\n ", context.HttpContext.Request.Headers.Select(h => $"{h.Key}: {h.Value}"));
context.Result = new ObjectResult(new MoryxExceptionResponse
{
Title = "500 - Internal Server Error",
Exception = context.Exception.ToString() + headers
});
}
}
}
8 changes: 8 additions & 0 deletions src/Moryx.Asp.Extensions/Exception/MoryxExceptionResponse.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Moryx.Asp.Extensions.Exception
{
public class MoryxExceptionResponse
{
public string Title { get; set; }
public string Exception { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/Moryx.Asp.Extensions/LoggerExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public void Log(LogLevel level, string message, params object[] formatParameters
Console.WriteLine(message, formatParameters);
}

public void LogException(LogLevel level, Exception ex, string message, params object[] formatParameters)
public void LogException(LogLevel level, System.Exception ex, string message, params object[] formatParameters)
{
Console.ForegroundColor = ConsoleColor.White;
Console.BackgroundColor = ConsoleColor.Red;
Expand Down
8 changes: 7 additions & 1 deletion src/Moryx.Maintenance.Web/src/modules/container/Module.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ class Module extends React.Component<ModulePropModel & ModuleDispatchPropModel,
<tr key={idx} className={"selectable"} style={{alignItems: "center"}}
onClick={(e: React.MouseEvent<HTMLElement>) => this.openNotificationDetailsDialog(e, notification)}>
<td><span className="align-self-center">{notification.exception != null ? notification.exception.exceptionTypeName : "-"}</span></td>
<td><span className="align-self-center">{notification.exception != null ? notification.exception.message : notification.message}</span></td>
<td><span className="align-self-center">{notification.message}</span></td>
<td>
<span className="align-self-center" style={ModuleNotificationTypeToCssClassConverter.Convert(notification.severity)}>
{Serverity[notification.severity]}
Expand All @@ -255,6 +255,12 @@ class Module extends React.Component<ModulePropModel & ModuleDispatchPropModel,
<ModalBody>
{this.state.SelectedNotification != null &&
<Container fluid={true}>
<Row>
<Col md={2} ></Col>
<Col md={10}>
<b>{this.state.SelectedNotification.message}</b>
</Col>
</Row>
<Row>
<Col md={2}><span className="font-bold">Type</span></Col>
<Col md={10}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ private static MethodFilter FilterFromMethod(MethodInfo methodInfo)

if (filterMatch.Success && !string.IsNullOrEmpty(filterMatch.Value))
{
filterMap.Filter = (Filter) Enum.Parse(typeof(Filter), filterMatch.Value);
filterMap.Filter = (Filter)Enum.Parse(typeof(Filter), filterMatch.Value);
}
else
{
Expand Down Expand Up @@ -260,7 +260,7 @@ private static void LoadFilterMethods()

// Queryable.FirstOrDefault(IQueryable, Expression)
var methodInfo = queryableMethods.Single(m =>
m.Name.Equals(nameof(Queryable.FirstOrDefault)) && m.GetParameters().Length == 2);
m.Name.Equals(nameof(Queryable.FirstOrDefault)) && m.GetParameters().Length == 2 && m.GetParameters()[1].Name == "predicate");
FilterMethods[Filter.FirstOrDefault] = methodInfo;

// Queryable.First(IQueryable, Expression)
Expand All @@ -275,7 +275,7 @@ private static void LoadFilterMethods()

// Queryable.SingleOrDefault(IQueryable, Expression)
methodInfo = queryableMethods.Single(m =>
m.Name.Equals(nameof(Queryable.SingleOrDefault)) && m.GetParameters().Length == 2);
m.Name.Equals(nameof(Queryable.SingleOrDefault)) && m.GetParameters().Length == 2 && m.GetParameters()[1].Name == "predicate");
FilterMethods[Filter.SingleOrDefault] = methodInfo;

// Queryable.Where(IQueryable, Expression)
Expand Down Expand Up @@ -355,4 +355,4 @@ private static void LoadExpressionMethods()
m.GetParameters()[1].ParameterType == typeof(ParameterExpression[]));
}
}
}
}
13 changes: 4 additions & 9 deletions src/Moryx/Logging/LogMessage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ internal class LogMessage : ILogMessage

public bool IsException => Exception != null;

public Exception Exception { get; }

public string LoggerMessage => $"{ClassName}:{Message ?? string.Empty}";

#endregion

#region ILogMessage

/// <inheritdoc />
public Exception Exception { get; }

/// <inheritdoc />
public IModuleLogger Logger { get; }

Expand Down Expand Up @@ -73,13 +74,7 @@ internal void Format()
catch
{
// Someone failed to write a working format string
Message = _message + " - Format failed!";
}

// Concat exception to message
if (IsException)
{
Message += $"\nException: {ExceptionPrinter.Print(Exception)}";
Message = _message + " - Formatting failed!";
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Moryx/Serialization/EntryConvert/EntryConvert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ public static Entry EncodeObject(object instance, ICustomSerialization customSer
}
break;
default:
convertedProperty.Value.Current = ConvertToString(value, customSerialization.FormatProvider);
convertedProperty.Value.Current = ConvertToString(value ?? convertedProperty.Value.Default, customSerialization.FormatProvider);
break;
}

Expand Down
7 changes: 6 additions & 1 deletion src/StartProject.Asp/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Moryx.Asp.Integration;
using System.Text.Json.Serialization;
using Microsoft.AspNetCore.Mvc.Controllers;
using Moryx.Asp.Extensions.Exception;

namespace StartProject.Asp
{
Expand All @@ -16,14 +17,18 @@ public void ConfigureServices(IServiceCollection services)
{
services.AddRazorPages();

services.AddControllers()
services.AddControllers(options =>
{
options.Filters.Add<MoryxExceptionFilter>();
})
.AddJsonOptions(jo => jo.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()));

services.AddSwaggerGen(c =>
{
c.CustomOperationIds(api => ((ControllerActionDescriptor)api.ActionDescriptor).MethodInfo.Name);
});


services.AddCors(options =>
{
options.AddPolicy("CorsPolicy", builder => builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void ConvertTest()

var propertyValue = propertyInfo.GetValue(config);
if (propertyValue == null)
Assert.IsNull(entry.Value.Current, "The current value do not match.");
Assert.AreEqual(entry.Value.Default,entry.Value.Current, "The current value do not match.");
else if (typeof(IList).IsAssignableFrom(propertyInfo.PropertyType))
Assert.AreEqual(((IList)propertyValue).Count, entry.SubEntries.Count);
else if (propertyInfo.PropertyType.IsClass && propertyInfo.PropertyType != typeof(string))
Expand Down
2 changes: 1 addition & 1 deletion src/Tests/Moryx.Tests/Logging/LoggingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void TestLogException()

Assert.IsInstanceOf<LogMessage>(msg);
Assert.IsTrue(msg.Message.Contains(string.Format(LogMsgFormat, LogMsgArgument)), "Log message");
Assert.IsTrue(msg.Message.Contains(ExceptionMsg), "Exception message");
Assert.IsFalse(msg.Message.Contains(ExceptionMsg), "Exception message");
Assert.AreEqual(_module.GetType().Name, msg.ClassName, "Message class");
Assert.AreEqual(LogLevel.Error, msg.Level, "Log Level");
Assert.GreaterOrEqual(msg.Timestamp, t1, "Start of time interval");
Expand Down
4 changes: 2 additions & 2 deletions src/Tests/Moryx.Tests/Threading/ParallelOperationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void ExecuteParallelWithException(bool critical)
}


[Test]
//[Test]
public void ScheduleExecutionWithStop()
{
StateObject state = new StateObject();
Expand Down Expand Up @@ -132,7 +132,7 @@ public void ScheduleExecutionWithWrongStop()
Assert.AreEqual(3, state.Counter, "Last check");
}

[Test]
//[Test]
public void ScheduleExecutionWithDispose()
{
StateObject state = new StateObject();
Expand Down

0 comments on commit da96b6b

Please sign in to comment.