Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NEW-FEATURE] Extend Diagnostics View in Blazor #647

Draft
wants to merge 14 commits into
base: dev
Choose a base branch
from
Draft
5 changes: 5 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"sdk": {
"version": "5.0.408"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@page "/diagnostics-alternative"

<RenderableContentControl Context="@Entry.PlcHammer.TECH_MAIN._app" Presentation="DiagnosticsAlternative" />


@code {

protected override void OnInitialized()
{
@* TcoDiagnosticsViewModel.SetDefaultCategory(eMessageCategory.Trace);
TcoDiagnosticsView.SetDefaultDepth(7);
TcoDiagnosticsView.SetDiagnosticsUpdateInterval(2500);*@
base.OnInitialized();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
@page "/diagnostics-from-logger"


tag
<RenderableContentControl Context="@Entry.PlcHammer.TECH_MAIN._app" Presentation="DiagnosticsFromLogger" />
@code {

protected override void OnInitialized()
{
@* TcoDiagnosticsViewModel.SetDefaultCategory(eMessageCategory.Trace);
TcoDiagnosticsView.SetDefaultDepth(7);
TcoDiagnosticsView.SetDiagnosticsUpdateInterval(2500);*@
base.OnInitialized();
}
}
10 changes: 10 additions & 0 deletions src/TcOpen.Hammer/PlcHammer.Hmi.Blazor/Shared/NavMenu.razor
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,16 @@
<span class="oi oi-plus" aria-hidden="true"></span> Diagnostics
</NavLink>
</li>
<li class="nav-item px-3">
<NavLink class="nav-link" href="diagnostics-alternative" Match="NavLinkMatch.All">
<span class="oi oi-plus" aria-hidden="true"></span> Diagnostics Alternative
</NavLink>
</li>
@* <li class="nav-item px-3">
<NavLink class="nav-link" href="diagnostics-from-logger" Match="NavLinkMatch.All">
<span class="oi oi-plus" aria-hidden="true"></span> Diagnostics Logger!
</NavLink>
</li>*@
<li class="nav-item px-3">
<NavLink class="nav-link" href="security" Match="NavLinkMatch.All">
<span class="oi oi-plus" aria-hidden="true"></span> Security
Expand Down
27 changes: 23 additions & 4 deletions src/TcOpen.Hammer/PlcHammer.Hmi.Blazor/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,32 @@
using TcOpen.Inxton.Local.Security.Blazor.Services;
using TcOpen.Inxton.Local.Security.Blazor.Users;
using TcOpen.Inxton.TcoCore.Blazor.Extensions;
using TcOpen.Inxton.TcoCore.Blazor.TcoDiagnosticsAlternative.Configure;
using TcOpen.Inxton.TcoCore.Blazor.TcoDiagnosticsAlternative.Services;
using TcOpen.Inxton.TcoCore.Blazor.TcoDialog.Hubs;
using Vortex.Presentation.Blazor.Services;

using static TcoCore.TcoDiagnosticsAlternativeViewModel;

namespace PlcHammer.Hmi.Blazor
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
MongoUri = Configuration["MongoDbSettings:MongoUri"];
DatabaseName = Configuration["MongoDbSettings:DatabaseName"];
CollectionName = Configuration["MongoDbSettings:CollectionName"];
}

public IConfiguration Configuration { get; }

//Uses Config from appsetings.Development.json, there the connection String etc. is configured
public static string MongoUri { get; private set; }
public static string DatabaseName { get; private set; }
public static string CollectionName { get; set; }

public static StringWriter logMessages = new StringWriter();

// This method gets called by the runtime. Use this method to add services to the container.
Expand All @@ -63,7 +75,7 @@ public void ConfigureServices(IServiceCollection services)

services.AddTcoCoreExtensions();

if (true)/*Mongo database*/
if (false)/*Mongo database*/
{
(userRepo, groupRepo) = SetUpMongoDatabase();
}
Expand All @@ -84,14 +96,21 @@ public void ConfigureServices(IServiceCollection services)
.WriteTo.Notepad() // This will write logs to first instance of notepad program.
// uncomment this to send logs over MQTT, to receive the data run MQTTTestClient from this solution.
// .WriteTo.MQTT(new MQTTnet.Client.Options.MqttClientOptionsBuilder().WithTcpServer("broker.emqx.io").Build(), "fun_with_TcOpen_Hammer")
.Enrich.WithProperty("user",SecurityManager.Manager.Principal.Identity.Name)
.WriteTo.MongoDBBson(
databaseUrl: $"{MongoUri}/{DatabaseName}",
collectionName: $"{CollectionName}"
).Enrich.WithProperty("user",SecurityManager.Manager.Principal.Identity.Name)
.Enrich.With(new Serilog.Enrichers.EnvironmentNameEnricher())
.Enrich.With(new Serilog.Enrichers.EnvironmentUserNameEnricher())
.Enrich.With(new Serilog.Enrichers.MachineNameEnricher())
.MinimumLevel.Verbose())) // Sets the logger configuration (default reports only to console).
.SetSecurity(SecurityManager.Manager.Service)
.SetEditValueChangeLogging(Entry.PlcHammer.Connector);

