FindCriteriaElement.cs 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. //
  2. // Author: Atsushi Enomoto <[email protected]>
  3. //
  4. // Copyright (C) 2010 Novell, Inc (http://www.novell.com)
  5. //
  6. // Permission is hereby granted, free of charge, to any person obtaining
  7. // a copy of this software and associated documentation files (the
  8. // "Software"), to deal in the Software without restriction, including
  9. // without limitation the rights to use, copy, modify, merge, publish,
  10. // distribute, sublicense, and/or sell copies of the Software, and to
  11. // permit persons to whom the Software is furnished to do so, subject to
  12. // the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be
  15. // included in all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  18. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  19. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  20. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  21. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  22. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  23. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  24. //
  25. #if NET_4_0
  26. using System;
  27. using System.ComponentModel;
  28. using System.Configuration;
  29. using System.ServiceModel.Configuration;
  30. using System.Xml;
  31. using System.Xml.Linq;
  32. namespace System.ServiceModel.Discovery.Configuration
  33. {
  34. public sealed class FindCriteriaElement : ConfigurationElement
  35. {
  36. static ConfigurationPropertyCollection properties;
  37. static ConfigurationProperty types, duration, extensions, max_results, scope_match_by, scopes;
  38. static FindCriteriaElement ()
  39. {
  40. types = new ConfigurationProperty ("types", typeof (ContractTypeNameElementCollection), null, null, null, ConfigurationPropertyOptions.None);
  41. duration = new ConfigurationProperty ("duration", typeof (TimeSpan), "00:00:20", new TimeSpanConverter (), null, ConfigurationPropertyOptions.None);
  42. extensions = new ConfigurationProperty ("extensions", typeof (XmlElementElementCollection), null, null, null, ConfigurationPropertyOptions.None);
  43. max_results = new ConfigurationProperty ("maxResults", typeof (TimeSpan), "00:00:20", new TimeSpanConverter (), null, ConfigurationPropertyOptions.None);
  44. scope_match_by = new ConfigurationProperty ("scopeMatchBy", typeof (Uri), null, null, null, ConfigurationPropertyOptions.None);
  45. scopes = new ConfigurationProperty ("scopes", typeof (ScopeElementCollection), null, null, null, ConfigurationPropertyOptions.None);
  46. properties = new ConfigurationPropertyCollection ();
  47. properties.Add (types);
  48. properties.Add (duration);
  49. properties.Add (extensions);
  50. properties.Add (max_results);
  51. properties.Add (scope_match_by);
  52. properties.Add (scopes);
  53. }
  54. public FindCriteriaElement ()
  55. {
  56. }
  57. [ConfigurationProperty ("types")]
  58. public ContractTypeNameElementCollection ContractTypeNames {
  59. get { return (ContractTypeNameElementCollection) base [types]; }
  60. }
  61. [ConfigurationProperty ("duration", DefaultValue = "00:00:20")]
  62. [TypeConverter (typeof (TimeSpanConverter))]
  63. public TimeSpan Duration {
  64. get { return (TimeSpan) base [duration]; }
  65. set { base [duration] = value; }
  66. }
  67. [ConfigurationProperty ("extensions")]
  68. public XmlElementElementCollection Extensions {
  69. get { return (XmlElementElementCollection) base [extensions]; }
  70. }
  71. [ConfigurationProperty ("maxResults", DefaultValue = 0)]
  72. [IntegerValidator (MinValue = 0, MaxValue = int.MaxValue)]
  73. public int MaxResults {
  74. get { return (int) base [max_results]; }
  75. set { base [max_results] = value; }
  76. }
  77. [ConfigurationProperty ("scopeMatchBy")]
  78. public Uri ScopeMatchBy {
  79. get { return (Uri) base [scope_match_by]; }
  80. set { base [scope_match_by] = value; }
  81. }
  82. [ConfigurationProperty ("scopes")]
  83. public ScopeElementCollection Scopes {
  84. get { return (ScopeElementCollection) base [scopes]; }
  85. }
  86. protected override ConfigurationPropertyCollection Properties {
  87. get { return properties; }
  88. }
  89. internal FindCriteria CreateInstance ()
  90. {
  91. var fc = new FindCriteria ();
  92. foreach (ContractTypeNameElement ctn in ContractTypeNames)
  93. fc.ContractTypeNames.Add (new XmlQualifiedName (ctn.Name, ctn.Namespace));
  94. fc.Duration = Duration;
  95. foreach (XmlElementElement ext in Extensions)
  96. fc.Extensions.Add (XElement.Load (new XmlNodeReader (ext.XmlElement)));
  97. fc.MaxResults = MaxResults;
  98. fc.ScopeMatchBy = ScopeMatchBy;
  99. foreach (ScopeElement scope in Scopes)
  100. fc.Scopes.Add (scope.Scope);
  101. return fc;
  102. }
  103. internal void CopyFrom (FindCriteriaElement other)
  104. {
  105. foreach (ContractTypeNameElement ctn in other.ContractTypeNames)
  106. ContractTypeNames.Add (new ContractTypeNameElement () { Name = ctn.Name, Namespace = ctn.Namespace });
  107. Duration = other.Duration;
  108. foreach (XmlElementElement ext in other.Extensions)
  109. Extensions.Add (new XmlElementElement () { XmlElement = (XmlElement) ext.XmlElement.CloneNode (true) });
  110. MaxResults = other.MaxResults;
  111. ScopeMatchBy = other.ScopeMatchBy;
  112. foreach (ScopeElement scope in other.Scopes)
  113. Scopes.Add (new ScopeElement () { Scope = scope.Scope });
  114. }
  115. }
  116. }
  117. #endif