Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / whidbey / NetFXspW7 / ndp / fx / src / Sys / System / IO / Ports / InternalResources.cs / 1 / InternalResources.cs
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: InternalResources
**
** Date: August 2002
**
===========================================================*/
using System.IO;
using System.Security;
using System.Resources;
using System.Globalization;
using System.Collections;
using System.Security.Permissions;
using System.Text;
using System.Configuration.Assemblies;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Diagnostics;
using Microsoft.Win32;
using System.Runtime.CompilerServices;
namespace System.IO.Ports
{
internal static class InternalResources
{
// Beginning of static Error methods
internal static void EndOfFile()
{
throw new EndOfStreamException(SR.GetString(SR.IO_EOF_ReadBeyondEOF));
}
internal static String GetMessage(int errorCode)
{
StringBuilder sb = new StringBuilder(512);
int result = SafeNativeMethods.FormatMessage(NativeMethods.FORMAT_MESSAGE_IGNORE_INSERTS |
NativeMethods.FORMAT_MESSAGE_FROM_SYSTEM | NativeMethods.FORMAT_MESSAGE_ARGUMENT_ARRAY,
new HandleRef(null, IntPtr.Zero), errorCode, 0, sb, sb.Capacity, IntPtr.Zero);
if (result != 0)
{
// result is the # of characters copied to the StringBuilder on NT,
// but on Win9x, it appears to be the number of MBCS bytes.
// Just give up and return the String as-is...
String s = sb.ToString();
return s;
}
else
{
return SR.GetString(SR.IO_UnknownError, errorCode);
}
}
internal static void FileNotOpen()
{
throw new ObjectDisposedException(null, SR.GetString(SR.Port_not_open));
}
internal static void WrongAsyncResult()
{
throw new ArgumentException(SR.GetString(SR.Arg_WrongAsyncResult));
}
internal static void EndReadCalledTwice()
{
// Should ideally be InvalidOperationExc but we can't maintain parity with Stream and SerialStream without some work
throw new ArgumentException(SR.GetString(SR.InvalidOperation_EndReadCalledMultiple));
}
internal static void EndWriteCalledTwice()
{
// Should ideally be InvalidOperationExc but we can't maintain parity with Stream and SerialStream without some work
throw new ArgumentException(SR.GetString(SR.InvalidOperation_EndWriteCalledMultiple));
}
internal static void WinIOError()
{
int errorCode = Marshal.GetLastWin32Error();
WinIOError(errorCode, String.Empty);
}
internal static void WinIOError(string str)
{
int errorCode = Marshal.GetLastWin32Error();
WinIOError(errorCode, str);
}
// After calling GetLastWin32Error(), it clears the last error field,
// so you must save the HResult and pass it to this method. This method
// will determine the appropriate exception to throw dependent on your
// error, and depending on the error, insert a string into the message
// gotten from the ResourceManager.
internal static void WinIOError(int errorCode, String str)
{
switch (errorCode)
{
case NativeMethods.ERROR_FILE_NOT_FOUND:
case NativeMethods.ERROR_PATH_NOT_FOUND:
if (str.Length == 0)
throw new IOException(SR.GetString(SR.IO_PortNotFound));
else
throw new IOException(SR.GetString(SR.IO_PortNotFoundFileName, str));
case NativeMethods.ERROR_ACCESS_DENIED:
if (str.Length == 0)
throw new UnauthorizedAccessException(SR.GetString(SR.UnauthorizedAccess_IODenied_NoPathName));
else
throw new UnauthorizedAccessException(SR.GetString(SR.UnauthorizedAccess_IODenied_Path, str));
case NativeMethods.ERROR_FILENAME_EXCED_RANGE:
throw new PathTooLongException(SR.GetString(SR.IO_PathTooLong));
case NativeMethods.ERROR_SHARING_VIOLATION:
// error message.
if (str.Length == 0)
throw new IOException(SR.GetString(SR.IO_SharingViolation_NoFileName));
else
throw new IOException(SR.GetString(SR.IO_SharingViolation_File, str));
default:
throw new IOException(GetMessage(errorCode), MakeHRFromErrorCode(errorCode));
}
}
// Use this to translate error codes like the above into HRESULTs like
// 0x80070006 for ERROR_INVALID_HANDLE
internal static int MakeHRFromErrorCode(int errorCode)
{
return unchecked(((int)0x80070000) | errorCode);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: InternalResources
**
** Date: August 2002
**
===========================================================*/
using System.IO;
using System.Security;
using System.Resources;
using System.Globalization;
using System.Collections;
using System.Security.Permissions;
using System.Text;
using System.Configuration.Assemblies;
using System.Runtime.InteropServices;
using System.Reflection;
using System.Diagnostics;
using Microsoft.Win32;
using System.Runtime.CompilerServices;
namespace System.IO.Ports
{
internal static class InternalResources
{
// Beginning of static Error methods
internal static void EndOfFile()
{
throw new EndOfStreamException(SR.GetString(SR.IO_EOF_ReadBeyondEOF));
}
internal static String GetMessage(int errorCode)
{
StringBuilder sb = new StringBuilder(512);
int result = SafeNativeMethods.FormatMessage(NativeMethods.FORMAT_MESSAGE_IGNORE_INSERTS |
NativeMethods.FORMAT_MESSAGE_FROM_SYSTEM | NativeMethods.FORMAT_MESSAGE_ARGUMENT_ARRAY,
new HandleRef(null, IntPtr.Zero), errorCode, 0, sb, sb.Capacity, IntPtr.Zero);
if (result != 0)
{
// result is the # of characters copied to the StringBuilder on NT,
// but on Win9x, it appears to be the number of MBCS bytes.
// Just give up and return the String as-is...
String s = sb.ToString();
return s;
}
else
{
return SR.GetString(SR.IO_UnknownError, errorCode);
}
}
internal static void FileNotOpen()
{
throw new ObjectDisposedException(null, SR.GetString(SR.Port_not_open));
}
internal static void WrongAsyncResult()
{
throw new ArgumentException(SR.GetString(SR.Arg_WrongAsyncResult));
}
internal static void EndReadCalledTwice()
{
// Should ideally be InvalidOperationExc but we can't maintain parity with Stream and SerialStream without some work
throw new ArgumentException(SR.GetString(SR.InvalidOperation_EndReadCalledMultiple));
}
internal static void EndWriteCalledTwice()
{
// Should ideally be InvalidOperationExc but we can't maintain parity with Stream and SerialStream without some work
throw new ArgumentException(SR.GetString(SR.InvalidOperation_EndWriteCalledMultiple));
}
internal static void WinIOError()
{
int errorCode = Marshal.GetLastWin32Error();
WinIOError(errorCode, String.Empty);
}
internal static void WinIOError(string str)
{
int errorCode = Marshal.GetLastWin32Error();
WinIOError(errorCode, str);
}
// After calling GetLastWin32Error(), it clears the last error field,
// so you must save the HResult and pass it to this method. This method
// will determine the appropriate exception to throw dependent on your
// error, and depending on the error, insert a string into the message
// gotten from the ResourceManager.
internal static void WinIOError(int errorCode, String str)
{
switch (errorCode)
{
case NativeMethods.ERROR_FILE_NOT_FOUND:
case NativeMethods.ERROR_PATH_NOT_FOUND:
if (str.Length == 0)
throw new IOException(SR.GetString(SR.IO_PortNotFound));
else
throw new IOException(SR.GetString(SR.IO_PortNotFoundFileName, str));
case NativeMethods.ERROR_ACCESS_DENIED:
if (str.Length == 0)
throw new UnauthorizedAccessException(SR.GetString(SR.UnauthorizedAccess_IODenied_NoPathName));
else
throw new UnauthorizedAccessException(SR.GetString(SR.UnauthorizedAccess_IODenied_Path, str));
case NativeMethods.ERROR_FILENAME_EXCED_RANGE:
throw new PathTooLongException(SR.GetString(SR.IO_PathTooLong));
case NativeMethods.ERROR_SHARING_VIOLATION:
// error message.
if (str.Length == 0)
throw new IOException(SR.GetString(SR.IO_SharingViolation_NoFileName));
else
throw new IOException(SR.GetString(SR.IO_SharingViolation_File, str));
default:
throw new IOException(GetMessage(errorCode), MakeHRFromErrorCode(errorCode));
}
}
// Use this to translate error codes like the above into HRESULTs like
// 0x80070006 for ERROR_INVALID_HANDLE
internal static int MakeHRFromErrorCode(int errorCode)
{
return unchecked(((int)0x80070000) | errorCode);
}
}
}
// 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
- ParseHttpDate.cs
- FormsAuthentication.cs
- LocalizableAttribute.cs
- IndexOutOfRangeException.cs
- SynchronizationLockException.cs
- CacheDependency.cs
- DBConnectionString.cs
- OpenTypeLayoutCache.cs
- __Error.cs
- StrokeNodeEnumerator.cs
- AQNBuilder.cs
- SiteOfOriginContainer.cs
- RowVisual.cs
- DetailsViewUpdateEventArgs.cs
- PrinterSettings.cs
- PowerEase.cs
- NegatedConstant.cs
- PackUriHelper.cs
- UnaryNode.cs
- MenuAdapter.cs
- TypeRestriction.cs
- ScriptReferenceEventArgs.cs
- PropertyAccessVisitor.cs
- Pair.cs
- DefaultAsyncDataDispatcher.cs
- _HTTPDateParse.cs
- PeerTransportCredentialType.cs
- OperationResponse.cs
- ProtocolElement.cs
- TrackingAnnotationCollection.cs
- SecureEnvironment.cs
- FilterElement.cs
- Int64Converter.cs
- UrlAuthFailedErrorFormatter.cs
- StylusPointCollection.cs
- Light.cs
- Location.cs
- InvokeProviderWrapper.cs
- BamlRecordHelper.cs
- AccessedThroughPropertyAttribute.cs
- hwndwrapper.cs
- ImageList.cs
- HtmlButton.cs
- BamlTreeUpdater.cs
- PageBuildProvider.cs
- _HelperAsyncResults.cs
- IndentedWriter.cs
- BaseResourcesBuildProvider.cs
- UpWmlPageAdapter.cs
- DataGridCell.cs
- LayoutEngine.cs
- UnsafeNativeMethods.cs
- XmlLangPropertyAttribute.cs
- oledbmetadatacolumnnames.cs
- SurrogateSelector.cs
- EncodingConverter.cs
- WeakEventManager.cs
- RunClient.cs
- ButtonStandardAdapter.cs
- AnimationException.cs
- SqlClientWrapperSmiStream.cs
- SparseMemoryStream.cs
- Vector3DKeyFrameCollection.cs
- InfoCardRSAOAEPKeyExchangeFormatter.cs
- TrackBarRenderer.cs
- MultiPartWriter.cs
- MinMaxParagraphWidth.cs
- ToolStripDropTargetManager.cs
- CustomCategoryAttribute.cs
- MetafileHeader.cs
- ProcessModelSection.cs
- TileModeValidation.cs
- SerialPinChanges.cs
- bindurihelper.cs
- PackageDigitalSignatureManager.cs
- TemplateNameScope.cs
- FamilyCollection.cs
- MimeMapping.cs
- Style.cs
- HttpClientChannel.cs
- ResourceSet.cs
- ObjectViewQueryResultData.cs
- SQLMoneyStorage.cs
- SafeSecurityHelper.cs
- SessionSwitchEventArgs.cs
- FillRuleValidation.cs
- DateTimeFormatInfoScanner.cs
- ListBoxAutomationPeer.cs
- XamlSerializerUtil.cs
- NamespaceEmitter.cs
- SequenceRange.cs
- Point3DValueSerializer.cs
- StrongNameUtility.cs
- DropShadowBitmapEffect.cs
- SubqueryRules.cs
- TypeResolvingOptionsAttribute.cs
- x509utils.cs
- ProfileGroupSettingsCollection.cs
- Matrix3DStack.cs
- WithStatement.cs