Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / whidbey / NetFxQFE / ndp / fx / src / Net / System / Net / Configuration / SmtpNetworkElement.cs / 1 / SmtpNetworkElement.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Net.Configuration { using System; using System.Configuration; using System.Net; using System.Net.Mail; using System.Reflection; using System.Security.Permissions; public sealed class SmtpNetworkElement : ConfigurationElement { public SmtpNetworkElement() { this.properties.Add(this.defaultCredentials); this.properties.Add(this.host); this.properties.Add(this.password); this.properties.Add(this.port); this.properties.Add(this.userName); } protected override void PostDeserialize() { // Perf optimization. If the configuration is coming from machine.config // It is safe and we don't need to check for permissions. if (EvaluationContext.IsMachineLevel) return; PropertyInformation portPropertyInfo = ElementInformation.Properties[ConfigurationStrings.Port]; if (portPropertyInfo.ValueOrigin == PropertyValueOrigin.SetHere && (int)portPropertyInfo.Value != (int)portPropertyInfo.DefaultValue) { try { (new SmtpPermission(SmtpAccess.ConnectToUnrestrictedPort)).Demand(); } catch (Exception exception) { throw new ConfigurationErrorsException( SR.GetString(SR.net_config_property_permission, portPropertyInfo.Name), exception); } } } protected override ConfigurationPropertyCollection Properties { get { return this.properties; } } [ConfigurationProperty(ConfigurationStrings.DefaultCredentials, DefaultValue = false)] public bool DefaultCredentials { get { return (bool)this[this.defaultCredentials]; } set { this[this.defaultCredentials] = value; } } [ConfigurationProperty(ConfigurationStrings.Host)] public string Host { get { return (string)this[this.host]; } set { this[this.host] = value; } } [ConfigurationProperty(ConfigurationStrings.Password)] public string Password { get { return (string)this[this.password]; } set { this[this.password] = value; } } [ConfigurationProperty(ConfigurationStrings.Port, DefaultValue = 25)] public int Port { get { return (int)this[this.port]; } set { // this[this.port] = value; } } [ConfigurationProperty(ConfigurationStrings.UserName)] public string UserName { get { return (string)this[this.userName]; } set { this[this.userName] = value; } } // ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection(); readonly ConfigurationProperty defaultCredentials = new ConfigurationProperty(ConfigurationStrings.DefaultCredentials, typeof(bool), false, ConfigurationPropertyOptions.None); readonly ConfigurationProperty host = new ConfigurationProperty(ConfigurationStrings.Host, typeof(string), null, ConfigurationPropertyOptions.None); readonly ConfigurationProperty password = new ConfigurationProperty(ConfigurationStrings.Password, typeof(string), null, ConfigurationPropertyOptions.None); readonly ConfigurationProperty port = new ConfigurationProperty(ConfigurationStrings.Port, typeof(int), 25, null, new IntegerValidator(IPEndPoint.MinPort+1, IPEndPoint.MaxPort), ConfigurationPropertyOptions.None); readonly ConfigurationProperty userName = new ConfigurationProperty(ConfigurationStrings.UserName, typeof(string), null, ConfigurationPropertyOptions.None); } internal sealed class SmtpNetworkElementInternal { internal SmtpNetworkElementInternal(SmtpNetworkElement element) { this.host = element.Host; this.port = element.Port; if (element.DefaultCredentials) { this.credential = (NetworkCredential)CredentialCache.DefaultCredentials; } else if (element.UserName != null && element.UserName.Length > 0) { this.credential = new NetworkCredential(element.UserName, element.Password); } } internal NetworkCredential Credential { get { return this.credential; } } internal string Host { get { return this.host; } } internal int Port { get { return this.port; } } string host; int port; NetworkCredential credential = null; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Net.Configuration { using System; using System.Configuration; using System.Net; using System.Net.Mail; using System.Reflection; using System.Security.Permissions; public sealed class SmtpNetworkElement : ConfigurationElement { public SmtpNetworkElement() { this.properties.Add(this.defaultCredentials); this.properties.Add(this.host); this.properties.Add(this.password); this.properties.Add(this.port); this.properties.Add(this.userName); } protected override void PostDeserialize() { // Perf optimization. If the configuration is coming from machine.config // It is safe and we don't need to check for permissions. if (EvaluationContext.IsMachineLevel) return; PropertyInformation portPropertyInfo = ElementInformation.Properties[ConfigurationStrings.Port]; if (portPropertyInfo.ValueOrigin == PropertyValueOrigin.SetHere && (int)portPropertyInfo.Value != (int)portPropertyInfo.DefaultValue) { try { (new SmtpPermission(SmtpAccess.ConnectToUnrestrictedPort)).Demand(); } catch (Exception exception) { throw new ConfigurationErrorsException( SR.GetString(SR.net_config_property_permission, portPropertyInfo.Name), exception); } } } protected override ConfigurationPropertyCollection Properties { get { return this.properties; } } [ConfigurationProperty(ConfigurationStrings.DefaultCredentials, DefaultValue = false)] public bool DefaultCredentials { get { return (bool)this[this.defaultCredentials]; } set { this[this.defaultCredentials] = value; } } [ConfigurationProperty(ConfigurationStrings.Host)] public string Host { get { return (string)this[this.host]; } set { this[this.host] = value; } } [ConfigurationProperty(ConfigurationStrings.Password)] public string Password { get { return (string)this[this.password]; } set { this[this.password] = value; } } [ConfigurationProperty(ConfigurationStrings.Port, DefaultValue = 25)] public int Port { get { return (int)this[this.port]; } set { // this[this.port] = value; } } [ConfigurationProperty(ConfigurationStrings.UserName)] public string UserName { get { return (string)this[this.userName]; } set { this[this.userName] = value; } } // ConfigurationPropertyCollection properties = new ConfigurationPropertyCollection(); readonly ConfigurationProperty defaultCredentials = new ConfigurationProperty(ConfigurationStrings.DefaultCredentials, typeof(bool), false, ConfigurationPropertyOptions.None); readonly ConfigurationProperty host = new ConfigurationProperty(ConfigurationStrings.Host, typeof(string), null, ConfigurationPropertyOptions.None); readonly ConfigurationProperty password = new ConfigurationProperty(ConfigurationStrings.Password, typeof(string), null, ConfigurationPropertyOptions.None); readonly ConfigurationProperty port = new ConfigurationProperty(ConfigurationStrings.Port, typeof(int), 25, null, new IntegerValidator(IPEndPoint.MinPort+1, IPEndPoint.MaxPort), ConfigurationPropertyOptions.None); readonly ConfigurationProperty userName = new ConfigurationProperty(ConfigurationStrings.UserName, typeof(string), null, ConfigurationPropertyOptions.None); } internal sealed class SmtpNetworkElementInternal { internal SmtpNetworkElementInternal(SmtpNetworkElement element) { this.host = element.Host; this.port = element.Port; if (element.DefaultCredentials) { this.credential = (NetworkCredential)CredentialCache.DefaultCredentials; } else if (element.UserName != null && element.UserName.Length > 0) { this.credential = new NetworkCredential(element.UserName, element.Password); } } internal NetworkCredential Credential { get { return this.credential; } } internal string Host { get { return this.host; } } internal int Port { get { return this.port; } } string host; int port; NetworkCredential credential = null; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- FrugalList.cs
- FormViewCommandEventArgs.cs
- UInt32.cs
- Mutex.cs
- TagNameToTypeMapper.cs
- DataColumn.cs
- complextypematerializer.cs
- ImageListUtils.cs
- DocumentEventArgs.cs
- TriggerBase.cs
- WebPartConnectionsConnectVerb.cs
- __ComObject.cs
- TextFormatterHost.cs
- TargetException.cs
- AuthenticatedStream.cs
- PieceDirectory.cs
- RowUpdatedEventArgs.cs
- TextRange.cs
- BuildManagerHost.cs
- KnownTypes.cs
- JoinSymbol.cs
- MinMaxParagraphWidth.cs
- UriExt.cs
- DataColumnMappingCollection.cs
- ContactManager.cs
- QuotedPrintableStream.cs
- TextRenderer.cs
- safesecurityhelperavalon.cs
- Switch.cs
- ContainerControl.cs
- Soap12ProtocolReflector.cs
- BlobPersonalizationState.cs
- MobileControl.cs
- ProfileBuildProvider.cs
- SafePointer.cs
- BufferedGraphicsManager.cs
- VisualBrush.cs
- TraceHwndHost.cs
- DbConnectionInternal.cs
- XmlAttribute.cs
- DefinitionBase.cs
- Floater.cs
- TemplateComponentConnector.cs
- FormViewUpdatedEventArgs.cs
- XmlSchemaSimpleTypeRestriction.cs
- TimeEnumHelper.cs
- VisualStyleRenderer.cs
- ServiceModelDictionary.cs
- _BufferOffsetSize.cs
- LineInfo.cs
- TextBoxAutomationPeer.cs
- BaseUriHelper.cs
- ImageDrawing.cs
- DebugHandleTracker.cs
- UpdateProgress.cs
- TableProvider.cs
- SecurityTokenValidationException.cs
- DnsPermission.cs
- SHA1CryptoServiceProvider.cs
- XsltFunctions.cs
- Point4DConverter.cs
- TreeViewHitTestInfo.cs
- TempFiles.cs
- KeySplineConverter.cs
- XmlAttributeCollection.cs
- BezierSegment.cs
- OdbcTransaction.cs
- CopyOnWriteList.cs
- DataChangedEventManager.cs
- XamlWriter.cs
- SpeechSeg.cs
- ContextMenuStrip.cs
- SqlDataSourceDesigner.cs
- ColorAnimationUsingKeyFrames.cs
- RsaKeyGen.cs
- QilCloneVisitor.cs
- DodSequenceMerge.cs
- SQLBytes.cs
- EventLogPermissionAttribute.cs
- HttpHandlersSection.cs
- ColumnMapTranslator.cs
- GACIdentityPermission.cs
- DbParameterCollection.cs
- SizeFConverter.cs
- TemporaryBitmapFile.cs
- DataGridSortCommandEventArgs.cs
- KeyValueSerializer.cs
- DependencyPropertyDescriptor.cs
- ErrorHandler.cs
- InitializingNewItemEventArgs.cs
- GridViewColumnHeaderAutomationPeer.cs
- ColorConvertedBitmapExtension.cs
- StorageMappingFragment.cs
- StickyNote.cs
- BamlBinaryWriter.cs
- GrammarBuilderBase.cs
- ExpressionList.cs
- SafeFileHandle.cs
- _ProxyChain.cs
- HostingEnvironmentException.cs