Skip to content

Commit

Permalink
collect metadata validation errors for displaying them al together, r…
Browse files Browse the repository at this point in the history
…eplace flow-layout pane
  • Loading branch information
t0815 committed Oct 18, 2024
1 parent f175dcf commit d1a9e5e
Show file tree
Hide file tree
Showing 9 changed files with 531 additions and 455 deletions.
59 changes: 44 additions & 15 deletions MyCBZ/Data/DataValidation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System;
using Microsoft.IdentityModel.Protocols.WsTrust;
using SharpCompress.Common;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
Expand All @@ -7,6 +9,7 @@
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Forms;
using Win_CBZ.Events;
using static Win_CBZ.Handler.AppEventHandler;
Expand Down Expand Up @@ -114,35 +117,61 @@ public bool ValidateMetaDataInvalidKeys(ref ArrayList metaDataEntryErrors, bool
{
bool error = false;

foreach (MetaDataEntry entryA in Program.ProjectModel.MetaData.Values)
foreach (MetaDataEntry entry in Program.ProjectModel.MetaData.Values)
{
if (Program.ProjectModel.MetaData.ProtectedKeys.IndexOf(entryA.Key.ToLower()) != -1 ||
entryA.Key.Length == 0)
try
{
metaDataEntryErrors.Add(entryA.Key);
error = true;
}
if (Program.ProjectModel.MetaData.ProtectedKeys.IndexOf(entry.Key.ToLower()) != -1)
{
throw new MetaDataValidationException(entry, null, "Key with name ['" + entry.Key + "'] is not allowed!", showError);
}

if (cancellationToken != null)
{
if (cancellationToken.Value.IsCancellationRequested)
//Regex re = Regex.("/[a-z]+$/gi");

if (entry != null && !Regex.IsMatch(entry.Key, @"^[a-z]+$", RegexOptions.IgnoreCase))
{
break;
throw new MetaDataValidationException(entry, null, "Key with name ['" + entry.Key + "'] must contain only values between ['a-zA-Z']!", showError);
}


if (cancellationToken != null)
{
if (cancellationToken.Value.IsCancellationRequested)
{
break;
}
}
}
catch (MetaDataValidationException ex)
{
metaDataEntryErrors.Add(ex.Message);
error = true;
}
}

string[] duplicates = ValidateDuplicateStrings(Program.ProjectModel.MetaData.Values.ToArray().Select(s => s.Key).ToArray());

if (duplicates.Length > 0)
{
metaDataEntryErrors.Add("Duplicate keys ['" + String.Join(",", duplicates) + "'] not allowed!");
error = true;
}

if (error)
{
String lines = string.Join("\r\n", metaDataEntryErrors.ToArray());
String errorText = string.Join(", ", metaDataEntryErrors.ToArray());


if (showError)
{
MessageLogger.Instance.Log(LogMessageEvent.LOGMESSAGE_TYPE_WARNING, "Metadata Validation failed! Invalid Keys [" + errorText + "] found.");
DialogResult r = ApplicationMessage.ShowWarning("Metadata Validation failed! The folliwing keys are no allowed:\r\n\r\n" + lines, "Metadata Validation Error", ApplicationMessage.DialogType.MT_WARNING, ApplicationMessage.DialogButtons.MB_OK);
MessageLogger.Instance.Log(LogMessageEvent.LOGMESSAGE_TYPE_WARNING, "Metadata validation failed!");


foreach (String errorText in metaDataEntryErrors)
{
MessageLogger.Instance.Log(LogMessageEvent.LOGMESSAGE_TYPE_WARNING, errorText);
}

DialogResult r = ApplicationMessage.ShowWarning("Metadata validation failed!\r\nThe following keys are not valid:\r\n\r\n" + lines, "Metadata Validation Error", ApplicationMessage.DialogType.MT_WARNING, ApplicationMessage.DialogButtons.MB_OK);
}
}

Expand Down
2 changes: 2 additions & 0 deletions MyCBZ/Events/UpdatePageListViewSortingEvent.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Versioning;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Win_CBZ.Events
{
[SupportedOSPlatform("windows")]
internal class UpdatePageListViewSortingEvent
{
public int SortColumn { get; set; } = 1; // sort by index by default
Expand Down
Loading

0 comments on commit d1a9e5e

Please sign in to comment.