Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / Net / System / Net / _WinHttpWebProxyDataBuilder.cs / 1 / _WinHttpWebProxyDataBuilder.cs
using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace System.Net { internal sealed class WinHttpWebProxyBuilder : WebProxyDataBuilder { protected override void BuildInternal() { GlobalLog.Enter("WinHttpWebProxyBuilder#" + ValidationHelper.HashString(this) + "::BuildInternal()"); UnsafeNclNativeMethods.WinHttp.WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ieProxyConfig = new UnsafeNclNativeMethods.WinHttp.WINHTTP_CURRENT_USER_IE_PROXY_CONFIG(); if (UnsafeNclNativeMethods.WinHttp.WinHttpGetIEProxyConfigForCurrentUser(ref ieProxyConfig)) { string proxy = null; string proxyByPass = null; string autoConfigUrl = null; try { proxy = Marshal.PtrToStringUni(ieProxyConfig.Proxy); proxyByPass = Marshal.PtrToStringUni(ieProxyConfig.ProxyBypass); autoConfigUrl = Marshal.PtrToStringUni(ieProxyConfig.AutoConfigUrl); // note that ieProxyConfig.Proxy will be null if "use a proxy server" flag is turned off, even if // the user specified a proxy address. When we read directly from the Registry we need to check // for ProxyTypeFlags.PROXY_TYPE_PROXY. WinHttp does this for us and if the flag is not set, // ieProxyConfig.Proxy will be null. SetProxyAndBypassList(proxy, proxyByPass); SetAutoDetectSettings(ieProxyConfig.AutoDetect); // similar to comment above: ieProxyConfig.AutoConfigUrl will only be set if "automatically detect // settings" flag is set. We don't need to check ProxyTypeFlags.PROXY_TYPE_AUTO_PROXY_URL; WinHttp // takes care of it and sets AutoConfigUrl to null if the flag is not set, regardless of the actual // config script string. SetAutoProxyUrl(autoConfigUrl); } finally { FreeStr(ieProxyConfig.Proxy); FreeStr(ieProxyConfig.ProxyBypass); FreeStr(ieProxyConfig.AutoConfigUrl); } } else { int errorCode = Marshal.GetLastWin32Error(); if (errorCode == Microsoft.Win32.NativeMethods.ERROR_NOT_ENOUGH_MEMORY) { throw new OutOfMemoryException(); } // if API call fails, rely on automatic detection SetAutoDetectSettings(true); } GlobalLog.Leave("WinHttpWebProxyBuilder#" + ValidationHelper.HashString(this) + "::BuildInternal()"); } private void FreeStr(IntPtr intPtr) { if (intPtr != IntPtr.Zero) { Marshal.FreeHGlobal(intPtr); } } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. using System; using System.Collections.Generic; using System.Text; using System.Runtime.InteropServices; namespace System.Net { internal sealed class WinHttpWebProxyBuilder : WebProxyDataBuilder { protected override void BuildInternal() { GlobalLog.Enter("WinHttpWebProxyBuilder#" + ValidationHelper.HashString(this) + "::BuildInternal()"); UnsafeNclNativeMethods.WinHttp.WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ieProxyConfig = new UnsafeNclNativeMethods.WinHttp.WINHTTP_CURRENT_USER_IE_PROXY_CONFIG(); if (UnsafeNclNativeMethods.WinHttp.WinHttpGetIEProxyConfigForCurrentUser(ref ieProxyConfig)) { string proxy = null; string proxyByPass = null; string autoConfigUrl = null; try { proxy = Marshal.PtrToStringUni(ieProxyConfig.Proxy); proxyByPass = Marshal.PtrToStringUni(ieProxyConfig.ProxyBypass); autoConfigUrl = Marshal.PtrToStringUni(ieProxyConfig.AutoConfigUrl); // note that ieProxyConfig.Proxy will be null if "use a proxy server" flag is turned off, even if // the user specified a proxy address. When we read directly from the Registry we need to check // for ProxyTypeFlags.PROXY_TYPE_PROXY. WinHttp does this for us and if the flag is not set, // ieProxyConfig.Proxy will be null. SetProxyAndBypassList(proxy, proxyByPass); SetAutoDetectSettings(ieProxyConfig.AutoDetect); // similar to comment above: ieProxyConfig.AutoConfigUrl will only be set if "automatically detect // settings" flag is set. We don't need to check ProxyTypeFlags.PROXY_TYPE_AUTO_PROXY_URL; WinHttp // takes care of it and sets AutoConfigUrl to null if the flag is not set, regardless of the actual // config script string. SetAutoProxyUrl(autoConfigUrl); } finally { FreeStr(ieProxyConfig.Proxy); FreeStr(ieProxyConfig.ProxyBypass); FreeStr(ieProxyConfig.AutoConfigUrl); } } else { int errorCode = Marshal.GetLastWin32Error(); if (errorCode == Microsoft.Win32.NativeMethods.ERROR_NOT_ENOUGH_MEMORY) { throw new OutOfMemoryException(); } // if API call fails, rely on automatic detection SetAutoDetectSettings(true); } GlobalLog.Leave("WinHttpWebProxyBuilder#" + ValidationHelper.HashString(this) + "::BuildInternal()"); } private void FreeStr(IntPtr intPtr) { if (intPtr != IntPtr.Zero) { Marshal.FreeHGlobal(intPtr); } } } } // 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
- OutputCacheProfile.cs
- FlowSwitchLink.cs
- ExtensionSurface.cs
- SchemaImporter.cs
- BooleanAnimationBase.cs
- CompilerScope.Storage.cs
- DataGridViewCellStyleChangedEventArgs.cs
- Single.cs
- TracedNativeMethods.cs
- UpdateCompiler.cs
- DBSqlParserTable.cs
- ComponentManagerBroker.cs
- SubMenuStyle.cs
- RelationshipDetailsRow.cs
- InfoCardHelper.cs
- DataGridViewCellErrorTextNeededEventArgs.cs
- PointAnimationClockResource.cs
- XPathNodeHelper.cs
- ResourceContainer.cs
- StringComparer.cs
- _SecureChannel.cs
- Converter.cs
- PropertyChangeTracker.cs
- ScrollViewerAutomationPeer.cs
- SHA512Managed.cs
- GeneralTransform2DTo3DTo2D.cs
- VisualStates.cs
- EntityCollection.cs
- DataGridViewTopLeftHeaderCell.cs
- ControlAdapter.cs
- StructureChangedEventArgs.cs
- RegexTypeEditor.cs
- TextInfo.cs
- ReferentialConstraint.cs
- ISAPIApplicationHost.cs
- OrthographicCamera.cs
- AppDomainInstanceProvider.cs
- RuntimeResourceSet.cs
- ComponentResourceKey.cs
- DbConnectionPoolCounters.cs
- LineServicesRun.cs
- ADMembershipUser.cs
- GeometryHitTestParameters.cs
- ToolStripSplitStackLayout.cs
- ColorConvertedBitmap.cs
- StdRegProviderWrapper.cs
- AudioDeviceOut.cs
- WebBrowserBase.cs
- SqlUdtInfo.cs
- Dictionary.cs
- TypeUtil.cs
- PowerModeChangedEventArgs.cs
- RegexStringValidator.cs
- RtfToken.cs
- EventWaitHandleSecurity.cs
- GroupStyle.cs
- SerializableAttribute.cs
- MD5CryptoServiceProvider.cs
- EventSetter.cs
- UnsupportedPolicyOptionsException.cs
- PropertyValueUIItem.cs
- ContextBase.cs
- FileLogRecord.cs
- XmlSignificantWhitespace.cs
- CodeStatement.cs
- RegexParser.cs
- IpcManager.cs
- FigureHelper.cs
- TaskSchedulerException.cs
- DataIdProcessor.cs
- SqlConnection.cs
- SettingsPropertyIsReadOnlyException.cs
- XsltFunctions.cs
- DoubleAnimationClockResource.cs
- StateValidator.cs
- MailFileEditor.cs
- ModelUIElement3D.cs
- MethodBody.cs
- SmiGettersStream.cs
- WmpBitmapEncoder.cs
- TypeDescriptionProvider.cs
- FunctionParameter.cs
- ColumnReorderedEventArgs.cs
- StorageRoot.cs
- ToolStripComboBox.cs
- HttpModuleActionCollection.cs
- WebPartAddingEventArgs.cs
- FreezableOperations.cs
- DecoderFallback.cs
- DBConnectionString.cs
- Cursor.cs
- StorageBasedPackageProperties.cs
- FaultConverter.cs
- CollectionViewGroupInternal.cs
- SqlMultiplexer.cs
- QilFunction.cs
- StylesEditorDialog.cs
- LayoutTable.cs
- ResXDataNode.cs
- PrePostDescendentsWalker.cs