示例#1
0
        public DiagnosticsEventPipeProcessor(
            PipeMode mode,
            ILoggerFactory loggerFactory = null,                               // PipeMode = Logs
            LogLevel logsLevel           = LogLevel.Debug,                     // PipeMode = Logs
            IEnumerable <ICountersLogger> metricLoggers = null,                // PipeMode = Metrics
            int metricIntervalSeconds  = 10,                                   // PipeMode = Metrics
            CounterFilter metricFilter = null,                                 // PipeMode = Metrics
            MemoryGraph gcGraph        = null,                                 // PipeMode = GCDump
            MonitoringSourceConfiguration configuration = null,                // PipeMode = Nettrace
            Func <Stream, CancellationToken, Task> onStreamAvailable   = null, // PipeMode = Nettrace
            Func <string, CancellationToken, Task> processInfoCallback = null  // PipeMode = ProcessInfo
            )
        {
            _metricLoggers         = metricLoggers ?? Enumerable.Empty <ICountersLogger>();
            _mode                  = mode;
            _loggerFactory         = loggerFactory;
            _gcGraph               = gcGraph;
            _metricIntervalSeconds = metricIntervalSeconds;
            _logsLevel             = logsLevel;
            _processInfoCallback   = processInfoCallback;
            _userConfig            = configuration;
            _onStreamAvailable     = onStreamAvailable;
            _processInfoCallback   = processInfoCallback;
            _counterFilter         = metricFilter;

            _sessionStarted = new TaskCompletionSource <bool>(TaskCreationOptions.RunContinuationsAsynchronously);
        }
示例#2
0
 private static extern SafeFileHandle ExternCreateNamedPipe(
     string lpName,
     PipeOpenMode dwOpenMode,
     PipeMode dwPipeMode,
     int nMaxInstances,
     int nOutBufferSize,
     int nInBufferSize,
     int nDefaultTimeout,
     IntPtr lpSecurityAttributes);
 public static extern IntPtr CreateNamedPipe(
     string lpName,
     PipeOpenMode dwOpenMode,
     PipeMode dwPipeMode,
     uint nMaxInstances,
     uint nOutBufferSize,
     uint nInBufferSize,
     uint nDefaultTimeOut,
     IntPtr pipeSecurityAttributes);
 public static extern IntPtr CreateNamedPipe(
     String lpName,                      // Pipe name
     PipeOpenMode dwOpenMode,            // Pipe open mode
     PipeMode dwPipeMode,                // Pipe-specific modes
     uint nMaxInstances,                 // Maximum number of instances
     uint nOutBufferSize,                // Output buffer size
     uint nInBufferSize,                 // Input buffer size
     uint nDefaultTimeOut,               // Time-out interval
     IntPtr pipeSecurityAttributes       // Security Attributes
     );
 public DiagnosticsEventPipeProcessor(ContextConfiguration contextConfig, PipeMode mode,
                                      ILoggerFactory loggerFactory,
                                      IEnumerable <IMetricsLogger> metricLoggers)
 {
     _dimValues = new List <string> {
         contextConfig.Namespace, contextConfig.Node
     };
     _metricLoggers = metricLoggers;
     _mode          = mode;
     _loggerFactory = loggerFactory;
 }
示例#6
0
 public DiagnosticsEventPipeProcessor(
     PipeMode mode,
     ILoggerFactory loggerFactory = null,
     IEnumerable <IMetricsLogger> metricLoggers = null,
     int metricIntervalSeconds = 10,
     MemoryGraph gcGraph       = null)
 {
     _metricLoggers         = metricLoggers ?? Enumerable.Empty <IMetricsLogger>();
     _mode                  = mode;
     _loggerFactory         = loggerFactory;
     _gcGraph               = gcGraph;
     _metricIntervalSeconds = metricIntervalSeconds;
 }
