/
smwwiki
/
OneScript_fork
Обзор
Документация
Войти
/
smwwiki
/
OneScript_fork
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
develop
src/OneScript.StandardLibrary/XMLSchema/Collections/XMLSchemaSet.cs
115 строк
3 KB
Yuri Goncharuk
Для классов библиотеки запрещаем наследование
27 сен 2023, 23:27
27 сен 2023, 23:27
f59e417
Код
Авторство
О чём код?
/*---------------------------------------------------------- This Source Code Form is subject to the terms of the Mozilla Public License, v.2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. ----------------------------------------------------------*/ using System.Collections.Generic; using System.Linq; using System.Xml.Schema; using OneScript.Contexts; using OneScript.Exceptions; using OneScript.Values; using ScriptEngine; using ScriptEngine.Machine; using ScriptEngine.Machine.Contexts; namespace OneScript.StandardLibrary.XMLSchema.Collections { [ContextClass("НаборСхемXML", "XMLSchemaSet")] public sealed class XMLSchemaSet : AutoCollectionContext<XMLSchemaSet, Objects.XMLSchema> { private readonly XmlSchemaSet _schemaSet; private readonly List<Objects.XMLSchema> _items; private XMLSchemaSet() { _items = new List<Objects.XMLSchema>(); _schemaSet = new XmlSchemaSet(); _schemaSet.ValidationEventHandler += SchemaSet_ValidationError; } #region OneScript #region Methods [ContextMethod("Добавить", "Add")] public void Add(Objects.XMLSchema schema) { _items.Add(schema); _schemaSet.Add(schema.SchemaObject); } [ContextMethod("Количество", "Count")] public override int Count() => _schemaSet.Count; [ContextMethod("Получить", "Get")] public Objects.XMLSchema Get(IValue value) { switch (value.GetRawValue()) { case BslStringValue s: return _items.FirstOrDefault(x => x.TargetNamespace.Equals((string)s)); case BslNumericValue n: return _items[(int)n]; default: throw RuntimeException.InvalidArgumentType(); } } [ContextMethod("Проверить", "Validate")] public bool Validate() { _schemaSet.Compile(); return _schemaSet.IsCompiled; } [ContextMethod("Удалить", "Delete")] public void Delete(string namespaceUri) { Objects.XMLSchema item = _items.Find(x => x.TargetNamespace.Equals(namespaceUri)); if (item is Objects.XMLSchema) { _items.Remove(item); _schemaSet.Remove(item.SchemaObject); } } #endregion #region Constructors [ScriptConstructor(Name = "По умолчанию")] public static XMLSchemaSet Constructor() => new XMLSchemaSet(); #endregion #endregion #region IEnumerable public override IEnumerator<Objects.XMLSchema> GetEnumerator() => _items.GetEnumerator(); #endregion #region SchemaSetEventHandlers private void SchemaSet_ValidationError(object sender, ValidationEventArgs args) { switch (args.Severity) { case XmlSeverityType.Error: SystemLogger.Write($"ERROR:{args.Message}"); break; default: SystemLogger.Write($"WARNING:{args.Message}"); break; } } #endregion } }