/OR.Lazarus/OR.Lazarus.Library/DataTier/Source/Lazarus/UserDetail.cs

# · C# · 191 lines · 138 code · 33 blank · 20 comment · 10 complexity · d0e3516b4a68981201714e951b0b1ea7 MD5 · raw file

  1. using System;
  2. using System.Data;
  3. using System.Xml;
  4. using OR.Reuse.Persistence;
  5. using Derived = OR.Lazarus.Library.DataTier.Source;
  6. namespace OR.Lazarus.Library.DataTier.Source.Lazarus
  7. {
  8. /// <summary>
  9. /// Defines a user, which may be a database-internal user, or a Windows Security User. As user may be a member of many roles.
  10. /// </summary>
  11. public class UserDetail : EntityBase
  12. {
  13. protected System.String mName;
  14. protected string mType;
  15. protected string mPassword;
  16. protected string mDescription;
  17. protected Derived.RoleCollection mRoles;
  18. public UserDetail()
  19. {
  20. mRoles = new Derived.RoleCollection();
  21. mRoles.ParentEntity = this;
  22. }
  23. /// <summary>
  24. /// Specifies a unique name for the entity.
  25. /// </summary>
  26. public System.String Name
  27. {
  28. get
  29. {
  30. return ( mName );
  31. }
  32. set
  33. {
  34. mName = value;
  35. }
  36. }
  37. /// <summary>
  38. /// Defines the type of user. Possible values are Internal and Windows. Internal users belong to the specific Database, while Windows users are Domain or Active Directory logins.
  39. /// </summary>
  40. public string Type
  41. {
  42. get
  43. {
  44. return ( mType );
  45. }
  46. set
  47. {
  48. mType = value;
  49. }
  50. }
  51. /// <summary>
  52. /// Defines the password for the user.
  53. /// </summary>
  54. public string Password
  55. {
  56. get
  57. {
  58. return ( mPassword );
  59. }
  60. set
  61. {
  62. mPassword = value;
  63. }
  64. }
  65. /// <summary>
  66. /// Provides a long-text description for the entity.
  67. /// </summary>
  68. public string Description
  69. {
  70. get
  71. {
  72. return ( mDescription );
  73. }
  74. set
  75. {
  76. mDescription = value;
  77. }
  78. }
  79. public Derived.RoleCollection Roles
  80. {
  81. get
  82. {
  83. return ( mRoles );
  84. }
  85. set
  86. {
  87. mRoles = value;
  88. }
  89. }
  90. public override void LoadXml( XmlElement pSource )
  91. {
  92. // Scalar Values
  93. mName = DataUtility.GetString( pSource, "name" );
  94. mType = DataUtility.GetString( pSource, "user-type" );
  95. mPassword = DataUtility.GetString( pSource, "password" );
  96. XmlElement vDescription = ( XmlElement )pSource.SelectSingleNode( "lz:description", PersistenceConfig.Namespaces );
  97. if ( vDescription != null )
  98. {
  99. mDescription = vDescription.InnerText;
  100. }
  101. XmlElement vRoles = ( XmlElement )pSource.SelectSingleNode( "lz:roles", PersistenceConfig.Namespaces );
  102. if ( vRoles != null )
  103. {
  104. mRoles.LoadXml( vRoles );
  105. }
  106. }
  107. public override XmlElement SaveXml( XmlDocument p_docContext )
  108. {
  109. XmlElement vNewElement = p_docContext.CreateElement( "lz", "user", "http://schemas.icitadel.com/Lazarus/Source.xsd" );
  110. // Scalar Values
  111. if ( !String.IsNullOrEmpty( mName ) )
  112. {
  113. vNewElement.SetAttribute( "name", mName );
  114. }
  115. if ( !String.IsNullOrEmpty( mType ) )
  116. {
  117. vNewElement.SetAttribute( "user-type", mType );
  118. }
  119. if ( !String.IsNullOrEmpty( mPassword ) )
  120. {
  121. vNewElement.SetAttribute( "password", mPassword );
  122. }
  123. if ( !String.IsNullOrEmpty( mDescription ) )
  124. {
  125. XmlElement vDescription = p_docContext.CreateElement( "lz", "description", "http://schemas.icitadel.com/Lazarus/Source.xsd" );
  126. vDescription.InnerText = mDescription;
  127. vNewElement.AppendChild( vDescription );
  128. }
  129. // Collections
  130. XmlElement vCollection = null;
  131. vCollection = mRoles.SaveXml( p_docContext );
  132. if ( vCollection != null )
  133. {
  134. vNewElement.AppendChild( vCollection );
  135. }
  136. return ( vNewElement );
  137. }
  138. public virtual object Clone()
  139. {
  140. Derived.UserDetail v_oReturn = new Derived.UserDetail();
  141. v_oReturn.Name = mName;
  142. v_oReturn.Type = mType;
  143. v_oReturn.Password = mPassword;
  144. v_oReturn.Description = mDescription;
  145. // FK Values
  146. // Collections
  147. foreach ( Derived.RoleDetail vDetail in mRoles )
  148. {
  149. v_oReturn.Roles.Add( vDetail.CloneTyped() );
  150. }
  151. return ( v_oReturn );
  152. }
  153. public virtual Derived.UserDetail CloneTyped()
  154. {
  155. return ( ( Derived.UserDetail )this.Clone() );
  156. }
  157. }
  158. }