using System.Collections.Generic;
using System.Linq;
using System.Text.Json.Serialization;
using System.Xml.Serialization;
using Dpz.Core.Infrastructure;
#nullable enable
namespace Dpz.Core.Public.ViewModel;
/// <summary>
/// 代码查看配置
/// </summary>
public class CodeViewOption
{
/// <summary>
/// 扩展名
/// </summary>
public string[]? Extensions { get; set; }
/// <summary>
/// 源码存放目录
/// </summary>
public required string SourceCodeRoot { get; set; }
/// <summary>
/// 过滤
/// </summary>
public string[]? Filters { get; set; }
/// <summary>
/// 扩展名和语言映射
/// </summary>
[XmlIgnore]
public Dictionary<string, string>? ExtensionToLanguage { get; set; }
[XmlArray(ElementName = "ExtensionToLanguage")]
[XmlArrayItem(ElementName = "Item")]
[JsonIgnore]
public KeyValueElement[] SerializableExtensionToLanguage =>
ExtensionToLanguage?.Select(x => new KeyValueElement(x.Key, x.Value)).ToArray() ?? [];
/// <summary>
/// version
/// </summary>
public int Version { get; set; }
/// <summary>
/// 获取唯一标识
/// </summary>
/// <returns></returns>
public override string ToString()
{
var list = new List<string>();
if (Extensions != null)
{
list.AddRange(Extensions);
}
if (Filters != null)
{
list.AddRange(Filters);
}
if (ExtensionToLanguage != null)
{
list.AddRange(ExtensionToLanguage.Select(x => x.Key + "=" + x.Value));
}
list.Add(SourceCodeRoot);
list.Add(Version.ToString());
return string.Join(";", list.Where(x => !string.IsNullOrWhiteSpace(x))).GenerateHashMd5();
}
}