Files
C4IT-F4SD-Collector/F4SD-Cockpit-ServerCore/DataHistoryConfigGolabalParameters.cs
2026-02-05 10:04:17 +01:00

348 lines
14 KiB
C#

using System;
using System.Collections.Generic;
using System.Reflection;
using System.Xml;
using Newtonsoft.Json;
using C4IT.Configuration;
using C4IT.FASD.Base;
using C4IT.Logging;
using C4IT.XML;
using static C4IT.Logging.cLogManager;
using static C4IT.Configuration.cConfigRegistryHelper;
namespace C4IT.DataHistoryProvider
{
public class cDataHistoryConfigGolabalParameters : cFasdBaseConfig
{
public const string constFileNameF4sdConfig = "F4SD-Global-Configuration.xml";
private const string constFileNameF4sdSchema = "F4SD-Global-Configuration.xsd";
private const string constConfigRootElement = "F4SD-Global-Configuration";
public cConfigHelperParameterList Parameters { get; private set; } = null;
private cDataHistoryConfigInfrastructure InfrastructureConfig = null;
internal cDataHistoryConfigGolabalParameters(cDataHistoryConfigInfrastructure configInfrastructure) :
base(constFileNameF4sdConfig, constFileNameF4sdSchema, constConfigRootElement, true)
{
InfrastructureConfig = configInfrastructure;
}
public override bool InstantiateProperties(XmlElement RootElement, cXmlParser Parser)
{
MethodBase CM = null; if (cLogManager.DefaultLogger.IsDebug) { CM = MethodBase.GetCurrentMethod(); LogMethodBegin(CM); }
try
{
Parameters = LoadParameters(RootElement, Parser );
var _s = JsonConvert.SerializeObject(Parameters, Newtonsoft.Json.Formatting.Indented);
this.IsValid = true;
return true;
}
catch (Exception E)
{
LogException(E);
}
finally
{
if (CM != null) LogMethodEnd(CM);
}
return false;
}
private cConfigHelperParameterList LoadParameters (XmlElement XRoot, cXmlParser Parser)
{
MethodBase CM = null; if (cLogManager.DefaultLogger.IsDebug) { CM = MethodBase.GetCurrentMethod(); LogMethodBegin(CM); }
var _result = new cConfigHelperParameterList();
try
{
var Items = XRoot.ChildNodes;
foreach (var _node in Items)
{
if (!(_node is XmlElement _item)) continue;
Parser.EnterElement(_item.Name);
try
{
var _attPolicy = _item.GetAttribute("Policy");
var _attValue = _item.GetAttribute("Value");
var _ElementCount = 0;
foreach (XmlNode _subNode in _item.ChildNodes)
{
if (_subNode is XmlElement)
_ElementCount++;
}
// check for special parameters
switch (_item.Name)
{
case "InformationClassSearchPriority":
var _val = getInformationClassSearchPriority(_item, Parser);
if (_val != null)
_result.Items[_val.Name] = _val;
continue;
}
if (_attPolicy != null && _attValue != null && _ElementCount == 0)
{
// we have a simple parameter
var _policy = cXmlParser.GetEnumFromAttribute<enumConfigPolicy>(_item, "Policy", enumConfigPolicy.Default);
var _value = cXmlParser.GetStringFromXmlAttribute(_item, "Value", String.Empty);
_result.Items[_item.Name] = new cConfigHelperParameterEntry()
{
Name = _item.Name,
Value = _value,
Policy = _policy.ToString(),
};
}
else if (string.IsNullOrEmpty(_attPolicy) && string.IsNullOrEmpty(_attValue) && _ElementCount > 0)
{
// we have a sublist
if (_result.SubItems == null)
_result.SubItems = new Dictionary<string, cConfigHelperParameterList>();
_result.SubItems[_item.Name] = LoadParameters(_item, Parser);
}
else
{
// we have an invalid entry
var _msg = $"Invalid entry in F4SD-Global-Configuration.xml: {_item.Name}";
Parser.AddMessage(_item, _msg, LogLevels.Warning);
LogEntry(_msg, LogLevels.Warning);
}
}
catch (Exception E)
{
LogException(E);
}
finally
{
Parser.LeaveElement(_item.Name);
}
}
}
catch (Exception E)
{
LogException(E);
}
finally
{
if (CM != null) LogMethodEnd(CM);
}
return _result;
}
private cConfigHelperParameterEntry getInformationClassSearchPriority(XmlElement XNode, cXmlParser Parser)
{
MethodBase CM = null; if (cLogManager.DefaultLogger.IsDebug) { CM = MethodBase.GetCurrentMethod(); LogMethodBegin(CM); }
try
{
var _xNodes = XNode.ChildNodes;
var _policy = cXmlParser.GetEnumFromAttribute<enumConfigPolicy>(XNode, "Policy", enumConfigPolicy.Default);
var _result = new List<string>();
foreach (var _xNode in _xNodes)
{
if (!(_xNode is XmlElement _item))
continue;
Parser.EnterElement(_item.Name);
try
{
if (_item.Name != "InformationClass")
{
// we have an invalid entry
var _msg = $"Invalid entry in F4SD-Global-Configuration.xml: {_item.Name}, should be <InformationClass/>";
Parser.AddMessage(_item, _msg, LogLevels.Warning);
LogEntry(_msg, LogLevels.Warning);
continue;
}
var _InfoClass = cXmlParser.GetEnumFromAttribute<enumFasdInformationClass>(_item, "Type", enumFasdInformationClass.Unknown);
if (_InfoClass == enumFasdInformationClass.Unknown)
{
// we have an invalid type attribute
var _strType = cXmlParser.GetStringFromXmlAttribute(_item, "Type", String.Empty);
var _msg = $"Invalid type attribute value ({_strType}) in entry {_item.Name}";
Parser.AddMessage(_item, _msg, LogLevels.Warning);
LogEntry(_msg, LogLevels.Warning);
continue;
}
var _strInfoClass = _InfoClass.ToString();
if (!_result.Contains(_strInfoClass))
_result.Add(_strInfoClass);
}
catch (Exception E)
{
LogException(E);
}
finally
{
Parser.LeaveElement(_item.Name);
}
}
return new cConfigHelperParameterEntry()
{
Name = XNode.Name,
ValueList = _result,
Policy = _policy.ToString()
};
}
catch (Exception E)
{
LogException(E);
}
finally
{
if (CM != null) LogMethodEnd(CM);
}
return null;
}
public override bool DoXmlUpdates(XmlElement XmlRoot, bool withM42Config = false, bool withIntuneConfig = false, bool withMobileDeviceConfig = false, bool withCitrixConfig = false)
{
MethodBase CM = null; if (cLogManager.DefaultLogger.IsDebug) { CM = MethodBase.GetCurrentMethod(); LogMethodBegin(CM); }
var RetVal = false;
try
{
RetVal |= DoXmlInsertElement(XmlRoot
, ""
, "ShouldSkipSlimView"
, "<ShouldSkipSlimView Policy=\"Default\" Value=\"false\" />"
);
RetVal |= DoXmlInsertElement(XmlRoot
, ""
, "SmallViewAlignment"
, "<SmallViewAlignment Policy=\"Default\" Value=\"Right\" />"
);
RetVal |= DoXmlInsertElement(XmlRoot
, ""
, "FavouriteBarAlignment"
, "<FavouriteBarAlignment Policy=\"Default\" Value=\"Right\" />"
);
RetVal |= DoXmlInsertElement(XmlRoot
, ""
, "InformationClassSearchPriority"
, "<InformationClassSearchPriority Policy=\"Default\" />"
);
RetVal |= DoXmlInsertElement(XmlRoot
, "InformationClassSearchPriority"
, "InformationClass[@Type='User']"
, "<InformationClass Type=\"User\" />"
);
RetVal |= DoXmlInsertElement(XmlRoot
, "InformationClassSearchPriority"
, "InformationClass[@Type='Computer']"
, "<InformationClass Type=\"Computer\" />"
);
RetVal |= DoXmlInsertElement(XmlRoot
, "InformationClassSearchPriority"
, "InformationClass[@Type='VirtualSession']"
, "<InformationClass Type=\"VirtualSession\" />"
);
RetVal |= DoXmlInsertElement(XmlRoot
, "InformationClassSearchPriority"
, "InformationClass[@Type='Ticket']"
, "<InformationClass Type=\"Ticket\" />"
);
RetVal |= DoXmlInsertElement(XmlRoot
, ""
, "TicketConfiguration"
, "<TicketConfiguration />"
);
RetVal |= DoXmlInsertElement(XmlRoot
, "TicketConfiguration"
, "NotesMandatory"
, "<NotesMandatory Policy=\"Hidden\" Value=\"false\" />"
);
RetVal |= DoXmlInsertElement(XmlRoot
, "TicketConfiguration"
, "ShowOverview"
, "<ShowOverview Policy=\"Hidden\" Value=\"true\" />"
);
RetVal |= DoXmlInsertElement(XmlRoot
, "TicketConfiguration"
, "OpenTicketsExternally"
, "<OpenTicketsExternally Policy=\"Hidden\" Value=\"false\" />"
);
RetVal |= DoXmlInsertElement(XmlRoot
, "TicketConfiguration"
, "OpenIncidentsExternally"
, "<OpenIncidentsExternally Policy=\"Hidden\" Value=\"false\" />"
);
RetVal |= DoXmlInsertElement(XmlRoot
, "TicketConfiguration"
, "OverviewPollingPersonal"
, $"<OverviewPollingPersonal Policy=\"Hidden\" Value=\"{cF4sdTicketConfig.DefaultOverviewPollingPersonal}\" />"
);
RetVal |= DoXmlInsertElement(XmlRoot
, "TicketConfiguration"
, "OverviewPollingRole"
, $"<OverviewPollingRole Policy=\"Hidden\" Value=\"{cF4sdTicketConfig.DefaultOverviewPollingRole}\" />"
);
#pragma warning disable CS0618 // Type or member is obsolete
var oldShowDocumentCaseDialog = InfrastructureConfig?.M42Wpm?.ShowDocumentCaseDialog ?? enumShowDocumentCaseDialog.ifRequired;
var oldDisableAutomaticTimeTracking = InfrastructureConfig?.M42Wpm?.DisableAutomaticTimeTracking ?? false;
#pragma warning restore CS0618 // Type or member is obsolete
RetVal |= DoXmlInsertElement(XmlRoot
, "TicketConfiguration"
, "CompletitionPolicy"
, $"<CompletitionPolicy Policy=\"Hidden\" Value=\"{oldShowDocumentCaseDialog.ToString()}\" />"
);
RetVal |= DoXmlInsertElement(XmlRoot
, "TicketConfiguration"
, "DisableAutomaticTimeTracking"
, $"<DisableAutomaticTimeTracking Policy=\"Mandatory\" Value=\"{oldDisableAutomaticTimeTracking.ToString()}\" />"
);
}
catch (Exception E)
{
LogException(E);
}
finally
{
if (CM != null) LogMethodEnd(CM);
}
return RetVal;
}
}
}