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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,4 @@ nugets/

# VSCode
.vscode/
src/TcOpen.Hammer/Logs/log20230925.txt
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()
{
TcoDiagnosticsAlternativeView.SetDefaultCategoryFilter(eMessageCategory.Info);
TcoDiagnosticsAlternativeView.SetDiagnosticsUpdateInterval(500);
TcoDiagnosticsAlternativeView.SetDefaultDepth(11);
base.OnInitialized();
}
}
4 changes: 4 additions & 0 deletions src/TcOpen.Hammer/PlcHammer.Hmi.Blazor/Pages/_Host.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<link href="PlcHammer.Hmi.Blazor.styles.css" rel="stylesheet" />
<link rel="stylesheet" href="/_content/Inxton.Vortex.Presentation.Controls.Blazor-experimental/css/inxton-bootstrap.min.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.12.0/css/all.css">
<link href="YourLibraryName.styles.css" rel="stylesheet">
<link href="path_to_bootstrap.min.css" rel="stylesheet" integrity="if_needed" />
</head>


Expand All @@ -37,6 +39,8 @@
<script src="/_content/Inxton.Vortex.Presentation.Controls.Blazor-experimental/js/inxton-bootstrap.bundle.min.js"></script>
<script src="/_content/Inxton.Vortex.Presentation.Controls.Blazor-experimental/js/jquery-3.6.0.min.js"></script>
<script src="_framework/blazor.server.js"></script>
<script src="_content/BlazorStrap/popper.min.js"></script>
<script src="_content/BlazorStrap/blazorstrap.js"></script>
</body>
</html>

18 changes: 11 additions & 7 deletions src/TcOpen.Hammer/PlcHammer.Hmi.Blazor/PlcHammer.Hmi.Blazor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@

<ItemGroup>
<PackageReference Include="Inxton.Vortex.Presentation.Controls.Blazor-experimental" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="5.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.4" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.4" />
<PackageReference Include="Serilog.Sinks.Notepad" Version="2.0.0" />
<PackageReference Include="Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore" Version="5.0.17" />
<PackageReference Include="Microsoft.AspNetCore.Identity.EntityFrameworkCore" Version="5.0.17" />
<PackageReference Include="Microsoft.AspNetCore.Identity.UI" Version="5.0.17" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="5.0.17" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="5.0.17">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Serilog.Sinks.MongoDB" Version="5.3.1" />
<PackageReference Include="Serilog.Sinks.Notepad" Version="3.0.0" />
<PackageReference Include="Serilog.Sinks.TextWriter" Version="2.1.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.2.0" />
<PackageReference Include="Serilog.Enrichers.Environment" Version="2.3.0" />
</ItemGroup>

<ItemGroup>
Expand Down
5 changes: 5 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,11 @@
<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="security" Match="NavLinkMatch.All">
<span class="oi oi-plus" aria-hidden="true"></span> Security
Expand Down
38 changes: 30 additions & 8 deletions src/TcOpen.Hammer/PlcHammer.Hmi.Blazor/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using BlazorStrap;

using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Components.Authorization;
Expand Down Expand Up @@ -31,20 +33,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 +77,7 @@ public void ConfigureServices(IServiceCollection services)

services.AddTcoCoreExtensions();

if (true)/*Mongo database*/
if (false)/*Mongo database*/
{
(userRepo, groupRepo) = SetUpMongoDatabase();
}
Expand All @@ -84,16 +98,24 @@ 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)
.Enrich.With(new Serilog.Enrichers.EnvironmentNameEnricher())
.Enrich.With(new Serilog.Enrichers.EnvironmentUserNameEnricher())
.Enrich.With(new Serilog.Enrichers.MachineNameEnricher())
.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<IDataService, DataService>();
services.AddSingleton<DataBaseMaxEntryCleanupService>();
services.AddBlazorStrap();
}


// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
Expand Down Expand Up @@ -126,7 +148,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
});