示例#7
0
 public DiagnosticsEventPipeProcessor(
     ContextConfiguration contextConfig,
     PipeMode mode,
     ILoggerFactory loggerFactory = null,
     IEnumerable <IMetricsLogger> metricLoggers = null,
     MemoryGraph gcGraph = null)
 {
     _dimValues = new List <string> {
         contextConfig.Namespace, contextConfig.Node
     };
     _metricLoggers = metricLoggers ?? Enumerable.Empty <IMetricsLogger>();
     _mode          = mode;
     _loggerFactory = loggerFactory;
     _gcGraph       = gcGraph;
 }
 public DiagnosticsEventPipeProcessor(
     PipeMode mode,
     ILoggerFactory loggerFactory = null,               // PipeMode = Logs
     LogLevel logsLevel           = LogLevel.Debug,     // PipeMode = Logs
     IEnumerable <IMetricsLogger> metricLoggers = null, // PipeMode = Metrics
     int metricIntervalSeconds           = 10,          // PipeMode = Metrics
     MemoryGraph gcGraph                 = null,        // PipeMode = GCDump
     Action <string> processInfoCallback = null         // PipeMode = ProcessInfo
     )
 {
     _metricLoggers         = metricLoggers ?? Enumerable.Empty <IMetricsLogger>();
     _mode                  = mode;
     _loggerFactory         = loggerFactory;
     _gcGraph               = gcGraph;
     _metricIntervalSeconds = metricIntervalSeconds;
     _logsLevel             = logsLevel;
     _processInfoCallback   = processInfoCallback;
 }
示例#9
0
 /// <nodoc />
 public static SafeFileHandle CreateNamedPipe(string lpName, PipeOpenMode dwOpenMode, PipeMode dwPipeMode, int nMaxInstances, int nOutBufferSize, int nInBufferSize, int nDefaultTimeout, IntPtr lpSecurityAttributes)
 => s_nativeMethods.CreateNamedPipe(lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeout, lpSecurityAttributes);
 public static extern IntPtr CreateNamedPipe(
     String lpName,                      // Pipe name
     PipeOpenMode dwOpenMode,            // Pipe open mode
     PipeMode dwPipeMode,                // Pipe-specific modes
     uint nMaxInstances,                 // Maximum number of instances
     uint nOutBufferSize,                // Output buffer size
     uint nInBufferSize,                 // Input buffer size
     uint nDefaultTimeOut,               // Time-out interval
     IntPtr pipeSecurityAttributes       // Security Attributes
     );
 public static extern bool SetNamedPipeHandleState(
     IntPtr hHandle,
     ref PipeMode lpMode,
     IntPtr lpMaxCollectionCount,
     IntPtr lpCollectDataTimeout);
示例#12
0
        public void KeyDown(KeyEventArgs key)
        {
            double radiusStep = PipeStep;

            switch (key.KeyCode)
            {
            case Constants.IncreaseBig:
                radiusStep *= 10;
                goto case Constants.Increase;

            case Constants.Increase:
                if (Keyboard.IsKeyDown(Key.LeftCtrl))
                {
                    switch (_pipeMode)
                    {
                    case PipeMode.NoApples:
                        break;

                    case PipeMode.ApplesDistance:
                        _appleDistance += AppleDistanceStep;
                        break;

                    case PipeMode.ApplesAmount:
                        _appleAmount++;
                        break;
                    }
                }
                else
                {
                    _pipeRadius += radiusStep;
                }

                break;

            case Constants.DecreaseBig:
                radiusStep *= 10;
                goto case Constants.Decrease;

            case Constants.Decrease:
                if (Keyboard.IsKeyDown(Key.LeftCtrl))
                {
                    switch (_pipeMode)
                    {
                    case PipeMode.NoApples:
                        break;

                    case PipeMode.ApplesDistance:
                        if (_appleDistance > AppleDistanceStep)
                        {
                            _appleDistance -= AppleDistanceStep;
                        }
                        break;

                    case PipeMode.ApplesAmount:
                        if (_appleAmount > 1)
                        {
                            _appleAmount--;
                        }
                        break;
                    }
                }
                else if (_pipeRadius > radiusStep)
                {
                    _pipeRadius -= radiusStep;
                }

                break;

            case Keys.Space:
                switch (_pipeMode)
                {
                case PipeMode.NoApples:
                    _pipeMode = PipeMode.ApplesDistance;
                    break;

                case PipeMode.ApplesDistance:
                    _pipeMode = PipeMode.ApplesAmount;
                    break;

                case PipeMode.ApplesAmount:
                    _pipeMode = PipeMode.NoApples;
                    break;
                }

                break;
            }

            if (CreatingPipe)
            {
                UpdatePipe(_pipeline);
            }

            UpdateHelp();
        }
