138 lines
5.3 KiB
C#
138 lines
5.3 KiB
C#
using C4IT.F4SD.DisplayFormatting;
|
|
using C4IT.FASD.Base;
|
|
using Newtonsoft.Json.Linq;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using static C4IT.Logging.cLogManager;
|
|
|
|
namespace FasdDesktopUi.Basics.Models.QuickActionOutput
|
|
{
|
|
public abstract class cQuickActionOutput
|
|
{
|
|
protected const string veiledText = "********";
|
|
|
|
protected readonly IRawValueFormatter _rawValueFormatter = new RawValueFormatter();
|
|
|
|
public cQuickActionOutput(cF4sdQuickActionRevision.cOutput scriptOutput)
|
|
{
|
|
_rawValueFormatter.SetDefaultCulture(cFasdCockpitConfig.Instance.SelectedCulture);
|
|
_rawValueFormatter.SetDefaultTimeZone(TimeZoneInfo.Local);
|
|
ErrorCode = scriptOutput.ErrorCode;
|
|
ErrorDescription = scriptOutput.ErrorDescription;
|
|
ResultCode = scriptOutput.ResultCode.GetValueOrDefault();
|
|
IsError = HasError(scriptOutput);
|
|
}
|
|
|
|
public cSupportCaseDataProvider DataProvider { get; private set; }
|
|
public enumQuickActionSuccess? ResultCode { get; set; }
|
|
public int? ErrorCode { get; set; }
|
|
public string ErrorDescription { get; set; }
|
|
|
|
public bool IsError { get; private set; }
|
|
|
|
internal static KeyValuePair<string, RawValueType> GetDisplayType(dynamic columnTypeObject)
|
|
{
|
|
var output = new KeyValuePair<string, RawValueType>();
|
|
|
|
try
|
|
{
|
|
var columnType = columnTypeObject.ToObject<dynamic>();
|
|
string name = string.Empty;
|
|
RawValueType type = RawValueType.STRING;
|
|
|
|
|
|
if (columnType.Name != null)
|
|
if (columnType.Name is Newtonsoft.Json.Linq.JValue nameJValue)
|
|
name = nameJValue.Value.ToString();
|
|
|
|
if (columnType.Type != null)
|
|
if (columnType.Type is Newtonsoft.Json.Linq.JValue typeJValue)
|
|
if (Enum.TryParse(typeJValue.Value.ToString(), out RawValueType typeJValueType))
|
|
type = typeJValueType;
|
|
|
|
output = new KeyValuePair<string, RawValueType>(name, type);
|
|
|
|
}
|
|
catch (Exception E)
|
|
{
|
|
LogException(E);
|
|
}
|
|
|
|
return output;
|
|
}
|
|
|
|
public static cQuickActionOutput GetQuickActionOutput(cF4sdQuickActionRevision.cOutput scriptOutput, cSupportCaseDataProvider dataProvider)
|
|
{
|
|
if (scriptOutput == null)
|
|
return null;
|
|
|
|
try
|
|
{
|
|
if (scriptOutput?.Values == null)
|
|
{
|
|
var output = new cQuickActionOutputSingle(scriptOutput) { DataProvider = dataProvider };
|
|
return output;
|
|
}
|
|
else if (scriptOutput.Values is JArray scriptValueJArray)
|
|
{
|
|
var scriptValues = scriptValueJArray.ToObject<List<dynamic>>();
|
|
if (scriptValues != null && scriptValues.Count > 0)
|
|
{
|
|
var output = new cQuickActionOutputList(scriptOutput) { DataProvider = dataProvider };
|
|
|
|
foreach (var scriptValue in scriptValues)
|
|
{
|
|
if (scriptValue is JObject scriptValueJObject)
|
|
{
|
|
try
|
|
{
|
|
var scriptValueHelperDictionary = scriptValueJObject.ToObject<Dictionary<string, object>>();
|
|
output.Values.Add(scriptValueHelperDictionary.ToList());
|
|
}
|
|
catch (Exception E)
|
|
{
|
|
LogException(E);
|
|
}
|
|
}
|
|
}
|
|
|
|
return output;
|
|
}
|
|
}
|
|
else if (scriptOutput.Values is JObject scriptValueJObject)
|
|
{
|
|
try
|
|
{
|
|
var output = new cQuickActionOutputObject(scriptOutput) { DataProvider = dataProvider };
|
|
return output;
|
|
}
|
|
catch (Exception E)
|
|
{
|
|
LogException(E);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return new cQuickActionOutputSingle(scriptOutput) { DataProvider = dataProvider };
|
|
}
|
|
}
|
|
catch (Exception E)
|
|
{
|
|
LogException(E);
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public static bool HasError(cF4sdQuickActionRevision.cOutput quickActionOutput)
|
|
{
|
|
if ((quickActionOutput?.ResultCode == null || quickActionOutput?.ResultCode == enumQuickActionSuccess.finished || quickActionOutput?.ResultCode == enumQuickActionSuccess.successfull)
|
|
&& (quickActionOutput?.ErrorCode == null || quickActionOutput?.ErrorCode == 0)
|
|
&& string.IsNullOrEmpty(quickActionOutput?.ErrorDescription))
|
|
return false;
|
|
return true;
|
|
}
|
|
}
|
|
}
|