Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / WCF / ServiceModel / System / ServiceModel / Channels / BufferedMessageWriter.cs / 1 / BufferedMessageWriter.cs
//------------------------------------------------------------ // Copyright (c) Microsoft Corporation. All rights reserved. //----------------------------------------------------------- namespace System.ServiceModel.Channels { using System.IO; using System.Xml; using System.Diagnostics; abstract class BufferedMessageWriter { int[] sizeHistory; int sizeHistoryIndex; const int sizeHistoryCount = 4; const int expectedSizeVariance = 256; BufferedOutputStream stream; public BufferedMessageWriter() { stream = new BufferedOutputStream(SR.MaxSentMessageSizeExceeded); InitMessagePredicter(); } protected abstract XmlDictionaryWriter TakeXmlWriter(Stream stream); protected abstract void ReturnXmlWriter(XmlDictionaryWriter writer); public ArraySegmentWriteMessage(Message message, BufferManager bufferManager, int initialOffset, int maxSizeQuota) { int effectiveMaxSize; // make sure that maxSize has room for initialOffset without overflowing, since // the effective buffer size is message size + initialOffset if (maxSizeQuota <= int.MaxValue - initialOffset) effectiveMaxSize = maxSizeQuota + initialOffset; else effectiveMaxSize = int.MaxValue; int predictedMessageSize = PredictMessageSize(); if (predictedMessageSize > effectiveMaxSize) predictedMessageSize = effectiveMaxSize; else if (predictedMessageSize < initialOffset) predictedMessageSize = initialOffset; try { stream.Init(predictedMessageSize, maxSizeQuota, effectiveMaxSize, bufferManager); stream.Skip(initialOffset); XmlDictionaryWriter writer = TakeXmlWriter(stream); OnWriteStartMessage(writer); message.WriteMessage(writer); OnWriteEndMessage(writer); writer.Flush(); ReturnXmlWriter(writer); int size; byte[] buffer = stream.ToArray(out size); RecordActualMessageSize(size); return new ArraySegment (buffer, initialOffset, size - initialOffset); } finally { stream.Clear(); } } protected virtual void OnWriteStartMessage(XmlDictionaryWriter writer) { } protected virtual void OnWriteEndMessage(XmlDictionaryWriter writer) { } void InitMessagePredicter() { sizeHistory = new int[4]; for (int i = 0; i < sizeHistoryCount; i++) sizeHistory[i] = 256; } int PredictMessageSize() { int max = 0; for (int i = 0; i < sizeHistoryCount; i++) if (sizeHistory[i] > max) max = sizeHistory[i]; return max + expectedSizeVariance; } void RecordActualMessageSize(int size) { sizeHistory[sizeHistoryIndex] = size; sizeHistoryIndex = (sizeHistoryIndex + 1) % sizeHistoryCount; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SerializationAttributes.cs
- _HeaderInfo.cs
- DeleteBookmarkScope.cs
- StreamGeometry.cs
- MediaTimeline.cs
- PackagePart.cs
- GenericQueueSurrogate.cs
- TagPrefixCollection.cs
- mediaeventargs.cs
- StylusPointProperties.cs
- SplashScreenNativeMethods.cs
- CodeNamespace.cs
- GridProviderWrapper.cs
- ProfileSettingsCollection.cs
- XmlMembersMapping.cs
- UnknownBitmapEncoder.cs
- DockPanel.cs
- Utils.cs
- KeyValuePair.cs
- PngBitmapEncoder.cs
- MemoryMappedFile.cs
- PowerEase.cs
- Win32PrintDialog.cs
- ThreadNeutralSemaphore.cs
- SQLMembershipProvider.cs
- NonNullItemCollection.cs
- MetadataSection.cs
- PropertyReferenceSerializer.cs
- PhysicalOps.cs
- DynamicMetaObjectBinder.cs
- LambdaCompiler.Statements.cs
- InheritedPropertyChangedEventArgs.cs
- SynchronizationLockException.cs
- AssemblyInfo.cs
- SoapFaultCodes.cs
- GlobalizationSection.cs
- TextBoxAutomationPeer.cs
- XmlSchemaAnyAttribute.cs
- CustomErrorCollection.cs
- HtmlEncodedRawTextWriter.cs
- OneOfElement.cs
- BuildProviderInstallComponent.cs
- MouseOverProperty.cs
- ElementUtil.cs
- FormView.cs
- PathGeometry.cs
- EventRecord.cs
- mediaclock.cs
- IdentityReference.cs
- ScriptResourceInfo.cs
- TraceSection.cs
- CodeLinePragma.cs
- Size3D.cs
- ServiceHttpHandlerFactory.cs
- DetectEofStream.cs
- TimeSpanValidatorAttribute.cs
- SettingsContext.cs
- IIS7WorkerRequest.cs
- RuleSettingsCollection.cs
- DecoderFallback.cs
- WebPartDescription.cs
- WebControlAdapter.cs
- DataTableReaderListener.cs
- ProcessModelInfo.cs
- FilteredSchemaElementLookUpTable.cs
- Semaphore.cs
- ScalarOps.cs
- AttributeTableBuilder.cs
- CollectionBuilder.cs
- Function.cs
- ActivityDesignerAccessibleObject.cs
- SynchronizationHandlesCodeDomSerializer.cs
- _RequestCacheProtocol.cs
- SQLResource.cs
- Underline.cs
- RuleAction.cs
- XPathSelfQuery.cs
- TrackingStringDictionary.cs
- RichTextBox.cs
- ContractType.cs
- SoapSchemaMember.cs
- SkewTransform.cs
- AuthorizationPolicyTypeElementCollection.cs
- Decimal.cs
- SqlDataSourceCommandEventArgs.cs
- ArrayTypeMismatchException.cs
- xamlnodes.cs
- TreeNodeBinding.cs
- FormatException.cs
- HostDesigntimeLicenseContext.cs
- CodeCommentStatement.cs
- BrushMappingModeValidation.cs
- CodeSnippetTypeMember.cs
- InteropAutomationProvider.cs
- InternalConfigHost.cs
- TransactionScope.cs
- ScriptResourceInfo.cs
- NullableDoubleSumAggregationOperator.cs
- WindowsFormsHelpers.cs
- FixedNode.cs