示例#13
0
 /// <inheritdoc />
 public SafeFileHandle CreateNamedPipe(string lpName, PipeOpenMode dwOpenMode, PipeMode dwPipeMode, int nMaxInstances, int nOutBufferSize, int nInBufferSize, int nDefaultTimeout, IntPtr lpSecurityAttributes)
 => throw new NotImplementedException();
示例#14
0
 public static extern SafeObjectHandle CreateNamedPipe(
     string lpName,
     PipeAccessMode dwOpenMode,
     PipeMode dwPipeMode,
     int nMaxInstances,
     int nOutBufferSize,
     int nInBufferSize,
     int nDefaultTimeOut,
     SECURITY_ATTRIBUTES lpSecurityAttributes);
示例#15
0
 public static extern bool SetNamedPipeHandleState(
     IntPtr hHandle,
     ref PipeMode lpMode,
     IntPtr lpMaxCollectionCount,
     IntPtr lpCollectDataTimeout);
示例#16
0
 public NullablePipeMode(PipeMode value)
 {
     this.Value = value;
 }
示例#17
0
 public static extern SafePipeHandle CreateNamedPipe(string pipeName, PipeOpenMode openMode, PipeMode pipeMode, int maxInstances, int outBufferSize, int inBufferSize, uint defaultTimeout);
示例#18
0
 public static extern bool SetNamedPipeHandleState(
     SafePipeHandle hNamedPipe, ref PipeMode mode,
     IntPtr maxCollectionCount, IntPtr collectDataTimeout);
示例#19
0
 public static extern unsafe SafeObjectHandle CreateNamedPipe(
     string lpName,
     PipeAccessMode dwOpenMode,
     PipeMode dwPipeMode,
     int nMaxInstances,
     int nOutBufferSize,
     int nInBufferSize,
     int nDefaultTimeOut,
     [Friendly(FriendlyFlags.In | FriendlyFlags.Optional)] SECURITY_ATTRIBUTES* lpSecurityAttributes);
示例#20
0
 public static extern SafePipeHandle CreateNamedPipe(string pipeName,
     PipeOpenMode openMode, PipeMode pipeMode, int maxInstances,
     int outBufferSize, int inBufferSize, uint defaultTimeout,
     SECURITY_ATTRIBUTES securityAttributes);
