| | | 1 | | // Licensed to the .NET Foundation under one or more agreements. |
| | | 2 | | // The .NET Foundation licenses this file to you under the MIT license. |
| | | 3 | | |
| | | 4 | | using System; |
| | | 5 | | using System.Xml; |
| | | 6 | | using CoreWCF.Description; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Channels |
| | | 9 | | { |
| | | 10 | | public sealed class PrivacyNoticeBindingElement : BindingElement, IPolicyExportExtension |
| | | 11 | | { |
| | | 12 | | private Uri _url; |
| | | 13 | | private int _version; |
| | | 14 | | |
| | 0 | 15 | | public PrivacyNoticeBindingElement() |
| | | 16 | | { |
| | 0 | 17 | | _url = null; |
| | 0 | 18 | | } |
| | | 19 | | |
| | | 20 | | public PrivacyNoticeBindingElement(PrivacyNoticeBindingElement elementToBeCloned) |
| | 0 | 21 | | : base(elementToBeCloned) |
| | | 22 | | { |
| | 0 | 23 | | _url = elementToBeCloned._url; |
| | 0 | 24 | | _version = elementToBeCloned._version; |
| | 0 | 25 | | } |
| | | 26 | | |
| | | 27 | | public Uri Url |
| | | 28 | | { |
| | | 29 | | get |
| | | 30 | | { |
| | 0 | 31 | | return _url; |
| | | 32 | | } |
| | | 33 | | set |
| | | 34 | | { |
| | 0 | 35 | | if (value == null) |
| | | 36 | | { |
| | 0 | 37 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(value)); |
| | | 38 | | } |
| | | 39 | | |
| | 0 | 40 | | _url = value; |
| | 0 | 41 | | } |
| | | 42 | | } |
| | | 43 | | |
| | | 44 | | public int Version |
| | | 45 | | { |
| | | 46 | | get |
| | | 47 | | { |
| | 0 | 48 | | return _version; |
| | | 49 | | } |
| | | 50 | | set |
| | | 51 | | { |
| | 0 | 52 | | if (value < 0) |
| | | 53 | | { |
| | 0 | 54 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException(nameof(val |
| | 0 | 55 | | SR.Format(SRCommon.ValueMustBePositive))); |
| | | 56 | | } |
| | 0 | 57 | | _version = value; |
| | 0 | 58 | | } |
| | | 59 | | } |
| | | 60 | | |
| | | 61 | | public override BindingElement Clone() |
| | | 62 | | { |
| | 0 | 63 | | return new PrivacyNoticeBindingElement(this); |
| | | 64 | | } |
| | | 65 | | |
| | | 66 | | public override T GetProperty<T>(BindingContext context) |
| | | 67 | | { |
| | 0 | 68 | | if (context == null) |
| | | 69 | | { |
| | 0 | 70 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context)); |
| | | 71 | | } |
| | 0 | 72 | | return context.GetInnerProperty<T>(); |
| | | 73 | | } |
| | | 74 | | |
| | | 75 | | void IPolicyExportExtension.ExportPolicy(MetadataExporter exporter, PolicyConversionContext context) |
| | | 76 | | { |
| | 0 | 77 | | if (context == null) |
| | 0 | 78 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull(nameof(context)); |
| | | 79 | | |
| | 0 | 80 | | if (context.BindingElements != null) |
| | | 81 | | { |
| | 0 | 82 | | PrivacyNoticeBindingElement settings = |
| | 0 | 83 | | context.BindingElements.Find<PrivacyNoticeBindingElement>(); |
| | | 84 | | |
| | 0 | 85 | | if (settings != null) |
| | | 86 | | { |
| | 0 | 87 | | XmlDocument doc = new XmlDocument(); |
| | | 88 | | |
| | | 89 | | // PrivacyNotice assertion |
| | 0 | 90 | | XmlElement assertion = doc.CreateElement(PrivacyNoticePolicyStrings.PrivacyNoticePrefix, |
| | 0 | 91 | | PrivacyNoticePolicyStrings.PrivacyNoticeName, |
| | 0 | 92 | | PrivacyNoticePolicyStrings.PrivacyNoticeNamespace); |
| | | 93 | | |
| | 0 | 94 | | assertion.InnerText = settings.Url.ToString(); |
| | 0 | 95 | | assertion.SetAttribute(PrivacyNoticePolicyStrings.PrivacyNoticeVersionAttributeName, PrivacyNoticePo |
| | | 96 | | |
| | 0 | 97 | | context.GetBindingAssertions().Add(assertion); |
| | | 98 | | } |
| | | 99 | | } |
| | 0 | 100 | | } |
| | | 101 | | |
| | | 102 | | protected override bool IsMatch(BindingElement b) |
| | | 103 | | { |
| | 0 | 104 | | if (b == null) |
| | 0 | 105 | | return false; |
| | 0 | 106 | | PrivacyNoticeBindingElement privacy = b as PrivacyNoticeBindingElement; |
| | 0 | 107 | | if (privacy == null) |
| | 0 | 108 | | return false; |
| | 0 | 109 | | return (_url == privacy._url && _version == privacy._version); |
| | | 110 | | } |
| | | 111 | | } |
| | | 112 | | } |