PluginElement.cs 3.03 KB
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

using Vrh.XmlProcessing;

namespace Vrh.iScheduler
{
    /// <summary>
    /// Plugin elérési mód esetén 
    /// itt találhatóak a szükséges adatok.
    /// </summary>
    public class PluginElement : XmlLinqBase
    {
        #region Built'in classes

        #region ElementNames class
        /// <summary>
        /// Az XML fájlban ilyen elem nevek találhatóak egy "Plugin" elemben.
        /// </summary>
        public new class ElementNames : XmlLinqBase.ElementNames
        {
            /// <summary>
            /// 'AssemblyPath' elem név.
            /// </summary>
            public const string ASSEMBLYPATH = "AssemblyPath";

            /// <summary>
            /// 'ObjectXml' elem név.
            /// </summary>
            public const string OBJECTXML = "ObjectXml";
        }
        #endregion ElementNames class

        #region AttributeNames static class
        /// <summary>
        /// Az XML fájlban ilyen attribútum nevek találhatóak egy 'Plugin' elemben.
        /// </summary>
        public static class AttributeNames
        {
        }
        #endregion AttributeNames static class

        #endregion Built'in classes

        #region Properties

        /// <summary>
        /// A plugin DLL fizikai elérésével együtt.
        /// </summary>
        public string AssemblyPath { get; set; }

        /// <summary>
        /// Az ütemezett objektum XmlParser kacsolati sztringje.
        /// A sztringben célszerűen fizikai elérési útvonalakat kell megadni.
        /// </summary>
        public string ObjectXml { get; set; }

        #endregion Properties

        #region Constructors
        /// <summary>
        /// Példányosítás egy 'Plugin' XElement alapján.
        /// </summary>
        /// <param name="xelement">A 'Plugin' elem XElement objektuma.</param>
        public PluginElement(XElement xelement)
        {
            if (xelement != null)
            {
                this.AssemblyPath = GetValue(GetXElement(xelement, ElementNames.ASSEMBLYPATH, true), "", true, true);
                this.ObjectXml = GetValue(GetXElement(xelement, ElementNames.OBJECTXML, true), "", true, true);
                if (!File.Exists(this.AssemblyPath))
                {
                    throw new ApplicationException(string.Concat(
                        "The file \"", this.AssemblyPath, "\" does not exist in then Plugin.",
                        nameof(PluginElement.AssemblyPath), " element!"
                    ));
                }
                //if (!File.Exists(this.ObjectXml))
                //{
                //    throw new ApplicationException(string.Concat(
                //        "The file \"", this.ObjectXml, "\" does not exist in then Plugin.", 
                //        nameof(PluginElement.ObjectXml), " element!"
                //    ));
                //}
            }
        }
        #endregion Constructors
    }
}