示例#21
0
    static void PInvokeNativePipeClient()
    {
        /////////////////////////////////////////////////////////////////////
        // Try to open a named pipe.
        //

        // Prepare the pipe name
        String strPipeName = String.Format(@"\\{0}\pipe\{1}",
                                           ".",         // Server name
                                           "HelloWorld" // Pipe name
                                           );

        IntPtr hPipe;

        while (true)
        {
            hPipe = PipeNative.CreateFile(
                strPipeName,                     // Pipe name
                FileDesiredAccess.GENERIC_READ | // Read and write access
                FileDesiredAccess.GENERIC_WRITE,

                FileShareMode.Zero,                    // No sharing
                IntPtr.Zero,                           // Default security attributes
                FileCreationDisposition.OPEN_EXISTING, // Opens existing pipe
                0,                                     // Default attributes
                0);                                    // No template file

            // Break if the pipe handle is valid.
            if (hPipe.ToInt32() != PipeNative.INVALID_HANDLE_VALUE)
            {
                break;
            }

            if (// Exit if an error other than ERROR_PIPE_BUSY occurs
                PipeNative.GetLastError() != PipeNative.ERROR_PIPE_BUSY
                ||
                // All pipe instances are busy, so wait for five seconds
                !PipeNative.WaitNamedPipe(strPipeName, 5000))
            {
                Console.WriteLine("Unable to open named pipe {0} w/err 0x{1:X}",
                                  strPipeName, PipeNative.GetLastError());
                return;
            }
        }
        Console.WriteLine("The named pipe, {0}, is connected.", strPipeName);


        /////////////////////////////////////////////////////////////////////
        // The pipe connected; change to message-read mode.
        //

        PipeMode mode    = PipeMode.PIPE_READMODE_MESSAGE;
        bool     bResult = PipeNative.SetNamedPipeHandleState(
            hPipe, ref mode, IntPtr.Zero, IntPtr.Zero);

        if (!bResult)
        {
            Console.WriteLine("SetNamedPipeHandleState failed w/err 0x{0:X}",
                              PipeNative.GetLastError());
            return;
        }


        /////////////////////////////////////////////////////////////////////
        // Send a message to the pipe server and receive its response.
        //

        // A byte buffer of BUFFER_SIZE bytes. The buffer should be big
        // enough for ONE request to the server.

        string strMessage;

        byte[] bRequest;                        // Client -> Server
        uint   cbBytesWritten, cbRequestBytes;

        byte[] bReply = new byte[BUFFER_SIZE];  // Server -> Client
        uint   cbBytesRead, cbReplyBytes;

        // Send one message to the pipe.

        // '\0' is appended in the end because the client may be a native
        // C++ program.
        strMessage     = "Default request from client\0";
        bRequest       = Encoding.Unicode.GetBytes(strMessage);
        cbRequestBytes = (uint)bRequest.Length;

        bResult = PipeNative.WriteFile(         // Write to the pipe.
            hPipe,                              // Handle of the pipe
            bRequest,                           // Message to be written
            cbRequestBytes,                     // Number of bytes to write
            out cbBytesWritten,                 // Number of bytes written
            IntPtr.Zero);                       // Not overlapped

        if (!bResult /*Failed*/ || cbRequestBytes != cbBytesWritten /*Failed*/)
        {
            Console.WriteLine("WriteFile failed w/err 0x{0:X}",
                              PipeNative.GetLastError());
            return;
        }

        Console.WriteLine("Sends {0} bytes; Message: \"{1}\"",
                          cbBytesWritten, strMessage.TrimEnd('\0'));

        // Receive the response from the server.

        cbReplyBytes = BUFFER_SIZE;
        do
        {
            bResult = PipeNative.ReadFile(      // Read from the pipe.
                hPipe,                          // Handle of the pipe
                bReply,                         // Buffer to receive the reply
                cbReplyBytes,                   // Size of buffer
                out cbBytesRead,                // Number of bytes read
                IntPtr.Zero);                   // Not overlapped

            if (!bResult &&
                PipeNative.GetLastError() != PipeNative.ERROR_MORE_DATA)
            {
                Console.WriteLine("ReadFile failed w/err 0x{0:X}",
                                  PipeNative.GetLastError());
                break;
            }

            strMessage = Encoding.Unicode.GetString(bReply).TrimEnd('\0');
            Console.WriteLine("Receives {0} bytes; Message: \"{1}\"",
                              cbBytesRead, strMessage);
        } while (!bResult);  // Repeat loop if ERROR_MORE_DATA


        /////////////////////////////////////////////////////////////////////
        // Close the pipe.
        //

        PipeNative.CloseHandle(hPipe);
    }
        /// <summary>
        /// P/Invoke the native APIs related to named pipe operations to connect
        /// to the named pipe.
        /// </summary>
        public static void Run()
        {
            SafePipeHandle hNamedPipe = null;

            try
            {
                // Try to open the named pipe identified by the pipe name.
                while (true)
                {
                    hNamedPipe = NativeMethod.CreateFile(
                        Program.FullPipeName,                   // Pipe name
                        FileDesiredAccess.GENERIC_READ |        // Read access
                        FileDesiredAccess.GENERIC_WRITE,        // Write access
                        FileShareMode.Zero,                     // No sharing
                        null,                                   // Default security attributes
                        FileCreationDisposition.OPEN_EXISTING,  // Opens existing pipe
                        0,                                      // Default attributes
                        IntPtr.Zero                             // No template file
                        );

                    // If the pipe handle is opened successfully ...
                    if (!hNamedPipe.IsInvalid)
                    {
                        Console.WriteLine("The named pipe ({0}) is connected.",
                                          Program.FullPipeName);
                        break;
                    }

                    // Exit if an error other than ERROR_PIPE_BUSY occurs.
                    if (Marshal.GetLastWin32Error() != ERROR_PIPE_BUSY)
                    {
                        throw new Win32Exception();
                    }

                    // All pipe instances are busy, so wait for 5 seconds.
                    if (!NativeMethod.WaitNamedPipe(Program.FullPipeName, 5000))
                    {
                        throw new Win32Exception();
                    }
                }

                // Set the read mode and the blocking mode of the named pipe. In
                // this sample, we set data to be read from the pipe as a stream
                // of messages.
                PipeMode mode = PipeMode.PIPE_READMODE_MESSAGE;
                if (!NativeMethod.SetNamedPipeHandleState(hNamedPipe, ref mode,
                                                          IntPtr.Zero, IntPtr.Zero))
                {
                    throw new Win32Exception();
                }

                //
                // Send a request from client to server.
                //

                string message = Program.RequestMessage;
                byte[] bRequest = Encoding.Unicode.GetBytes(message);
                int    cbRequest = bRequest.Length, cbWritten;

                if (!NativeMethod.WriteFile(
                        hNamedPipe,             // Handle of the pipe
                        bRequest,               // Message to be written
                        cbRequest,              // Number of bytes to write
                        out cbWritten,          // Number of bytes written
                        IntPtr.Zero             // Not overlapped
                        ))
                {
                    throw new Win32Exception();
                }

                Console.WriteLine("Send {0} bytes to server: \"{1}\"",
                                  cbWritten, message.TrimEnd('\0'));

                //
                // Receive a response from server.
                //

                bool finishRead = false;
                do
                {
                    byte[] bResponse = new byte[Program.BufferSize];
                    int    cbResponse = bResponse.Length, cbRead;

                    finishRead = NativeMethod.ReadFile(
                        hNamedPipe,             // Handle of the pipe
                        bResponse,              // Buffer to receive data
                        cbResponse,             // Size of buffer in bytes
                        out cbRead,             // Number of bytes read
                        IntPtr.Zero             // Not overlapped
                        );

                    if (!finishRead &&
                        Marshal.GetLastWin32Error() != ERROR_MORE_DATA)
                    {
                        throw new Win32Exception();
                    }

                    // Unicode-encode the received byte array and trim all the
                    // '\0' characters at the end.
                    message = Encoding.Unicode.GetString(bResponse).TrimEnd('\0');
                    Console.WriteLine("Receive {0} bytes from server: \"{1}\"",
                                      cbRead, message);
                }while (!finishRead);  // Repeat loop if ERROR_MORE_DATA
            }
            catch (Exception ex)
            {
                Console.WriteLine("The client throws the error: {0}", ex.Message);
            }
            finally
            {
                if (hNamedPipe != null)
                {
                    hNamedPipe.Close();
                    hNamedPipe = null;
                }
            }
        }