Entry.PlcHammer.Connector.BuildAndStart();
Entry.PlcHammer.TECH_MAIN._app._logger.StartLoggingMessages(TcoCore.eMessageCategory.Info);
Entry.PlcHammer.TECH_MAIN._app._logger.StartLoggingMessages(TcoCore.eMessageCategory.Debug);
}

private static void SetUpRepositories(IRepository<PlainStation001_ProductionData> processRecipiesRepository,
Expand Down Expand Up @@ -168,8 +190,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
Expand Up @@ -19,16 +19,24 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="BlazorStrap" Version="5.1.102.51923" />
<PackageReference Include="BlazorStrap.V5" Version="5.1.102.51723" />
<PackageReference Include="Inxton.Vortex.Presentation.Controls.Blazor-experimental" Version="2.0.0" />
<PackageReference Include="Blazm.Components" Version="1.0.5" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.4" />
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="5.0.17" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Client" Version="5.0.17" />
<PackageReference Include="Microsoft.AspNetCore.SignalR.Core" Version="1.1.0" />
<PackageReference Include="MongoDB.Bson" Version="2.22.0" />
<PackageReference Include="MongoDB.Driver" Version="2.22.0" />
<PackageReference Include="Blazm.Components" Version="1.0.5" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\TcOpen.Inxton\src\Abstractions\TcOpen.Inxton.Abstractions.csproj" />
<ProjectReference Include="..\TcoCoreConnector\TcoCoreConnector.csproj" />
</ItemGroup>

<ItemGroup>
<Folder Include="wwwroot\Icons\" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ public TcoDiagnosticsViewModel()
this.UpdateMessagesCommand = new RelayCommand(a => this.UpdateMessages(), (x) => !this.DiagnosticsRunning);
}

public TcoDiagnosticsViewModel(IsTcoObject tcoObject)
{
_tcoObject = tcoObject;
this.UpdateMessagesCommand = new RelayCommand(a => this.UpdateMessages(), (x) => !this.DiagnosticsRunning);
}
//This is actually never called, so we could remove it
//public TcoDiagnosticsViewModel(IsTcoObject tcoObject)
//{
// _tcoObject = tcoObject;
// Console.WriteLine("tcoObject constructor called TcoDiagnosticsViewModel");
// this.UpdateMessagesCommand = new RelayCommand(a => this.UpdateMessages(), (x) => !this.DiagnosticsRunning);
//}
/// <summary>
/// Gets the command that executes update of messages on demand.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<div class="d-flex">
@if (UseNative)
{
<input type="date" class="form-control w-auto d-inline" @bind-value="@Date" disabled="@IsDisabled" />
<TimePickerComponent @bind-SecondOfDay="SecondOfDay" UseNativeTimePicker="@UseNative" IsDisabled="IsDisabled" />
}
else
{
<input type="datetime-local" class="form-control w-auto d-inline" value="@(DateAndTime.ToString("yyyy-MM-ddTHH:mm"))" disabled="@IsDisabled"
@onchange="async (e) =>
{
var dateString = e.Value.ToString();
if(!string.IsNullOrEmpty(dateString))
{
DateAndTime = DateTime.Parse(dateString);
}
else
{
DateAndTime = new DateTime(2022, 01, 01, 12, 0, 0);
}
await NotifyChanged();
}"
/>

}
</div>

@code {

[Parameter]
public DateTime DateAndTime
{
get; set;
}

[Parameter]
public EventCallback<DateTime> DateAndTimeChanged
{
get; set;
}

[Parameter]
public bool IsDisabled
{
get; set;
}

[Parameter]
public bool UseNative
{
get; set;
}

private DateTime Date
{
get
{
return DateAndTime.Date;
}
set
{
DateAndTime = value.AddSeconds(SecondOfDay);
_ = NotifyChanged();
}
}

private int SecondOfDay
{
get
{
return DateAndTime.Hour * 3600 + DateAndTime.Minute * 60;
}
set
{
DateAndTime = DateAndTime.Date.AddSeconds(value);
_ = NotifyChanged();
}
}

private Task NotifyChanged()
{
return DateAndTimeChanged.InvokeAsync(DateAndTime);
}
}
Loading
Loading