mscorlib(4.0.0.0) API with additions
AnonymousPipeClientStream.cs
1 using Microsoft.Win32;
2 using Microsoft.Win32.SafeHandles;
3 using System.Security;
5 
6 namespace System.IO.Pipes
7 {
9  [HostProtection(SecurityAction.LinkDemand, MayLeakOnAbort = true)]
10  public sealed class AnonymousPipeClientStream : PipeStream
11  {
15  {
16  [SecurityCritical]
17  get
18  {
19  return PipeTransmissionMode.Byte;
20  }
21  }
22 
29  public override PipeTransmissionMode ReadMode
30  {
31  [SecurityCritical]
32  set
33  {
35  switch (value)
36  {
37  case PipeTransmissionMode.Byte:
38  break;
39  default:
40  throw new ArgumentOutOfRangeException("value", System.SR.GetString("ArgumentOutOfRange_TransmissionModeByteOrMsg"));
42  throw new NotSupportedException(System.SR.GetString("NotSupported_AnonymousPipeMessagesNotSupported"));
43  }
44  }
45  }
46 
51  [SecuritySafeCritical]
52  [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
53  public AnonymousPipeClientStream(string pipeHandleAsString)
54  : this(PipeDirection.In, pipeHandleAsString)
55  {
56  }
57 
67  [SecurityCritical]
68  [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
69  public AnonymousPipeClientStream(PipeDirection direction, string pipeHandleAsString)
70  : base(direction, 0)
71  {
72  if (direction == PipeDirection.InOut)
73  {
74  throw new NotSupportedException(System.SR.GetString("NotSupported_AnonymousPipeUnidirectional"));
75  }
76  if (pipeHandleAsString == null)
77  {
78  throw new ArgumentNullException("pipeHandleAsString");
79  }
80  long result = 0L;
81  if (!long.TryParse(pipeHandleAsString, out result))
82  {
83  throw new ArgumentException(System.SR.GetString("Argument_InvalidHandle"), "pipeHandleAsString");
84  }
85  SafePipeHandle safePipeHandle = new SafePipeHandle((IntPtr)result, ownsHandle: true);
86  if (safePipeHandle.IsInvalid)
87  {
88  throw new ArgumentException(System.SR.GetString("Argument_InvalidHandle"), "pipeHandleAsString");
89  }
90  Init(direction, safePipeHandle);
91  }
92 
103  [SecurityCritical]
104  [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
105  public AnonymousPipeClientStream(PipeDirection direction, SafePipeHandle safePipeHandle)
106  : base(direction, 0)
107  {
108  if (direction == PipeDirection.InOut)
109  {
110  throw new NotSupportedException(System.SR.GetString("NotSupported_AnonymousPipeUnidirectional"));
111  }
112  if (safePipeHandle == null)
113  {
114  throw new ArgumentNullException("safePipeHandle");
115  }
116  if (safePipeHandle.IsInvalid)
117  {
118  throw new ArgumentException(System.SR.GetString("Argument_InvalidHandle"), "safePipeHandle");
119  }
120  Init(direction, safePipeHandle);
121  }
122 
123  [SecuritySafeCritical]
124  [PermissionSet(SecurityAction.Demand, Name = "FullTrust")]
125  private void Init(PipeDirection direction, SafePipeHandle safePipeHandle)
126  {
127  if (Microsoft.Win32.UnsafeNativeMethods.GetFileType(safePipeHandle) != 3)
128  {
129  throw new IOException(System.SR.GetString("IO_IO_InvalidPipeHandle"));
130  }
131  InitializeHandle(safePipeHandle, isExposed: true, isAsync: false);
132  base.State = PipeState.Connected;
133  }
134 
137  {
138  Dispose(disposing: false);
139  }
140  }
141 }
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
override PipeTransmissionMode ReadMode
Sets the reading mode for the T:System.IO.Pipes.AnonymousPipeClientStream object.
Exposes the client side of an anonymous pipe stream, which supports both synchronous and asynchronous...
Might cause a resource leak on termination, if not protected by a safe handle or some other means of ...
Definition: __Canon.cs:3
The exception that is thrown when the value of an argument is outside the allowable range of values a...
void InitializeHandle(SafePipeHandle handle, bool isExposed, bool isAsync)
Initializes a T:System.IO.Pipes.PipeStream object from the specified T:Microsoft.Win32....
Definition: PipeStream.cs:386
PipeTransmissionMode
Specifies the transmission mode of the pipe.
override PipeTransmissionMode TransmissionMode
Gets the pipe transmission mode supported by the current pipe.
SecurityAction
Specifies the security actions that can be performed using declarative security.
Exposes a T:System.IO.Stream object around a pipe, which supports both anonymous and named pipes.
Definition: PipeStream.cs:14
Represents a collection that can contain many different types of permissions.
override string Message
Gets the error message and the string representation of the invalid argument value,...
AnonymousPipeClientStream(string pipeHandleAsString)
Initializes a new instance of the T:System.IO.Pipes.AnonymousPipeClientStream class with the specifie...
The exception that is thrown when an I/O error occurs.
Definition: IOException.cs:10
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
Definition: SR.cs:7
AnonymousPipeClientStream(PipeDirection direction, SafePipeHandle safePipeHandle)
Initializes a new instance of the T:System.IO.Pipes.AnonymousPipeClientStream class from the specifie...
The exception that is thrown when one of the arguments provided to a method is not valid.
Specifies that the pipe direction is in.
virtual internal void CheckPipePropertyOperations()
Verifies that the pipe is in a proper state for getting or setting properties.
Definition: PipeStream.cs:1047
PipeDirection
Specifies the direction of the pipe.
Definition: PipeDirection.cs:5
void Dispose()
Releases all resources used by the T:System.IO.Stream.
Definition: Stream.cs:863
The exception that is thrown when an invoked method is not supported, or when there is an attempt to ...
AnonymousPipeClientStream(PipeDirection direction, string pipeHandleAsString)
Initializes a new instance of the T:System.IO.Pipes.AnonymousPipeClientStream class with the specifie...
SafePipeHandle SafePipeHandle
Gets the safe handle for the local end of the pipe that the current T:System.IO.Pipes....
Definition: PipeStream.cs:223