//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
// UserRTX.NET satellite library | Author: Sergei Y.Kitáev
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
using System;
using System.Xml;
using System.Xml.Schema;

#if !WASM
namespace user_rtx { using u = user_rtx;
#else
namespace user_rtx.wasm { using u = user_rtx.wasm;
#endif

partial class XmlConfigurationBase {
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

/// <exception cref="InvalidOperationException" />
protected void VerifyDocumentLoaded()
{
   if ( !IsDocumentLoaded )
      throw new InvalidOperationException(u.local.T(
         RC._Document_has_not_been_loaded_into_XML_configuration,
         "Документ не был загружен в XML-конфигурацию." ));
}

//--------------------------------------------------------------------------------------------------

/// <exception cref="InvalidOperationException" />
protected void VerifyCurrentElementSelected()
{
   VerifyDocumentLoaded();
   if ( !IsCurrentElementSelected )
      throw new InvalidOperationException(ProvideErrorMessageWithFile(u.local.T(
         RC._Current_element_is_not_selected_for_XML_configuration,
         "Текущий элемент не выбран для XML-конфигурации." )));
}

//==================================================================================================

/// <exception cref="InvalidOperationException" />
/// <exception cref="XmlSchemaValidationException" />
protected void ValidateDocument() =>
   Document.Validate( ValidateSchema_Handler );

//==================================================================================================

/// <exception cref="XmlSchemaValidationException" />
static void ValidateSchema_Handler( object? sender, ValidationEventArgs e )
{
   if ( u.ops.IsOneOf( e.Severity, XmlSeverityType.Error, XmlSeverityType.Warning ) )
      throw new XmlSchemaValidationException( e.Message );
}

//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
} // XmlConfigurationBase

} // user_rtx (.wasm)
