Add project files.

This commit is contained in:
Admin
2024-09-02 10:03:23 +07:00
parent 42def0d4aa
commit 6219298497
361 changed files with 58423 additions and 0 deletions
@@ -0,0 +1,60 @@
using Serilog;
using Serilog.Core;
using Serilog.Events;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace SafeBagDE70.Admin
{
/// <summary>
/// Interaction logic for LogViewerUC.xaml
/// </summary>
public partial class LogViewerUC : UserControl
{
private ObservableCollection<string> _logItems = new ObservableCollection<string>();
public LogViewerUC(ObservableCollection<string> logCollection)
{
InitializeComponent();
LogListBox.ItemsSource = logCollection;
}
private void LogInfoButton_Click(object sender, RoutedEventArgs e)
{
Log.Information("This is an informational log message");
}
}
public class RealTimeLogSink : ILogEventSink
{
private readonly IFormatProvider _formatProvider;
private readonly ObservableCollection<string> _logCollection;
public RealTimeLogSink(ObservableCollection<string> logCollection, IFormatProvider formatProvider = null)
{
_logCollection = logCollection;
_formatProvider = formatProvider;
}
public void Emit(LogEvent logEvent)
{
var message = logEvent.RenderMessage(_formatProvider);
var logLevel = logEvent.Level.ToString();
var timestampedMessage = $"[{logEvent.Timestamp:HH:mm:ss}] [{logLevel}]{message}";
// Ensure the message is added on the UI thread
App.Current.Dispatcher.Invoke(() => _logCollection.Add(timestampedMessage));
}
}
}
@@ -0,0 +1,94 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SafeBagDE70.StateMachine
{
public class ProcessStateMachine
{
private string? _currentState;
public ProcessStateMachine()
{
_currentState = App.StateMachineConfig.States.FirstOrDefault();
}
public string CurrentState => _currentState;
public bool CanTransitionTo(string newState, out Transition transition)
{
transition = App.StateMachineConfig.Transitions
.FirstOrDefault(t => t.From.Contains(_currentState) && t.To.Contains(newState));
return transition != null;
}
public void TransitionToState(string newState)
{
if (CanTransitionTo(newState, out Transition transition))
{
if (ExecuteActions(transition))
{
// Transition to the new state if the required condition is met
_currentState = newState;
}
else
{
Console.WriteLine($"Failed to meet action requirements. Staying in {_currentState}.");
}
}
else
{
throw new InvalidOperationException($"Cannot transition from {_currentState} to {newState}");
}
}
private bool ExecuteActions(Transition transition)
{
bool allRequiredActionsSucceeded = true;
bool atLeastOneActionSucceeded = false;
foreach (var action in transition.Actions)
{
bool success = ExecuteAction(action.Name);
if (success)
{
atLeastOneActionSucceeded = true;
}
if (action.IsRequired && !success)
{
allRequiredActionsSucceeded = false;
}
}
// Determine if the transition should happen based on the condition
if (transition.RequireAtLeastOneActionSuccess)
{
return atLeastOneActionSucceeded;
}
else
{
return allRequiredActionsSucceeded;
}
}
private bool ExecuteAction(string actionName)
{
// Simulate action execution based on the action name
//Console.WriteLine($"Executing action: {App.StateMachineConfig.Actions[actionName]}");
switch(actionName)
{
case "DoInit":
break;
}
// For the sake of this example, all actions succeed
return true;
}
}
}