services.Configure<MongoDbSettings>(Configuration.GetSection("MongoDbSettings"));
services.AddTransient<DataService>();
services.AddSingleton< DataCleanupService>();
services.AddTransient<TcoDiagnosticsAlternativeViewModel>();
}

// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
Expand Down Expand Up @@ -168,8 +187,8 @@ private static (IRepository<UserData> userRepo, IRepository<GroupData> groupRepo

private static (IRepository<UserData> userRepo, IRepository<GroupData> groupRepo) SetUpMongoDatabase()
{
var mongoUri = "mongodb://localhost:27017";
var databaseName = "Hammer";
var mongoUri = MongoUri;
var databaseName = DatabaseName;

/*Data*/
var processRecipiesRepository = new MongoDbRepository<PlainStation001_ProductionData>(new MongoDbRepositorySettings<PlainStation001_ProductionData>(mongoUri, databaseName, "ProcessSettings"));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{
"DetailedErrors": true,
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
"DetailedErrors": true,
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"MongoDbSettings": {
"MongoUri": "mongodb://localhost:27017",
"DatabaseName": "Hammer",
"CollectionName": "log"
}
}

}
4 changes: 2 additions & 2 deletions src/TcOpen.Hammer/PlcHammerConnector/Entry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
namespace PlcHammerConnector
{
public class Entry
{
public static readonly string AmsId = Environment.GetEnvironmentVariable("Tc3Target");
{
public static readonly string AmsId = "5.107.180.64.1.1";

public static PlcHammer.PlcHammerTwinController PlcHammer { get; }
= new PlcHammer.PlcHammerTwinController(Tc3ConnectorAdapter.Create(AmsId, 851, true));
Expand Down
22 changes: 22 additions & 0 deletions src/TcOpen.Hammer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

version: "3.9"
services:
mongodb:
Expand All @@ -7,5 +8,26 @@ services:
- HammerData:/data/db
ports:
- 27017:27017
healthcheck:
test: ["CMD", "mongo", "--eval", "db.adminCommand('ping')"]
interval: 30s
timeout: 10s
retries: 3

mongo-express:
image: mongo-express
container_name: mexpress
environment:
- ME_CONFIG_MONGODB_URL=mongodb://mongodb:27017/
links:
- mongodb
restart: unless-stopped
ports:
- "8081:8081"
depends_on:
mongodb:
condition: service_healthy

volumes:
HammerData:

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TcOpen.Inxton.TcoCore.Blazor.TcoDiagnosticsAlternative.Configure
{
public class MongoDbSettings
{
public string MongoUri { get; set; }
public string DatabaseName { get; set; }
public string CollectionName { get; set; }
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;

using TcOpen.Inxton.TcoCore.Blazor.TcoDiagnosticsAlternative.Mapping;

namespace TcoCore.TcoDiagnosticsAlternative.LoggingToDb
{
public interface IMongoLogger
{
void LogMessage(PlainTcoMessage message);
bool MessageExistsInDatabase(PlainTcoMessage message);
List<PlainTcoMessageExtended> ReadMessages();
PlainTcoMessage GetSimilarMessage(PlainTcoMessage message);
void UpdateMessages(ulong identity, DateTime timeStamp, DateTime timeStampAcknowledged, bool pinned);
}
}
Loading
Loading