| | | 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.ComponentModel; |
| | | 6 | | using System.ComponentModel.Design.Serialization; |
| | | 7 | | |
| | | 8 | | namespace CoreWCF.Configuration |
| | | 9 | | { |
| | | 10 | | internal class MessageSecurityVersionConverter : TypeConverter |
| | | 11 | | { |
| | | 12 | | public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) |
| | | 13 | | { |
| | 0 | 14 | | if (typeof(string) == sourceType) |
| | | 15 | | { |
| | 0 | 16 | | return true; |
| | | 17 | | } |
| | 0 | 18 | | return base.CanConvertFrom(context, sourceType); |
| | | 19 | | } |
| | | 20 | | |
| | | 21 | | public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) |
| | | 22 | | { |
| | 0 | 23 | | if (typeof(InstanceDescriptor) == destinationType) |
| | | 24 | | { |
| | 0 | 25 | | return true; |
| | | 26 | | } |
| | 0 | 27 | | return base.CanConvertTo(context, destinationType); |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, obj |
| | | 31 | | { |
| | 3 | 32 | | if (value is string) |
| | | 33 | | { |
| | 3 | 34 | | string version = (string)value; |
| | | 35 | | MessageSecurityVersion retval; |
| | | 36 | | switch (version) |
| | | 37 | | { |
| | | 38 | | case ConfigurationStrings.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityP |
| | 0 | 39 | | retval = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005W |
| | 0 | 40 | | break; |
| | | 41 | | case ConfigurationStrings.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityP |
| | 0 | 42 | | retval = MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005W |
| | 0 | 43 | | break; |
| | | 44 | | case ConfigurationStrings.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecurityP |
| | 1 | 45 | | retval = MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005W |
| | 1 | 46 | | break; |
| | | 47 | | case ConfigurationStrings.WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurity |
| | 0 | 48 | | retval = MessageSecurityVersion.WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12Bas |
| | 0 | 49 | | break; |
| | | 50 | | case ConfigurationStrings.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12: |
| | 0 | 51 | | retval = MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12; |
| | 0 | 52 | | break; |
| | | 53 | | case ConfigurationStrings.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecurity |
| | 0 | 54 | | retval = MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12Bas |
| | 0 | 55 | | break; |
| | | 56 | | case ConfigurationStrings.Default: |
| | 2 | 57 | | retval = MessageSecurityVersion.Default; |
| | 2 | 58 | | break; |
| | | 59 | | default: |
| | 0 | 60 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value |
| | 0 | 61 | | SR.Format(SR.ConfigInvalidClassFactoryValue, version, typeof(MessageSecurityVersion).FullNam |
| | | 62 | | } |
| | 3 | 63 | | return retval; |
| | | 64 | | } |
| | 0 | 65 | | return base.ConvertFrom(context, culture, value); |
| | | 66 | | } |
| | | 67 | | |
| | | 68 | | public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, objec |
| | | 69 | | { |
| | 0 | 70 | | if (typeof(string) == destinationType && value is MessageSecurityVersion) |
| | | 71 | | { |
| | | 72 | | string retval; |
| | 0 | 73 | | MessageSecurityVersion securityVersion = (MessageSecurityVersion)value; |
| | 0 | 74 | | if (securityVersion == MessageSecurityVersion.Default) |
| | | 75 | | { |
| | 0 | 76 | | retval = ConfigurationStrings.Default; |
| | | 77 | | } |
| | 0 | 78 | | else if (securityVersion == MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFe |
| | | 79 | | { |
| | 0 | 80 | | retval = ConfigurationStrings.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecur |
| | | 81 | | } |
| | 0 | 82 | | else if (securityVersion == MessageSecurityVersion.WSSecurity10WSTrustFebruary2005WSSecureConversationFe |
| | | 83 | | { |
| | 0 | 84 | | retval = ConfigurationStrings.WSSecurity10WSTrustFebruary2005WSSecureConversationFebruary2005WSSecur |
| | | 85 | | } |
| | 0 | 86 | | else if (securityVersion == MessageSecurityVersion.WSSecurity11WSTrustFebruary2005WSSecureConversationFe |
| | | 87 | | { |
| | 0 | 88 | | retval = ConfigurationStrings.WSSecurity11WSTrustFebruary2005WSSecureConversationFebruary2005WSSecur |
| | | 89 | | } |
| | 0 | 90 | | else if (securityVersion == MessageSecurityVersion.WSSecurity10WSTrust13WSSecureConversation13WSSecurity |
| | | 91 | | { |
| | 0 | 92 | | retval = ConfigurationStrings.WSSecurity10WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecu |
| | | 93 | | } |
| | 0 | 94 | | else if (securityVersion == MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13WSSecurity |
| | | 95 | | { |
| | 0 | 96 | | retval = ConfigurationStrings.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12; |
| | | 97 | | } |
| | 0 | 98 | | else if (securityVersion == MessageSecurityVersion.WSSecurity11WSTrust13WSSecureConversation13WSSecurity |
| | | 99 | | { |
| | 0 | 100 | | retval = ConfigurationStrings.WSSecurity11WSTrust13WSSecureConversation13WSSecurityPolicy12BasicSecu |
| | | 101 | | } |
| | | 102 | | else |
| | | 103 | | { |
| | 0 | 104 | | throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new ArgumentOutOfRangeException("value", |
| | 0 | 105 | | SR.Format(SR.ConfigInvalidClassInstanceValue, typeof(MessageSecurityVersion).FullName))); |
| | | 106 | | } |
| | 0 | 107 | | return retval; |
| | | 108 | | } |
| | 0 | 109 | | return base.ConvertTo(context, culture, value, destinationType); |
| | | 110 | | } |
| | | 111 | | } |
| | | 112 | | } |