using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;
using Vrh.XmlProcessing;
namespace Vrh.iScheduler
{
///
/// WebAppAction elérési mód esetén
/// itt találhatóak a szükséges adatok.
///
public class WebAppActionElement : XmlLinqBase
{
#region Built'in classes
#region ElementNames class
///
/// Az XML fájlban ilyen elem nevek találhatóak egy "WebAppAction" elemben.
///
public new class ElementNames : XmlLinqBase.ElementNames
{
///
/// 'LoginCredentials' elem név.
///
public const string LOGINCREDENTIALS = "LoginCredentials";
///
/// 'LoginUrl' elem név.
///
public const string LOGINURL = "LoginUrl";
///
/// 'ResponseTimeout' elem név.
///
public const string RESPONSETIMEOUT = "ResponseTimeout";
}
#endregion ElementNames class
#region AttributeNames static class
///
/// Az XML fájlban ilyen attribútum nevek találhatóak egy 'Plugin' elemben.
///
public static class AttributeNames
{
///
/// 'Password' attribútum név.
///
public const string PASSWORD = "Password";
///
/// 'UserName' attribútum név.
///
public const string USERNAME = "UserName";
}
#endregion AttributeNames static class
#endregion Built'in classes
#region Properties
///
/// A bejelentkezéshez szükséges akció. Az az URL ahol a login form található.
///
public UrlElement LoginUrl { get; set; }
///
/// A felhasználó neve.
///
public string UserName { get; set; }
///
/// A felhasználó jelszava.
///
public string Password { get; set; }
///
/// Az akcióhívásokhoz beállítandó timout érték.
///
public int ResponseTimeout { get; set; }
#endregion Properties
#region Constructors
///
/// Példányosítás egy 'WebAppAction' XElement alapján.
///
/// A 'WebAppAction' elem XElement objektuma.
public WebAppActionElement(XElement xelement)
{
if (xelement != null)
{
XElement urlXE = xelement.Element(ElementNames.LOGINURL);
if (urlXE == null)
{
throw new ApplicationException(string.Format(XmlLinqBase.Messages.ERR_MISSINGELEMENT,ElementNames.LOGINURL));
}
this.LoginUrl = new UrlElement(urlXE);
XElement credXE = xelement.Element(ElementNames.LOGINCREDENTIALS);
if (urlXE == null)
{
throw new ApplicationException(string.Format(XmlLinqBase.Messages.ERR_MISSINGELEMENT, ElementNames.LOGINURL));
}
this.UserName = GetValue(AttributeNames.USERNAME, credXE, "", true, true);
this.Password = GetValue(AttributeNames.PASSWORD, credXE, "");
int timeout = GetValue(xelement.Element(ElementNames.RESPONSETIMEOUT), 60);
this.ResponseTimeout = Math.Min(3600, Math.Max(10, timeout)) * 1000;
}
}
#endregion Constructors
}
}