Blame view

Vrh.iScheduler/XmlProcessing/WebAppActionElement.cs 3.76 KB
ab9f2fbe   Schwirg László   Add project files.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  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
  {
      /// <summary>
      /// WebAppAction elérési mód esetén 
      /// itt találhatóak a szükséges adatok.
      /// </summary>
      public class WebAppActionElement : XmlLinqBase
      {
          #region Built'in classes
  
          #region ElementNames class
          /// <summary>
          /// Az XML fájlban ilyen elem nevek találhatóak egy "WebAppAction" elemben.
          /// </summary>
          public new class ElementNames : XmlLinqBase.ElementNames
          {
              /// <summary>
              /// 'LoginCredentials' elem név.
              /// </summary>
              public const string LOGINCREDENTIALS = "LoginCredentials";
  
              /// <summary>
              /// 'LoginUrl' elem név.
              /// </summary>
              public const string LOGINURL = "LoginUrl";
  
              /// <summary>
              /// 'ResponseTimeout' elem név.
              /// </summary>
              public const string RESPONSETIMEOUT = "ResponseTimeout";
  
          }
          #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
          {
              /// <summary>
              /// 'Password' attribútum név.
              /// </summary>
              public const string PASSWORD = "Password";
  
              /// <summary>
              /// 'UserName' attribútum név.
              /// </summary>
              public const string USERNAME = "UserName";
          }
          #endregion AttributeNames static class
  
          #endregion Built'in classes
  
          #region Properties
  
          /// <summary>
          /// A bejelentkezéshez szükséges akció. Az az URL ahol a login form található.
          /// </summary>
          public UrlElement LoginUrl { get; set; }
  
          /// <summary>
          /// A felhasználó neve.
          /// </summary>
          public string UserName { get; set; }
  
          /// <summary>
          /// A felhasználó jelszava.
          /// </summary>
          public string Password { get; set; }
  
          /// <summary>
          /// Az akcióhívásokhoz beállítandó timout érték.
          /// </summary>
          public int ResponseTimeout { get; set; }
  
          #endregion Properties
  
          #region Constructors
          /// <summary>
          /// Példányosítás egy 'WebAppAction' XElement alapján.
          /// </summary>
          /// <param name="xelement">A 'WebAppAction' elem XElement objektuma.</param>
          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
      }
  }