示例#23
0
		public static extern SafeFileHandle CreateNamedPipe(string lpName, PipeOpenMode dwOpenMode, PipeMode dwPipeMode,
			uint nMaxInstances, uint nOutBufferSize, uint nInBufferSize, uint nDefaultTimeOut,
			IntPtr lpSecurityAttributes);
示例#24
0
 public static extern SafePipeHandle CreateNamedPipe(string pipeName, PipeOpenMode openMode, PipeMode pipeMode, int maxInstances, int outBufferSize, int inBufferSize, uint defaultTimeout, SECURITY_ATTRIBUTES securityAttributes);
示例#25
0
 public static extern bool GetNamedPipeHandleState(
     SafeObjectHandle hNamedPipe,
     out PipeMode lpState,
     [In, Out] NullableUInt32 lpCurInstances,
     [In, Out] NullableUInt32 lpMaxCollectionCount,
     [In, Out] NullableUInt32 lpCollectDataTimeout,
     StringBuilder lpUserName,
     int nMaxUserNameSize);
示例#26
0
 public static extern bool SetNamedPipeHandleState(SafePipeHandle hNamedPipe, ref PipeMode mode, IntPtr maxCollectionCount, IntPtr collectDataTimeout);
示例#27
0
 public static extern unsafe bool GetNamedPipeHandleState(
     SafeObjectHandle hNamedPipe,
     out PipeMode lpState,
     [Friendly(FriendlyFlags.Bidirectional | FriendlyFlags.Optional)] int* lpCurInstances,
     [Friendly(FriendlyFlags.Bidirectional | FriendlyFlags.Optional)] int* lpMaxCollectionCount,
     [Friendly(FriendlyFlags.Bidirectional | FriendlyFlags.Optional)] int* lpCollectDataTimeout,
     StringBuilder lpUserName,
     int nMaxUserNameSize);
示例#28
0
 public NullablePipeMode(PipeMode value)
 {
     this.Value = value;
 }