161 lines
5.8 KiB
C#
161 lines
5.8 KiB
C#
// Copyright (c) 2017 schick Informatik
|
|
// Description: Controls zur Statusanzeige auf dem Server
|
|
//
|
|
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Windows.Controls;
|
|
using System.Text.RegularExpressions;
|
|
using System.Globalization;
|
|
|
|
using log4net;
|
|
using bsmd.database;
|
|
using System.ServiceProcess;
|
|
|
|
namespace ENI2.Controls
|
|
{
|
|
/// <summary>
|
|
/// Interaction logic for ServerStatusControl.xaml
|
|
/// </summary>
|
|
public partial class ServerStatusControl : UserControl
|
|
{
|
|
|
|
private ObservableCollection<StatusEntry> entries = new ObservableCollection<StatusEntry>();
|
|
private static Regex regex = new Regex(@"BSMD_(\d*)-(.*)-(\w*)");
|
|
private static ILog _log = LogManager.GetLogger("ServerStatus");
|
|
|
|
public ServerStatusControl()
|
|
{
|
|
InitializeComponent();
|
|
this.dataGridStatus.ItemsSource = this.entries;
|
|
this.Loaded += ServerStatusControl_Loaded;
|
|
}
|
|
|
|
private void ServerStatusControl_Loaded(object sender, System.Windows.RoutedEventArgs e)
|
|
{
|
|
this.refreshButton_Click(null, null);
|
|
}
|
|
|
|
internal void Update(LockingServiceReference.ServerStatus serverStatus)
|
|
{
|
|
|
|
System.Windows.Application.Current.Dispatcher.Invoke(delegate {
|
|
// Die Dateien müssen in die Objekte
|
|
entries.Clear();
|
|
foreach (StatusEntry se in StatusEntry.CreateFromList(serverStatus.IMPFiles, "IMP"))
|
|
entries.Add(se);
|
|
|
|
foreach (StatusEntry se in StatusEntry.CreateFromList(serverStatus.READYFiles, "READY"))
|
|
entries.Add(se);
|
|
|
|
foreach (StatusEntry se in StatusEntry.CreateFromList(serverStatus.CORRUPTFiles, "CORRUPT"))
|
|
entries.Add(se);
|
|
|
|
// Enumeration parsen und text ausgeben
|
|
ServiceControllerStatus excel = (ServiceControllerStatus)serverStatus.Excel;
|
|
this.labelStatusExcel.Content = excel.ToString();
|
|
|
|
ServiceControllerStatus report = (ServiceControllerStatus)serverStatus.Report;
|
|
this.labelStatusReport.Content = report.ToString();
|
|
|
|
ServiceControllerStatus transmitter = (ServiceControllerStatus)serverStatus.Transmitter;
|
|
this.labelStatusTransmitter.Content = transmitter.ToString();
|
|
|
|
entries.BubbleSort();
|
|
});
|
|
}
|
|
|
|
public class StatusEntry : IComparable
|
|
{
|
|
private static Dictionary<string, string> guidIdDict = new Dictionary<string, string>();
|
|
|
|
public string Class { get; set; }
|
|
|
|
public DateTime Timestamp { get; set; }
|
|
|
|
public string Id { get; set; }
|
|
|
|
public string Status { get; set; }
|
|
|
|
public static List<StatusEntry> CreateFromList(string[] aList, string status)
|
|
{
|
|
List<StatusEntry> result = new List<StatusEntry>();
|
|
|
|
foreach(string listEntry in aList)
|
|
{
|
|
if (regex.IsMatch(listEntry))
|
|
{
|
|
try
|
|
{
|
|
StatusEntry entry = new StatusEntry();
|
|
Match m = regex.Match(listEntry);
|
|
entry.Timestamp = DateTime.ParseExact(m.Groups[1].Value, "yyyyMMddHHmmss", CultureInfo.InvariantCulture);
|
|
|
|
string guidString = m.Groups[2].Value;
|
|
|
|
if (!guidIdDict.ContainsKey(guidString))
|
|
{
|
|
string idString = "";
|
|
Guid coreId;
|
|
if (Guid.TryParse(m.Groups[2].Value, out coreId))
|
|
{
|
|
MessageCore aCore = DBManager.Instance.GetMessageCoreById(coreId);
|
|
if (aCore != null)
|
|
{
|
|
idString = aCore.DisplayId;
|
|
}
|
|
}
|
|
guidIdDict[guidString] = idString;
|
|
}
|
|
|
|
entry.Id = guidIdDict[guidString];
|
|
entry.Class = m.Groups[3].Value;
|
|
entry.Status = status;
|
|
|
|
result.Add(entry);
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
_log.WarnFormat("Problem reading status info: {0}", ex.Message);
|
|
}
|
|
}
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
public static void ClearIds() { guidIdDict.Clear(); }
|
|
|
|
public int CompareTo(object obj)
|
|
{
|
|
if(obj is StatusEntry)
|
|
return -(Timestamp.CompareTo(((StatusEntry)obj).Timestamp));
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
private void refreshButton_Click(object sender, System.Windows.RoutedEventArgs e)
|
|
{
|
|
StatusEntry.ClearIds();
|
|
|
|
if (App.LockingServiceClient != null)
|
|
{
|
|
try
|
|
{
|
|
LockingServiceReference.ServerStatus serverStatus = App.LockingServiceClient.GetStatus();
|
|
if (serverStatus != null)
|
|
{
|
|
this.Update(serverStatus);
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
_log.DebugFormat("LockingService.GetStatus() threw an exception: {0}", ex.Message);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|