Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / Web / Util / ProviderUtil.cs / 1305376 / ProviderUtil.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * Sec * * Copyright (c) 1998-1999, Microsoft Corporation * */ namespace System.Web.Util { using System.Collections.Specialized; using System.Web.Mail; using System.Configuration; using System.Globalization; internal static class ProviderUtil { internal const int Infinite = Int32.MaxValue; internal static void GetAndRemoveStringAttribute(NameValueCollection config, string attrib, string providerName, ref string val) { val = config.Get(attrib); config.Remove(attrib); } internal static void GetAndRemovePositiveAttribute(NameValueCollection config, string attrib, string providerName, ref int val) { GetPositiveAttribute(config, attrib, providerName, ref val); config.Remove(attrib); } internal static void GetPositiveAttribute(NameValueCollection config, string attrib, string providerName, ref int val) { string s = config.Get(attrib); int t; if (s == null) { return; } try { t = Convert.ToInt32(s, CultureInfo.InvariantCulture); } catch (Exception e){ if (e is ArgumentException || e is FormatException || e is OverflowException) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_provider_positive_attributes, attrib, providerName)); } else { throw; } } if (t < 0) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_provider_positive_attributes, attrib, providerName)); } val = t; } internal static void GetAndRemovePositiveOrInfiniteAttribute(NameValueCollection config, string attrib, string providerName, ref int val) { GetPositiveOrInfiniteAttribute(config, attrib, providerName, ref val); config.Remove(attrib); } internal static void GetPositiveOrInfiniteAttribute(NameValueCollection config, string attrib, string providerName, ref int val) { string s = config.Get(attrib); int t; if (s == null) { return; } if (s == "Infinite") { t = ProviderUtil.Infinite; } else { try { t = Convert.ToInt32(s, CultureInfo.InvariantCulture); } catch (Exception e){ if (e is ArgumentException || e is FormatException || e is OverflowException) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_provider_positive_attributes, attrib, providerName)); } else { throw; } } if (t < 0) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_provider_positive_attributes, attrib, providerName)); } } val = t; } internal static void GetAndRemoveNonZeroPositiveOrInfiniteAttribute(NameValueCollection config, string attrib, string providerName, ref int val) { GetNonZeroPositiveOrInfiniteAttribute(config, attrib, providerName, ref val); config.Remove(attrib); } internal static void GetNonZeroPositiveOrInfiniteAttribute(NameValueCollection config, string attrib, string providerName, ref int val) { string s = config.Get(attrib); int t; if (s == null) { return; } if (s == "Infinite") { t = ProviderUtil.Infinite; } else { try { t = Convert.ToInt32(s, CultureInfo.InvariantCulture); } catch (Exception e){ if (e is ArgumentException || e is FormatException || e is OverflowException) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_provider_non_zero_positive_attributes, attrib, providerName)); } else { throw; } } if (t <= 0) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_provider_non_zero_positive_attributes, attrib, providerName)); } } val = t; } internal static void GetAndRemoveBooleanAttribute(NameValueCollection config, string attrib, string providerName, ref bool val) { GetBooleanAttribute(config, attrib, providerName, ref val); config.Remove(attrib); } internal static void GetBooleanAttribute(NameValueCollection config, string attrib, string providerName, ref bool val) { string s = config.Get(attrib); if (s == null) { return; } if (s == "true") { val = true; } else if (s == "false") { val = false; } else { throw new ConfigurationErrorsException(SR.GetString(SR.Invalid_provider_attribute, attrib, providerName, s)); } } internal static void GetAndRemoveRequiredNonEmptyStringAttribute(NameValueCollection config, string attrib, string providerName, ref string val) { GetRequiredNonEmptyStringAttribute(config, attrib, providerName, ref val); config.Remove(attrib); } internal static void GetRequiredNonEmptyStringAttribute(NameValueCollection config, string attrib, string providerName, ref string val) { GetNonEmptyStringAttributeInternal(config, attrib, providerName, ref val, true); } private static void GetNonEmptyStringAttributeInternal(NameValueCollection config, string attrib, string providerName, ref string val, bool required) { string s = config.Get(attrib); // If it's (null and required) -OR- (empty string) we throw if ((s == null && required) || (s.Length == 0)) { throw new ConfigurationErrorsException( SR.GetString(SR.Provider_missing_attribute, attrib, providerName)); } val = s; } internal static void CheckUnrecognizedAttributes(NameValueCollection config, string providerName) { if (config.Count > 0) { string attribUnrecognized = config.GetKey(0); if (!String.IsNullOrEmpty(attribUnrecognized)) throw new ConfigurationErrorsException( SR.GetString(SR.Unexpected_provider_attribute, attribUnrecognized, providerName)); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* * Sec * * Copyright (c) 1998-1999, Microsoft Corporation * */ namespace System.Web.Util { using System.Collections.Specialized; using System.Web.Mail; using System.Configuration; using System.Globalization; internal static class ProviderUtil { internal const int Infinite = Int32.MaxValue; internal static void GetAndRemoveStringAttribute(NameValueCollection config, string attrib, string providerName, ref string val) { val = config.Get(attrib); config.Remove(attrib); } internal static void GetAndRemovePositiveAttribute(NameValueCollection config, string attrib, string providerName, ref int val) { GetPositiveAttribute(config, attrib, providerName, ref val); config.Remove(attrib); } internal static void GetPositiveAttribute(NameValueCollection config, string attrib, string providerName, ref int val) { string s = config.Get(attrib); int t; if (s == null) { return; } try { t = Convert.ToInt32(s, CultureInfo.InvariantCulture); } catch (Exception e){ if (e is ArgumentException || e is FormatException || e is OverflowException) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_provider_positive_attributes, attrib, providerName)); } else { throw; } } if (t < 0) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_provider_positive_attributes, attrib, providerName)); } val = t; } internal static void GetAndRemovePositiveOrInfiniteAttribute(NameValueCollection config, string attrib, string providerName, ref int val) { GetPositiveOrInfiniteAttribute(config, attrib, providerName, ref val); config.Remove(attrib); } internal static void GetPositiveOrInfiniteAttribute(NameValueCollection config, string attrib, string providerName, ref int val) { string s = config.Get(attrib); int t; if (s == null) { return; } if (s == "Infinite") { t = ProviderUtil.Infinite; } else { try { t = Convert.ToInt32(s, CultureInfo.InvariantCulture); } catch (Exception e){ if (e is ArgumentException || e is FormatException || e is OverflowException) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_provider_positive_attributes, attrib, providerName)); } else { throw; } } if (t < 0) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_provider_positive_attributes, attrib, providerName)); } } val = t; } internal static void GetAndRemoveNonZeroPositiveOrInfiniteAttribute(NameValueCollection config, string attrib, string providerName, ref int val) { GetNonZeroPositiveOrInfiniteAttribute(config, attrib, providerName, ref val); config.Remove(attrib); } internal static void GetNonZeroPositiveOrInfiniteAttribute(NameValueCollection config, string attrib, string providerName, ref int val) { string s = config.Get(attrib); int t; if (s == null) { return; } if (s == "Infinite") { t = ProviderUtil.Infinite; } else { try { t = Convert.ToInt32(s, CultureInfo.InvariantCulture); } catch (Exception e){ if (e is ArgumentException || e is FormatException || e is OverflowException) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_provider_non_zero_positive_attributes, attrib, providerName)); } else { throw; } } if (t <= 0) { throw new ConfigurationErrorsException( SR.GetString(SR.Invalid_provider_non_zero_positive_attributes, attrib, providerName)); } } val = t; } internal static void GetAndRemoveBooleanAttribute(NameValueCollection config, string attrib, string providerName, ref bool val) { GetBooleanAttribute(config, attrib, providerName, ref val); config.Remove(attrib); } internal static void GetBooleanAttribute(NameValueCollection config, string attrib, string providerName, ref bool val) { string s = config.Get(attrib); if (s == null) { return; } if (s == "true") { val = true; } else if (s == "false") { val = false; } else { throw new ConfigurationErrorsException(SR.GetString(SR.Invalid_provider_attribute, attrib, providerName, s)); } } internal static void GetAndRemoveRequiredNonEmptyStringAttribute(NameValueCollection config, string attrib, string providerName, ref string val) { GetRequiredNonEmptyStringAttribute(config, attrib, providerName, ref val); config.Remove(attrib); } internal static void GetRequiredNonEmptyStringAttribute(NameValueCollection config, string attrib, string providerName, ref string val) { GetNonEmptyStringAttributeInternal(config, attrib, providerName, ref val, true); } private static void GetNonEmptyStringAttributeInternal(NameValueCollection config, string attrib, string providerName, ref string val, bool required) { string s = config.Get(attrib); // If it's (null and required) -OR- (empty string) we throw if ((s == null && required) || (s.Length == 0)) { throw new ConfigurationErrorsException( SR.GetString(SR.Provider_missing_attribute, attrib, providerName)); } val = s; } internal static void CheckUnrecognizedAttributes(NameValueCollection config, string providerName) { if (config.Count > 0) { string attribUnrecognized = config.GetKey(0); if (!String.IsNullOrEmpty(attribUnrecognized)) throw new ConfigurationErrorsException( SR.GetString(SR.Unexpected_provider_attribute, attribUnrecognized, providerName)); } } } } // 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
- CounterSet.cs
- AnimationStorage.cs
- XsltException.cs
- UdpDiscoveryEndpointElement.cs
- UTF32Encoding.cs
- LinqDataSourceEditData.cs
- XPathAncestorQuery.cs
- RemotingService.cs
- CurrentTimeZone.cs
- ExtensionWindowResizeGrip.cs
- AsymmetricSignatureFormatter.cs
- TemplateField.cs
- XsltContext.cs
- HitTestDrawingContextWalker.cs
- DataStreams.cs
- externdll.cs
- DbMetaDataFactory.cs
- ResolvedKeyFrameEntry.cs
- WMIGenerator.cs
- SimpleTypeResolver.cs
- CompilerHelpers.cs
- ContentPosition.cs
- FilterQuery.cs
- Compensate.cs
- ToolBarButtonClickEvent.cs
- UrlMapping.cs
- Substitution.cs
- HybridObjectCache.cs
- DataTablePropertyDescriptor.cs
- CSharpCodeProvider.cs
- PropertyGridCommands.cs
- ApplicationCommands.cs
- ExtendedProtectionPolicy.cs
- DoubleAnimationClockResource.cs
- BamlReader.cs
- DescendantBaseQuery.cs
- ChunkedMemoryStream.cs
- WaitHandle.cs
- WindowsStartMenu.cs
- DomNameTable.cs
- RecordConverter.cs
- ImageSource.cs
- DispatcherHooks.cs
- ButtonFlatAdapter.cs
- WebPartVerbsEventArgs.cs
- MissingMemberException.cs
- AssemblyHash.cs
- AspNetSynchronizationContext.cs
- CodeThrowExceptionStatement.cs
- SafeThemeHandle.cs
- LayoutEvent.cs
- StylusPointProperties.cs
- InputProcessorProfilesLoader.cs
- OutputWindow.cs
- WorkflowServiceHostFactory.cs
- IteratorDescriptor.cs
- ToolboxItemImageConverter.cs
- DirectoryObjectSecurity.cs
- SqlClientMetaDataCollectionNames.cs
- IntMinMaxAggregationOperator.cs
- DirectoryInfo.cs
- IconConverter.cs
- BitmapSizeOptions.cs
- RegexCharClass.cs
- XmlSubtreeReader.cs
- DataSourceComponent.cs
- TemplateControl.cs
- SoapAttributeOverrides.cs
- HtmlHistory.cs
- PropertyEntry.cs
- XmlDocumentType.cs
- DigitalSignatureProvider.cs
- BidirectionalDictionary.cs
- BaseDataBoundControl.cs
- ResourceDescriptionAttribute.cs
- Cloud.cs
- AssemblyEvidenceFactory.cs
- Msmq.cs
- SchemaTableColumn.cs
- VariantWrapper.cs
- ReliableSessionElement.cs
- Line.cs
- Duration.cs
- PassportPrincipal.cs
- PageParser.cs
- QuaternionAnimation.cs
- DateTimeUtil.cs
- TableDesigner.cs
- ContextMenuAutomationPeer.cs
- DataTemplate.cs
- EntityStoreSchemaGenerator.cs
- AnnotationComponentChooser.cs
- DrawingContextWalker.cs
- TextLine.cs
- WindowsBrush.cs
- Point3DCollectionValueSerializer.cs
- MatrixStack.cs
- TitleStyle.cs
- CodeSnippetStatement.cs
- AlignmentXValidation.cs