Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Configuration / System / Configuration / updateconfighost.cs / 1305376 / updateconfighost.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Configuration { using System.Collections.Specialized; using System.Configuration.Internal; using System.IO; // // Configuration host that intercepts calls to filename functions // to support SaveAs to an alternate file stream. // internal class UpdateConfigHost : DelegatingConfigHost { private HybridDictionary _streams; // oldStreamname -> StreamUpdate internal UpdateConfigHost(IInternalConfigHost host) { // Delegate to the host provided. Host = host; } // Add a stream to the list of streams to intercept. // // Parameters: // alwaysIntercept - If true, then don't check whether the old stream and the new stream are the same. // SaveAs() will set this to true if oldStreamname is actually referring to a stream // on a remote machine. internal void AddStreamname(string oldStreamname, string newStreamname, bool alwaysIntercept) { // Debug.Assert(!String.IsNullOrEmpty(oldStreamname)); if (String.IsNullOrEmpty(oldStreamname)) { return; } if (!alwaysIntercept && StringUtil.EqualsIgnoreCase(oldStreamname, newStreamname)) { return; } if (_streams == null) { _streams = new HybridDictionary(true); } _streams[oldStreamname] = new StreamUpdate(newStreamname); } // Get the new stream name for a stream if a new name exists, otherwise // return the original stream name. internal string GetNewStreamname(string oldStreamname) { StreamUpdate streamUpdate = GetStreamUpdate(oldStreamname, false); if (streamUpdate != null) { return streamUpdate.NewStreamname; } return oldStreamname; } // // Get the StreamUpdate for a stream. // If alwaysIntercept is true, then the StreamUpdate is // always returned if it exists. // If alwaysIntercept is false, then only return the StreamUpdate // if the new stream has been successfully written to. // private StreamUpdate GetStreamUpdate(string oldStreamname, bool alwaysIntercept) { if (_streams == null) return null; StreamUpdate streamUpdate = (StreamUpdate) _streams[oldStreamname]; if (streamUpdate != null && !alwaysIntercept && !streamUpdate.WriteCompleted) { streamUpdate = null; } return streamUpdate; } public override object GetStreamVersion(string streamName) { StreamUpdate streamUpdate = GetStreamUpdate(streamName, false); if (streamUpdate != null) { return InternalConfigHost.StaticGetStreamVersion(streamUpdate.NewStreamname); } else { return Host.GetStreamVersion(streamName); } } public override Stream OpenStreamForRead(string streamName) { StreamUpdate streamUpdate = GetStreamUpdate(streamName, false); if (streamUpdate != null) { return InternalConfigHost.StaticOpenStreamForRead(streamUpdate.NewStreamname); } else { return Host.OpenStreamForRead(streamName); } } public override Stream OpenStreamForWrite(string streamName, string templateStreamName, ref object writeContext) { // Always attempt to write to the new stream name if it exists. StreamUpdate streamUpdate = GetStreamUpdate(streamName, true); if (streamUpdate != null) { return InternalConfigHost.StaticOpenStreamForWrite(streamUpdate.NewStreamname, templateStreamName, ref writeContext, false); } else { return Host.OpenStreamForWrite(streamName, templateStreamName, ref writeContext); } } public override void WriteCompleted(string streamName, bool success, object writeContext) { StreamUpdate streamUpdate = GetStreamUpdate(streamName, true); if (streamUpdate != null) { InternalConfigHost.StaticWriteCompleted(streamUpdate.NewStreamname, success, writeContext, false); // // Mark the write as having successfully completed, so that subsequent calls // to Read() will use the new stream name. // if (success) { streamUpdate.WriteCompleted = true; } } else { Host.WriteCompleted(streamName, success, writeContext); } } public override bool IsConfigRecordRequired(string configPath) { return true; } public override void DeleteStream(string streamName) { StreamUpdate streamUpdate = GetStreamUpdate(streamName, false); if (streamUpdate != null) { InternalConfigHost.StaticDeleteStream(streamUpdate.NewStreamname); } else { Host.DeleteStream(streamName); } } public override bool IsFile(string streamName) { StreamUpdate streamUpdate = GetStreamUpdate(streamName, false); if (streamUpdate != null) { return InternalConfigHost.StaticIsFile(streamUpdate.NewStreamname); } else { return Host.IsFile(streamName); } } } } // 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
- PassportPrincipal.cs
- DataContractJsonSerializer.cs
- SupportingTokenSpecification.cs
- Intellisense.cs
- DataSetUtil.cs
- TableRowCollection.cs
- TileBrush.cs
- AsymmetricKeyExchangeDeformatter.cs
- ReadWriteControlDesigner.cs
- RegionIterator.cs
- IfElseDesigner.xaml.cs
- cookieexception.cs
- OleDbConnectionPoolGroupProviderInfo.cs
- Models.cs
- MenuItemBindingCollection.cs
- MouseButtonEventArgs.cs
- ImageMap.cs
- Utilities.cs
- URL.cs
- RoleGroup.cs
- OdbcPermission.cs
- SqlDelegatedTransaction.cs
- BrowsableAttribute.cs
- MobileControlDesigner.cs
- CheckBoxStandardAdapter.cs
- querybuilder.cs
- PersonalizationAdministration.cs
- GenericUriParser.cs
- Misc.cs
- Compilation.cs
- DocumentXmlWriter.cs
- EditorZone.cs
- HtmlTableRow.cs
- DataGridViewCellConverter.cs
- AxHost.cs
- VisualProxy.cs
- WebPartZoneBase.cs
- SystemResources.cs
- StructuredTypeEmitter.cs
- HtmlMeta.cs
- DocumentSequenceHighlightLayer.cs
- controlskin.cs
- ListViewGroup.cs
- Scalars.cs
- GridViewSortEventArgs.cs
- NullableConverter.cs
- AppearanceEditorPart.cs
- _ListenerAsyncResult.cs
- BitArray.cs
- LogPolicy.cs
- SmiSettersStream.cs
- LineVisual.cs
- _ListenerAsyncResult.cs
- CodeEventReferenceExpression.cs
- NativeMethods.cs
- InstanceNotReadyException.cs
- DisplayInformation.cs
- HttpConfigurationSystem.cs
- Triplet.cs
- CapabilitiesSection.cs
- WebPartZoneBase.cs
- Char.cs
- DataStreams.cs
- TypeSystem.cs
- DataTableMappingCollection.cs
- RuntimeCompatibilityAttribute.cs
- TextBlock.cs
- SqlDataSourceCustomCommandPanel.cs
- XmlSortKeyAccumulator.cs
- ListViewItemEventArgs.cs
- DesignUtil.cs
- Clipboard.cs
- LayoutSettings.cs
- Transform3DGroup.cs
- EventPropertyMap.cs
- RedistVersionInfo.cs
- TextComposition.cs
- DefaultTraceListener.cs
- ImageListImage.cs
- PropertiesTab.cs
- GenericTextProperties.cs
- WS2007FederationHttpBinding.cs
- TabItem.cs
- DesignTimeParseData.cs
- XsltSettings.cs
- SafeLibraryHandle.cs
- StrongNameHelpers.cs
- ScrollViewer.cs
- HttpServerUtilityWrapper.cs
- SqlTriggerContext.cs
- CustomAssemblyResolver.cs
- XmlEncoding.cs
- ConfigXmlElement.cs
- Propagator.JoinPropagator.cs
- TemplateBuilder.cs
- HtmlProps.cs
- DefaultTextStoreTextComposition.cs
- LocationReference.cs
- X509Certificate2.cs
- PhoneCall.cs