Imported Upstream version 4.6.0.125

Former-commit-id: a2155e9bd80020e49e72e86c44da02a8ac0e57a4
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2016-08-03 10:59:49 +00:00
parent a569aebcfd
commit e79aa3c0ed
17047 changed files with 3137615 additions and 392334 deletions

View File

@@ -0,0 +1,42 @@
//------------------------------------------------------------------------------
// <copyright file="AlphabeticalEnumConverter.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Diagnostics {
using System.Collections;
using System.ComponentModel;
using System;
using System.Globalization;
/// <internalonly/>
/// <devdoc>
/// <para>
/// Provides a type converter to
/// convert ???? objects to and from various other representations.
/// </para>
/// </devdoc>
internal class AlphabeticalEnumConverter : EnumConverter {
public AlphabeticalEnumConverter(Type type) : base(type) {
}
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) {
if (Values == null) {
Array objValues = Enum.GetValues(EnumType);
//IComparer comparer = Comparer;
object[] names = new object[objValues.Length];
for (int i = 0; i < names.Length; i++)
names[i] = ConvertTo(context, null, objValues.GetValue(i), typeof(string));
Array.Sort(names, objValues, 0, objValues.Length, System.Collections.Comparer.Default);
Values = new StandardValuesCollection(objValues);
}
return Values;
}
}
}

View File

@@ -0,0 +1,301 @@
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: AsyncStreamReader
**
** Purpose: For reading text from streams using a particular
** encoding in an asychronous manner used by the process class
**
**
===========================================================*/
namespace System.Diagnostics {
using System;
using System.IO;
using System.Text;
using System.Runtime.InteropServices;
using System.Threading;
using System.Collections;
internal delegate void UserCallBack(String data);
internal class AsyncStreamReader : IDisposable
{
internal const int DefaultBufferSize = 1024; // Byte buffer size
private const int MinBufferSize = 128;
private Stream stream;
private Encoding encoding;
private Decoder decoder;
private byte[] byteBuffer;
private char[] charBuffer;
// Record the number of valid bytes in the byteBuffer, for a few checks.
// This is the maximum number of chars we can get from one call to
// ReadBuffer. Used so ReadBuffer can tell when to copy data into
// a user's char[] directly, instead of our internal char[].
private int _maxCharsPerBuffer;
// Store a backpointer to the process class, to check for user callbacks
private Process process;
// Delegate to call user function.
private UserCallBack userCallBack;
// Internal Cancel operation
private bool cancelOperation;
private ManualResetEvent eofEvent;
private Queue messageQueue;
private StringBuilder sb;
private bool bLastCarriageReturn;
// Cache the last position scanned in sb when searching for lines.
private int currentLinePos;
internal AsyncStreamReader(Process process, Stream stream, UserCallBack callback, Encoding encoding)
: this(process, stream, callback, encoding, DefaultBufferSize) {
}
// Creates a new AsyncStreamReader for the given stream. The
// character encoding is set by encoding and the buffer size,
// in number of 16-bit characters, is set by bufferSize.
//
internal AsyncStreamReader(Process process, Stream stream, UserCallBack callback, Encoding encoding, int bufferSize)
{
Debug.Assert (process != null && stream !=null && encoding !=null && callback != null, "Invalid arguments!");
Debug.Assert(stream.CanRead, "Stream must be readable!");
Debug.Assert(bufferSize > 0, "Invalid buffer size!");
Init(process, stream, callback, encoding, bufferSize);
messageQueue = new Queue();
}
private void Init(Process process, Stream stream, UserCallBack callback, Encoding encoding, int bufferSize) {
this.process = process;
this.stream = stream;
this.encoding = encoding;
this.userCallBack = callback;
decoder = encoding.GetDecoder();
if (bufferSize < MinBufferSize) bufferSize = MinBufferSize;
byteBuffer = new byte[bufferSize];
_maxCharsPerBuffer = encoding.GetMaxCharCount(bufferSize);
charBuffer = new char[_maxCharsPerBuffer];
cancelOperation = false;
eofEvent = new ManualResetEvent(false);
sb = null;
this.bLastCarriageReturn = false;
}
public virtual void Close()
{
Dispose(true);
}
void IDisposable.Dispose() {
Dispose(true);
GC.SuppressFinalize(this);
}
protected virtual void Dispose(bool disposing)
{
if (disposing) {
if (stream != null)
stream.Close();
}
if (stream != null) {
stream = null;
encoding = null;
decoder = null;
byteBuffer = null;
charBuffer = null;
}
if( eofEvent != null) {
eofEvent.Close();
eofEvent = null;
}
}
public virtual Encoding CurrentEncoding {
get { return encoding; }
}
public virtual Stream BaseStream {
get { return stream; }
}
// User calls BeginRead to start the asynchronous read
internal void BeginReadLine() {
if( cancelOperation) {
cancelOperation = false;
}
if( sb == null ) {
sb = new StringBuilder(DefaultBufferSize);
stream.BeginRead(byteBuffer, 0 , byteBuffer.Length, new AsyncCallback(ReadBuffer), null);
}
else {
FlushMessageQueue();
}
}
internal void CancelOperation() {
cancelOperation = true;
}
// This is the async callback function. Only one thread could/should call this.
private void ReadBuffer(IAsyncResult ar) {
int byteLen;
try {
byteLen = stream.EndRead(ar);
}
catch (IOException ) {
// We should ideally consume errors from operations getting cancelled
// so that we don't crash the unsuspecting parent with an unhandled exc.
// This seems to come in 2 forms of exceptions (depending on platform and scenario),
// namely OperationCanceledException and IOException (for errorcode that we don't
// map explicitly).
byteLen = 0; // Treat this as EOF
}
catch (OperationCanceledException ) {
// We should consume any OperationCanceledException from child read here
// so that we don't crash the parent with an unhandled exc
byteLen = 0; // Treat this as EOF
}
if (byteLen == 0) {
// We're at EOF, we won't call this function again from here on.
lock(messageQueue) {
if( sb.Length != 0) {
messageQueue.Enqueue(sb.ToString());
sb.Length = 0;
}
messageQueue.Enqueue(null);
}
try {
// UserCallback could throw, we should still set the eofEvent
FlushMessageQueue();
}
finally {
eofEvent.Set();
}
} else {
int charLen = decoder.GetChars(byteBuffer, 0, byteLen, charBuffer, 0);
sb.Append(charBuffer, 0, charLen);
GetLinesFromStringBuilder();
stream.BeginRead(byteBuffer, 0 , byteBuffer.Length, new AsyncCallback(ReadBuffer), null);
}
}
// Read lines stored in StringBuilder and the buffer we just read into.
// A line is defined as a sequence of characters followed by
// a carriage return ('\r'), a line feed ('\n'), or a carriage return
// immediately followed by a line feed. The resulting string does not
// contain the terminating carriage return and/or line feed. The returned
// value is null if the end of the input stream has been reached.
//
private void GetLinesFromStringBuilder() {
int currentIndex = currentLinePos;
int lineStart = 0;
int len = sb.Length;
// skip a beginning '\n' character of new block if last block ended
// with '\r'
if (bLastCarriageReturn && (len > 0) && sb[0] == '\n')
{
currentIndex = 1;
lineStart = 1;
bLastCarriageReturn = false;
}
while (currentIndex < len) {
char ch = sb[currentIndex];
// Note the following common line feed chars:
// \n - UNIX \r\n - DOS \r - Mac
if (ch == '\r' || ch == '\n') {
string s = sb.ToString(lineStart, currentIndex - lineStart);
lineStart = currentIndex + 1;
// skip the "\n" character following "\r" character
if ((ch == '\r') && (lineStart < len) && (sb[lineStart] == '\n'))
{
lineStart++;
currentIndex++;
}
lock(messageQueue) {
messageQueue.Enqueue(s);
}
}
currentIndex++;
}
if (sb[len - 1] == '\r') {
bLastCarriageReturn = true;
}
// Keep the rest characaters which can't form a new line in string builder.
if (lineStart < len) {
if (lineStart == 0) {
// we found no breaklines, in this case we cache the position
// so next time we don't have to restart from the beginning
currentLinePos = currentIndex;
}
else {
sb.Remove(0, lineStart);
currentLinePos = 0;
}
}
else {
sb.Length = 0;
currentLinePos = 0;
}
FlushMessageQueue();
}
private void FlushMessageQueue() {
while(true) {
// When we call BeginReadLine, we also need to flush the queue
// So there could be a ---- between the ReadBuffer and BeginReadLine
// We need to take lock before DeQueue.
if( messageQueue.Count > 0) {
lock(messageQueue) {
if( messageQueue.Count > 0) {
string s = (string)messageQueue.Dequeue();
// skip if the read is the read is cancelled
// this might happen inside UserCallBack
// However, continue to drain the queue
if (!cancelOperation)
{
userCallBack(s);
}
}
}
}
else {
break;
}
}
}
// Wait until we hit EOF. This is called from Process.WaitForExit
// We will lose some information if we don't do this.
internal void WaitUtilEOF() {
if( eofEvent != null) {
eofEvent.WaitOne();
eofEvent.Close();
eofEvent = null;
}
}
}
}

View File

@@ -0,0 +1,95 @@
//------------------------------------------------------------------------------
// <copyright file="CounterCreationData.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Diagnostics {
using System.Diagnostics;
using System;
using System.ComponentModel;
/// <devdoc>
/// A struct defining the counter type, name and help string for a custom counter.
/// </devdoc>
[
TypeConverter("System.Diagnostics.Design.CounterCreationDataConverter, " + AssemblyRef.SystemDesign),
Serializable
]
public class CounterCreationData {
private PerformanceCounterType counterType = PerformanceCounterType.NumberOfItems32;
private string counterName = String.Empty;
private string counterHelp = String.Empty;
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public CounterCreationData() {
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public CounterCreationData(string counterName, string counterHelp, PerformanceCounterType counterType) {
CounterType = counterType;
CounterName = counterName;
CounterHelp = counterHelp;
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
[
DefaultValue(PerformanceCounterType.NumberOfItems32),
MonitoringDescription(SR.CounterType)
]
public PerformanceCounterType CounterType {
get {
return counterType;
}
set {
if (!Enum.IsDefined(typeof(PerformanceCounterType), value))
throw new InvalidEnumArgumentException("value", (int)value, typeof(PerformanceCounterType));
counterType = value;
}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
[
DefaultValue(""),
MonitoringDescription(SR.CounterName),
TypeConverter("System.Diagnostics.Design.StringValueConverter, " + AssemblyRef.SystemDesign)
]
public string CounterName {
get {
return counterName;
}
set {
PerformanceCounterCategory.CheckValidCounter(value);
counterName = value;
}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
[
DefaultValue(""),
MonitoringDescription(SR.CounterHelp)
]
public string CounterHelp {
get {
return counterHelp;
}
set {
PerformanceCounterCategory.CheckValidHelp(value);
counterHelp = value;
}
}
}
}

View File

@@ -0,0 +1,127 @@
//------------------------------------------------------------------------------
// <copyright file="CounterCreationDataCollection.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Diagnostics {
using System;
using System.ComponentModel;
using System.Collections;
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
[Serializable()]
public class CounterCreationDataCollection : CollectionBase {
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public CounterCreationDataCollection() {
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public CounterCreationDataCollection(CounterCreationDataCollection value) {
this.AddRange(value);
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public CounterCreationDataCollection(CounterCreationData[] value) {
this.AddRange(value);
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public CounterCreationData this[int index] {
get {
return ((CounterCreationData)(List[index]));
}
set {
List[index] = value;
}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public int Add(CounterCreationData value) {
return List.Add(value);
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void AddRange(CounterCreationData[] value) {
if (value == null) {
throw new ArgumentNullException("value");
}
for (int i = 0; ((i) < (value.Length)); i = ((i) + (1))) {
this.Add(value[i]);
}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void AddRange(CounterCreationDataCollection value) {
if (value == null) {
throw new ArgumentNullException("value");
}
int currentCount = value.Count;
for (int i = 0; i < currentCount; i = ((i) + (1))) {
this.Add(value[i]);
}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public bool Contains(CounterCreationData value) {
return List.Contains(value);
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void CopyTo(CounterCreationData[] array, int index) {
List.CopyTo(array, index);
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public int IndexOf(CounterCreationData value) {
return List.IndexOf(value);
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void Insert(int index, CounterCreationData value) {
List.Insert(index, value);
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public virtual void Remove(CounterCreationData value) {
List.Remove(value);
}
protected override void OnValidate(object value) {
if (value == null)
throw new ArgumentNullException("value");
CounterCreationData dataToAdd = value as CounterCreationData;
if (dataToAdd == null)
throw new ArgumentException(SR.GetString(SR.MustAddCounterCreationData));
}
}
}

View File

@@ -0,0 +1,180 @@
//------------------------------------------------------------------------------
// <copyright file="CounterSample.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Diagnostics {
using System.Diagnostics;
using System;
/// <devdoc>
/// A struct holding the raw data for a performance counter.
/// </devdoc>
public struct CounterSample {
private long rawValue;
private long baseValue;
private long timeStamp;
private long counterFrequency;
private PerformanceCounterType counterType;
private long timeStamp100nSec;
private long systemFrequency;
private long counterTimeStamp;
// Dummy holder for an empty sample
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public static CounterSample Empty = new CounterSample(0, 0, 0, 0, 0, 0, PerformanceCounterType.NumberOfItems32);
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public CounterSample(long rawValue, long baseValue, long counterFrequency, long systemFrequency, long timeStamp, long timeStamp100nSec, PerformanceCounterType counterType) {
this.rawValue = rawValue;
this.baseValue = baseValue;
this.timeStamp = timeStamp;
this.counterFrequency = counterFrequency;
this.counterType = counterType;
this.timeStamp100nSec = timeStamp100nSec;
this.systemFrequency = systemFrequency;
this.counterTimeStamp = 0;
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public CounterSample(long rawValue, long baseValue, long counterFrequency, long systemFrequency, long timeStamp, long timeStamp100nSec, PerformanceCounterType counterType, long counterTimeStamp) {
this.rawValue = rawValue;
this.baseValue = baseValue;
this.timeStamp = timeStamp;
this.counterFrequency = counterFrequency;
this.counterType = counterType;
this.timeStamp100nSec = timeStamp100nSec;
this.systemFrequency = systemFrequency;
this.counterTimeStamp = counterTimeStamp;
}
/// <devdoc>
/// Raw value of the counter.
/// </devdoc>
public long RawValue {
get {
return this.rawValue;
}
}
internal ulong UnsignedRawValue {
get {
return (ulong)this.rawValue;
}
}
/// <devdoc>
/// Optional base raw value for the counter (only used if multiple counter based).
/// </devdoc>
public long BaseValue {
get {
return this.baseValue;
}
}
/// <devdoc>
/// Raw system frequency
/// </devdoc>
public long SystemFrequency {
get {
return this.systemFrequency;
}
}
/// <devdoc>
/// Raw counter frequency
/// </devdoc>
public long CounterFrequency {
get {
return this.counterFrequency;
}
}
/// <devdoc>
/// Raw counter frequency
/// </devdoc>
public long CounterTimeStamp {
get {
return this.counterTimeStamp;
}
}
/// <devdoc>
/// Raw timestamp
/// </devdoc>
public long TimeStamp {
get {
return this.timeStamp;
}
}
/// <devdoc>
/// Raw high fidelity timestamp
/// </devdoc>
public long TimeStamp100nSec {
get {
return this.timeStamp100nSec;
}
}
/// <devdoc>
/// Counter type
/// </devdoc>
public PerformanceCounterType CounterType {
get {
return this.counterType;
}
}
/// <devdoc>
/// Static functions to calculate the performance value off the sample
/// </devdoc>
public static float Calculate(CounterSample counterSample) {
return CounterSampleCalculator.ComputeCounterValue(counterSample);
}
/// <devdoc>
/// Static functions to calculate the performance value off the samples
/// </devdoc>
public static float Calculate(CounterSample counterSample, CounterSample nextCounterSample) {
return CounterSampleCalculator.ComputeCounterValue(counterSample, nextCounterSample);
}
public override bool Equals(Object o) {
return ( o is CounterSample) && Equals((CounterSample)o);
}
public bool Equals(CounterSample sample) {
return (rawValue == sample.rawValue) &&
(baseValue == sample.baseValue) &&
(timeStamp == sample.timeStamp) &&
(counterFrequency == sample.counterFrequency) &&
(counterType == sample.counterType) &&
(timeStamp100nSec == sample.timeStamp100nSec) &&
(systemFrequency == sample.systemFrequency) &&
(counterTimeStamp == sample.counterTimeStamp);
}
public override int GetHashCode() {
return rawValue.GetHashCode();
}
public static bool operator ==(CounterSample a, CounterSample b) {
return a.Equals(b);
}
public static bool operator !=(CounterSample a, CounterSample b) {
return !(a.Equals(b));
}
}
}

View File

@@ -0,0 +1,244 @@
//------------------------------------------------------------------------------
// <copyright file="CounterSampleCalculator.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Diagnostics {
using System.Threading;
using System;
using System.ComponentModel;
using Microsoft.Win32;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using System.Globalization;
using System.Runtime.Versioning;
/// <devdoc>
/// Set of utility functions for interpreting the counter data
/// NOTE: most of this code was taken and ported from counters.c (PerfMon source code)
/// </devdoc>
public static class CounterSampleCalculator {
static volatile bool perfCounterDllLoaded = false;
/// <devdoc>
/// Converts 100NS elapsed time to fractional seconds
/// </devdoc>
/// <internalonly/>
private static float GetElapsedTime(CounterSample oldSample, CounterSample newSample) {
float eSeconds;
float eDifference;
if (newSample.RawValue == 0) {
// no data [start time = 0] so return 0
return 0.0f;
}
else {
float eFreq;
eFreq = (float)(ulong)oldSample.CounterFrequency;
if (oldSample.UnsignedRawValue >= (ulong)newSample.CounterTimeStamp || eFreq <= 0.0f)
return 0.0f;
// otherwise compute difference between current time and start time
eDifference = (float)((ulong)newSample.CounterTimeStamp - oldSample.UnsignedRawValue);
// convert to fractional seconds using object counter
eSeconds = eDifference / eFreq;
return eSeconds;
}
}
/// <devdoc>
/// Computes the calculated value given a raw counter sample.
/// </devdoc>
public static float ComputeCounterValue(CounterSample newSample) {
return ComputeCounterValue(CounterSample.Empty, newSample);
}
/// <devdoc>
/// Computes the calculated value given a raw counter sample.
/// </devdoc>
public static float ComputeCounterValue(CounterSample oldSample, CounterSample newSample) {
int newCounterType = (int) newSample.CounterType;
if (oldSample.SystemFrequency == 0) {
if ((newCounterType != NativeMethods.PERF_RAW_FRACTION) &&
(newCounterType != NativeMethods.PERF_COUNTER_RAWCOUNT) &&
(newCounterType != NativeMethods.PERF_COUNTER_RAWCOUNT_HEX) &&
(newCounterType != NativeMethods.PERF_COUNTER_LARGE_RAWCOUNT) &&
(newCounterType != NativeMethods.PERF_COUNTER_LARGE_RAWCOUNT_HEX) &&
(newCounterType != NativeMethods.PERF_COUNTER_MULTI_BASE)) {
// Since oldSample has a system frequency of 0, this means the newSample is the first sample
// on a two sample calculation. Since we can't do anything with it, return 0.
return 0.0f;
}
}
else if (oldSample.CounterType != newSample.CounterType) {
throw new InvalidOperationException(SR.GetString(SR.MismatchedCounterTypes));
}
if (newCounterType == NativeMethods.PERF_ELAPSED_TIME)
return (float)GetElapsedTime(oldSample, newSample);
NativeMethods.PDH_RAW_COUNTER newPdhValue = new NativeMethods.PDH_RAW_COUNTER();
NativeMethods.PDH_RAW_COUNTER oldPdhValue = new NativeMethods.PDH_RAW_COUNTER();
FillInValues(oldSample, newSample, oldPdhValue, newPdhValue);
LoadPerfCounterDll();
NativeMethods.PDH_FMT_COUNTERVALUE pdhFormattedValue= new NativeMethods.PDH_FMT_COUNTERVALUE();
long timeBase = newSample.SystemFrequency;
int result = SafeNativeMethods.FormatFromRawValue((uint) newCounterType, NativeMethods.PDH_FMT_DOUBLE | NativeMethods.PDH_FMT_NOSCALE | NativeMethods.PDH_FMT_NOCAP100,
ref timeBase, newPdhValue, oldPdhValue, pdhFormattedValue);
if (result != NativeMethods.ERROR_SUCCESS) {
// If the numbers go negative, just return 0. This better matches the old behavior.
if (result == NativeMethods.PDH_CALC_NEGATIVE_VALUE || result == NativeMethods.PDH_CALC_NEGATIVE_DENOMINATOR || result == NativeMethods.PDH_NO_DATA)
return 0;
else
throw new Win32Exception(result, SR.GetString(SR.PerfCounterPdhError, result.ToString("x", CultureInfo.InvariantCulture)));
}
return (float) pdhFormattedValue.data;
}
// This method figures out which values are supposed to go into which structures so that PDH can do the
// calculation for us. This was ported from Window's cutils.c
private static void FillInValues(CounterSample oldSample, CounterSample newSample, NativeMethods.PDH_RAW_COUNTER oldPdhValue, NativeMethods.PDH_RAW_COUNTER newPdhValue) {
int newCounterType = (int) newSample.CounterType;
switch (newCounterType) {
case NativeMethods.PERF_COUNTER_COUNTER:
case NativeMethods.PERF_COUNTER_QUEUELEN_TYPE:
case NativeMethods.PERF_SAMPLE_COUNTER:
case NativeMethods.PERF_OBJ_TIME_TIMER:
case NativeMethods.PERF_COUNTER_OBJ_TIME_QUEUELEN_TYPE:
newPdhValue.FirstValue = newSample.RawValue;
newPdhValue.SecondValue = newSample.TimeStamp;
oldPdhValue.FirstValue = oldSample.RawValue;
oldPdhValue.SecondValue = oldSample.TimeStamp;
break;
case NativeMethods.PERF_COUNTER_100NS_QUEUELEN_TYPE:
newPdhValue.FirstValue = newSample.RawValue;
newPdhValue.SecondValue = newSample.TimeStamp100nSec;
oldPdhValue.FirstValue = oldSample.RawValue;
oldPdhValue.SecondValue = oldSample.TimeStamp100nSec;
break;
case NativeMethods.PERF_COUNTER_TIMER:
case NativeMethods.PERF_COUNTER_TIMER_INV:
case NativeMethods.PERF_COUNTER_BULK_COUNT:
case NativeMethods.PERF_COUNTER_LARGE_QUEUELEN_TYPE:
case NativeMethods.PERF_COUNTER_MULTI_TIMER:
case NativeMethods.PERF_COUNTER_MULTI_TIMER_INV:
newPdhValue.FirstValue = newSample.RawValue;
newPdhValue.SecondValue = newSample.TimeStamp;
oldPdhValue.FirstValue = oldSample.RawValue;
oldPdhValue.SecondValue = oldSample.TimeStamp;
if (newCounterType == NativeMethods.PERF_COUNTER_MULTI_TIMER || newCounterType == NativeMethods.PERF_COUNTER_MULTI_TIMER_INV) {
// this is to make PDH work like PERFMON for
// this counter type
newPdhValue.FirstValue *= (uint) newSample.CounterFrequency;
if (oldSample.CounterFrequency != 0) {
oldPdhValue.FirstValue *= (uint) oldSample.CounterFrequency;
}
}
if ((newCounterType & NativeMethods.PERF_MULTI_COUNTER) == NativeMethods.PERF_MULTI_COUNTER) {
newPdhValue.MultiCount = (int) newSample.BaseValue;
oldPdhValue.MultiCount = (int) oldSample.BaseValue;
}
break;
//
// These counters do not use any time reference
//
case NativeMethods.PERF_COUNTER_RAWCOUNT:
case NativeMethods.PERF_COUNTER_RAWCOUNT_HEX:
case NativeMethods.PERF_COUNTER_DELTA:
case NativeMethods.PERF_COUNTER_LARGE_RAWCOUNT:
case NativeMethods.PERF_COUNTER_LARGE_RAWCOUNT_HEX:
case NativeMethods.PERF_COUNTER_LARGE_DELTA:
newPdhValue.FirstValue = newSample.RawValue;
newPdhValue.SecondValue = 0;
oldPdhValue.FirstValue = oldSample.RawValue;
oldPdhValue.SecondValue = 0;
break;
//
// These counters use the 100 Ns time base in thier calculation
//
case NativeMethods.PERF_100NSEC_TIMER:
case NativeMethods.PERF_100NSEC_TIMER_INV:
case NativeMethods.PERF_100NSEC_MULTI_TIMER:
case NativeMethods.PERF_100NSEC_MULTI_TIMER_INV:
newPdhValue.FirstValue = newSample.RawValue;
newPdhValue.SecondValue = newSample.TimeStamp100nSec;
oldPdhValue.FirstValue = oldSample.RawValue;
oldPdhValue.SecondValue = oldSample.TimeStamp100nSec;
if ((newCounterType & NativeMethods.PERF_MULTI_COUNTER) == NativeMethods.PERF_MULTI_COUNTER) {
newPdhValue.MultiCount = (int) newSample.BaseValue;
oldPdhValue.MultiCount = (int) oldSample.BaseValue;
}
break;
//
// These counters use two data points
//
case NativeMethods.PERF_SAMPLE_FRACTION:
case NativeMethods.PERF_RAW_FRACTION:
case NativeMethods.PERF_LARGE_RAW_FRACTION:
case NativeMethods.PERF_PRECISION_SYSTEM_TIMER:
case NativeMethods.PERF_PRECISION_100NS_TIMER:
case NativeMethods.PERF_PRECISION_OBJECT_TIMER:
case NativeMethods.PERF_AVERAGE_TIMER:
case NativeMethods.PERF_AVERAGE_BULK:
newPdhValue.FirstValue = newSample.RawValue;
newPdhValue.SecondValue = newSample.BaseValue;
oldPdhValue.FirstValue = oldSample.RawValue;
oldPdhValue.SecondValue = oldSample.BaseValue;
break;
default:
// an unidentified counter was returned so
newPdhValue.FirstValue = 0;
newPdhValue.SecondValue = 0;
oldPdhValue.FirstValue = 0;
oldPdhValue.SecondValue = 0;
break;
}
}
[ResourceExposure(ResourceScope.None)]
[ResourceConsumption(ResourceScope.Machine, ResourceScope.Machine)]
private static void LoadPerfCounterDll() {
if (perfCounterDllLoaded)
return;
new FileIOPermission(PermissionState.Unrestricted).Assert();
string installPath = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory();
string perfcounterPath = Path.Combine(installPath, "perfcounter.dll");
if (SafeNativeMethods.LoadLibrary(perfcounterPath) == IntPtr.Zero) {
throw new Win32Exception( Marshal.GetLastWin32Error() );
}
perfCounterDllLoaded = true;
}
}
}

View File

@@ -0,0 +1,25 @@
//------------------------------------------------------------------------------
// <copyright file="Process.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Diagnostics {
using System;
public delegate void DataReceivedEventHandler(Object sender, DataReceivedEventArgs e);
public class DataReceivedEventArgs : EventArgs {
internal String _data;
internal DataReceivedEventArgs(String data) {
_data = data;
}
public String Data {
get {
return _data;
}
}
}
}

View File

@@ -0,0 +1,264 @@
//------------------------------------------------------------------------------
// <copyright file="DiagnosticsConfigurationHandler.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
#if !LIB
#define TRACE
#define DEBUG
namespace System.Diagnostics {
using System;
using System.Collections;
using System.Diagnostics;
using System.Xml;
using System.Configuration;
using System.Reflection;
using System.Globalization;
/// <devdoc>
/// The configuration section handler for the diagnostics section of the configuration
/// file. The section handler participates in the resolution of configuration settings
/// between the &lt;diagnostics&gt; and &lt;/diagnostics&gt;portion of the .config file.
/// </devdoc>
/// <internalonly/>
[Obsolete("This class has been deprecated. http://go.microsoft.com/fwlink/?linkid=14202")]
public class DiagnosticsConfigurationHandler : IConfigurationSectionHandler {
/// <devdoc>
/// <para>Parses the configuration settings between the
/// &lt;diagnostics&gt; and &lt;/diagnostics&gt; portion of the .config file to populate
/// the values of 'WebServicesConfiguration' object and returning it.
/// </para>
/// </devdoc>
/// <internalonly/>
public virtual object Create(object parent, object configContext, XmlNode section) {
bool foundSwitches = false;
bool foundAssert = false;
bool foundTrace = false;
bool foundCounters = false;
HandlerBase.CheckForUnrecognizedAttributes(section);
// Since the tracing and switch code lives in System.Dll and config is in System.Configuration.dll
// the settings just go into a hashtable to communicate to the values to the diagnostics code in System.dll
Hashtable parentConfig = (Hashtable)parent;
Hashtable config;
if (parentConfig == null)
config = new Hashtable();
else
config = (Hashtable)parentConfig.Clone();
foreach (XmlNode child in section.ChildNodes) {
if (HandlerBase.IsIgnorableAlsoCheckForNonElement(child))
continue;
switch (child.Name) {
case "switches":
if (foundSwitches)
throw new ConfigurationErrorsException(SR.GetString(SR.ConfigSectionsUnique, "switches"));
foundSwitches = true;
HandleSwitches(config, child, configContext);
break;
case "assert":
if (foundAssert)
throw new ConfigurationErrorsException(SR.GetString(SR.ConfigSectionsUnique, "assert"));
foundAssert = true;
HandleAssert(config, child, configContext);
break;
case "trace":
if (foundTrace)
throw new ConfigurationErrorsException(SR.GetString(SR.ConfigSectionsUnique, "trace"));
foundTrace = true;
HandleTrace(config, child, configContext);
break;
case "performanceCounters":
if (foundCounters)
throw new ConfigurationErrorsException(SR.GetString(SR.ConfigSectionsUnique, "performanceCounters"));
foundCounters = true;
HandleCounters((Hashtable)parent, config, child, configContext);
break;
default:
HandlerBase.ThrowUnrecognizedElement(child);
break;
} // switch(child.Name)
HandlerBase.CheckForUnrecognizedAttributes(child);
}
return config;
}
private static void HandleSwitches(Hashtable config, XmlNode switchesNode, object context) {
Hashtable switches = (Hashtable) new SwitchesDictionarySectionHandler().Create(config["switches"], context, switchesNode);
IDictionaryEnumerator en = switches.GetEnumerator();
while (en.MoveNext()) {
try {
Int32.Parse((string) en.Value, CultureInfo.InvariantCulture);
}
catch {
throw new ConfigurationErrorsException(SR.GetString(SR.Value_must_be_numeric, en.Key));
}
}
config["switches"] = switches;
}
private static void HandleAssert(Hashtable config, XmlNode assertNode, object context) {
bool assertuienabled = false;
if (HandlerBase.GetAndRemoveBooleanAttribute(assertNode, "assertuienabled", ref assertuienabled) != null)
config["assertuienabled"] = assertuienabled;
string logfilename = null;
if (HandlerBase.GetAndRemoveStringAttribute(assertNode, "logfilename", ref logfilename) != null)
config["logfilename"] = logfilename;
HandlerBase.CheckForChildNodes(assertNode);
}
private static void HandleCounters(Hashtable parent, Hashtable config, XmlNode countersNode, object context) {
int filemappingsize = 0;
if (HandlerBase.GetAndRemoveIntegerAttribute(countersNode, "filemappingsize", ref filemappingsize) != null) {
//Should only be handled at machine config level
if (parent == null)
config["filemappingsize"] = filemappingsize;
}
HandlerBase.CheckForChildNodes(countersNode);
}
private static void HandleTrace(Hashtable config, XmlNode traceNode, object context) {
bool foundListeners = false;
bool autoflush = false;
if (HandlerBase.GetAndRemoveBooleanAttribute(traceNode, "autoflush", ref autoflush) != null)
config["autoflush"] = autoflush;
int indentsize = 0;
if (HandlerBase.GetAndRemoveIntegerAttribute(traceNode, "indentsize", ref indentsize) != null)
config["indentsize"] = indentsize;
foreach (XmlNode traceChild in traceNode.ChildNodes) {
if (HandlerBase.IsIgnorableAlsoCheckForNonElement(traceChild))
continue;
if (traceChild.Name == "listeners") {
if (foundListeners)
throw new ConfigurationErrorsException(SR.GetString(SR.ConfigSectionsUnique, "listeners"));
foundListeners = true;
HandleListeners(config, traceChild, context);
}
else {
HandlerBase.ThrowUnrecognizedElement(traceChild);
}
}
}
private static void HandleListeners(Hashtable config, XmlNode listenersNode, object context) {
HandlerBase.CheckForUnrecognizedAttributes(listenersNode);
foreach (XmlNode listenersChild in listenersNode.ChildNodes) {
if (HandlerBase.IsIgnorableAlsoCheckForNonElement(listenersChild))
continue;
string name = null, className = null, initializeData = null;
string op = listenersChild.Name;
switch (op) {
case "add":
case "remove":
case "clear":
break;
default:
HandlerBase.ThrowUnrecognizedElement(listenersChild);
break;
}
HandlerBase.GetAndRemoveStringAttribute(listenersChild, "name", ref name);
HandlerBase.GetAndRemoveStringAttribute(listenersChild, "type", ref className);
HandlerBase.GetAndRemoveStringAttribute(listenersChild, "initializeData", ref initializeData);
HandlerBase.CheckForUnrecognizedAttributes(listenersChild);
HandlerBase.CheckForChildNodes(listenersChild);
TraceListener newListener = null;
if (className != null) {
Type t = Type.GetType(className);
if (t == null)
throw new ConfigurationErrorsException(SR.GetString(SR.Could_not_find_type, className));
if (!typeof(TraceListener).IsAssignableFrom(t))
throw new ConfigurationErrorsException(SR.GetString(SR.Type_isnt_tracelistener, className));
// create a listener with parameterless constructor
if (initializeData == null) {
ConstructorInfo ctorInfo = t.GetConstructor(new Type[] {});
if (ctorInfo == null)
throw new ConfigurationErrorsException(SR.GetString(SR.Could_not_get_constructor, className));
newListener = (TraceListener)(SecurityUtils.ConstructorInfoInvoke(ctorInfo, new object[] { }));
}
// create a listener with a one-string constructor
else {
ConstructorInfo ctorInfo = t.GetConstructor(new Type[] { typeof(string) });
if (ctorInfo == null)
throw new ConfigurationErrorsException(SR.GetString(SR.Could_not_get_constructor, className));
newListener = (TraceListener)(SecurityUtils.ConstructorInfoInvoke(ctorInfo, new object[] { initializeData }));
}
if (name != null) {
newListener.Name = name;
}
}
// we already verified above that we only have "add", "remove", or "clear", so we can
// switch on the first char here for perf.
switch (op[0]) {
case 'a':
if (newListener == null)
throw new ConfigurationErrorsException(SR.GetString(SR.Could_not_create_listener, name));
Trace.Listeners.Add(newListener);
break;
case 'r':
if (newListener == null) {
// no type specified, we'll have to delete by name
// if no name is specified we can't do anything
if (name == null)
throw new ConfigurationErrorsException(SR.GetString(SR.Cannot_remove_with_null));
Trace.Listeners.Remove(name);
}
else {
// remove by listener
Trace.Listeners.Remove(newListener);
}
break;
case 'c':
Trace.Listeners.Clear();
break;
default:
HandlerBase.ThrowUnrecognizedElement(listenersChild);
break;
}
}
}
}
internal class SwitchesDictionarySectionHandler : DictionarySectionHandler {
protected override string KeyAttributeName {
get { return "name";}
}
internal override bool ValueRequired {
get { return true; }
}
}
}
#endif

View File

@@ -0,0 +1,56 @@
//------------------------------------------------------------------------------
// <copyright file="EntryWrittenEventArgs.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Diagnostics {
using System.Diagnostics;
using System;
using System.ComponentModel;
/// <devdoc>
/// <para>
/// Provides data for the <see cref='System.Diagnostics.EventLog.EntryWritten'/> event.
/// </para>
/// </devdoc>
public class EntryWrittenEventArgs : EventArgs {
private EventLogEntry entry;
/// <devdoc>
/// <para>
/// The default constructor, which
/// initializes a new instance of the <see cref='System.Diagnostics.EntryWrittenEventArgs'/> class without
/// specifying a value for <see cref='System.Diagnostics.EntryWrittenEventArgs.Entry'/>.
///
/// </para>
/// </devdoc>
public EntryWrittenEventArgs() {
}
/// <devdoc>
/// <para>
/// Initializes a new instance of the <see cref='System.Diagnostics.EntryWrittenEventArgs'/> class with the
/// specified event log entry.
/// </para>
/// </devdoc>
public EntryWrittenEventArgs(EventLogEntry entry) {
this.entry = entry;
}
/// <devdoc>
/// <para>
/// Represents
/// an event log entry.
///
/// </para>
/// </devdoc>
public EventLogEntry Entry {
get {
return this.entry;
}
}
}
}

View File

@@ -0,0 +1,17 @@
//------------------------------------------------------------------------------
// <copyright file="EntryWrittenEventHandler.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Diagnostics {
using System.Diagnostics;
using System;
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public delegate void EntryWrittenEventHandler(object sender, EntryWrittenEventArgs e);
}

View File

@@ -0,0 +1,52 @@
using System.ComponentModel;
using System.Security.Permissions;
using System.Security;
namespace System.Diagnostics {
public class EventInstance {
private int _categoryNumber;
private EventLogEntryType _entryType = EventLogEntryType.Information;
private long _instanceId;
public EventInstance(long instanceId, int categoryId) {
CategoryId = categoryId;
InstanceId = instanceId;
}
public EventInstance(long instanceId, int categoryId, EventLogEntryType entryType) : this (instanceId, categoryId) {
EntryType = entryType;
}
public int CategoryId {
get { return _categoryNumber; }
set {
if (value > UInt16.MaxValue || value < 0)
throw new ArgumentOutOfRangeException("value");
_categoryNumber = value;
}
}
public EventLogEntryType EntryType {
get { return _entryType; }
set {
if (!Enum.IsDefined(typeof(EventLogEntryType), value))
throw new InvalidEnumArgumentException("value", (int)value, typeof(EventLogEntryType));
_entryType = value;
}
}
public long InstanceId {
get { return _instanceId; }
set {
if (value > UInt32.MaxValue || value < 0)
throw new ArgumentOutOfRangeException("value");
_instanceId = value;
}
}
}
}

View File

@@ -0,0 +1,143 @@
//------------------------------------------------------------------------------
// <copyright file="EventLogEntryCollection.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Diagnostics {
using System.Text;
using System;
using System.Collections;
//Consider, V2, [....]: Is there a way to implement Contains
//and IndexOf, can we live withouth this part of the ReadOnly
//collection pattern?
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public class EventLogEntryCollection : ICollection {
private EventLogInternal log;
internal EventLogEntryCollection(EventLogInternal log) {
this.log = log;
}
/// <devdoc>
/// <para>
/// Gets the number of entries in the event log
/// </para>
/// </devdoc>
public int Count {
get {
return log.EntryCount;
}
}
/// <devdoc>
/// <para>
/// Gets an entry in
/// the event log, based on an index starting at 0.
/// </para>
/// </devdoc>
public virtual EventLogEntry this[int index] {
get {
return log.GetEntryAt(index);
}
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public void CopyTo(EventLogEntry[] entries, int index) {
((ICollection)this).CopyTo((Array)entries, index);
}
/// <devdoc>
/// </devdoc>
public IEnumerator GetEnumerator() {
return new EntriesEnumerator(this);
}
internal EventLogEntry GetEntryAtNoThrow(int index) {
return log.GetEntryAtNoThrow(index);
}
/// <internalonly/>
bool ICollection.IsSynchronized {
get {
return false;
}
}
/// <devdoc>
/// ICollection private interface implementation.
/// </devdoc>
/// <internalonly/>
object ICollection.SyncRoot {
get {
return this;
}
}
/// <devdoc>
/// ICollection private interface implementation.
/// </devdoc>
/// <internalonly/>
void ICollection.CopyTo(Array array, int index) {
EventLogEntry[] entries = log.GetAllEntries();
Array.Copy(entries, 0, array, index, entries.Length);
}
/// <devdoc>
/// <para>
/// Holds an System.Diagnostics.EventLog.EventLogEntryCollection that
/// consists of the entries in an event
/// log.
/// </para>
/// </devdoc>
private class EntriesEnumerator : IEnumerator {
private EventLogEntryCollection entries;
private int num = -1;
private EventLogEntry cachedEntry = null;
internal EntriesEnumerator(EventLogEntryCollection entries) {
this.entries = entries;
}
/// <devdoc>
/// <para>
/// Gets the entry at the current position.
/// </para>
/// </devdoc>
public object Current {
get {
if (cachedEntry == null)
throw new InvalidOperationException(SR.GetString(SR.NoCurrentEntry));
return cachedEntry;
}
}
/// <devdoc>
/// <para>
/// Advances the enumerator to the next entry in the event log.
/// </para>
/// </devdoc>
public bool MoveNext() {
num++;
cachedEntry = entries.GetEntryAtNoThrow(num);
return cachedEntry != null;
}
/// <devdoc>
/// <para>
/// Resets the state of the enumeration.
/// </para>
/// </devdoc>
public void Reset() {
num = -1;
}
}
}
}

View File

@@ -0,0 +1,66 @@
//------------------------------------------------------------------------------
// <copyright file="EventLogEntryType.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Diagnostics {
using System.Diagnostics;
// cpr: make this class an enum
using System;
/// <devdoc>
/// <para>
/// Specifies the event type of the event log entry.
///
/// </para>
/// </devdoc>
public enum EventLogEntryType {
/// <devdoc>
/// <para>
/// An
/// error event. This indicates a significant problem the
/// user should know about; usually a loss of
/// functionality or data.
///
/// </para>
/// </devdoc>
Error = 1,
/// <devdoc>
/// <para>
/// A warning event. This indicates a problem that is not
/// immediately significant, but that may signify conditions that could
/// cause future problems.
///
/// </para>
/// </devdoc>
Warning = 2,
/// <devdoc>
/// <para>
/// An information event. This indicates a significant successful
/// operation.
/// </para>
/// </devdoc>
Information = 4,
/// <devdoc>
/// <para>
/// A success audit event. This indicates a security event
/// that occurs when an audited access attempt is successful; for
/// example, a successful logon.
///
/// </para>
/// </devdoc>
SuccessAudit = 8,
/// <devdoc>
/// <para>
/// A failure audit event. This indicates a security event
/// that occurs when an audited access attempt fails; for example, a failed attempt
/// to open a file.
///
/// </para>
/// </devdoc>
FailureAudit = 16,
}
}

View File

@@ -0,0 +1,87 @@
//------------------------------------------------------------------------------
// <copyright file="EventLogPermission.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Diagnostics {
using System;
using System.Security.Permissions;
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
[
Serializable()
]
public sealed class EventLogPermission : ResourcePermissionBase {
private EventLogPermissionEntryCollection innerCollection;
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public EventLogPermission() {
SetNames();
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public EventLogPermission(PermissionState state)
: base(state) {
SetNames();
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public EventLogPermission(EventLogPermissionAccess permissionAccess, string machineName) {
SetNames();
this.AddPermissionAccess(new EventLogPermissionEntry(permissionAccess, machineName));
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public EventLogPermission(EventLogPermissionEntry[] permissionAccessEntries) {
if (permissionAccessEntries == null)
throw new ArgumentNullException("permissionAccessEntries");
SetNames();
for (int index = 0; index < permissionAccessEntries.Length; ++index)
this.AddPermissionAccess(permissionAccessEntries[index]);
}
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
public EventLogPermissionEntryCollection PermissionEntries {
get {
if (this.innerCollection == null)
this.innerCollection = new EventLogPermissionEntryCollection(this, base.GetPermissionEntries());
return this.innerCollection;
}
}
///<internalonly/>
internal void AddPermissionAccess(EventLogPermissionEntry entry) {
base.AddPermissionAccess(entry.GetBaseEntry());
}
///<internalonly/>
internal new void Clear() {
base.Clear();
}
///<internalonly/>
internal void RemovePermissionAccess(EventLogPermissionEntry entry) {
base.RemovePermissionAccess(entry.GetBaseEntry());
}
private void SetNames() {
this.PermissionAccessType = typeof(EventLogPermissionAccess);
this.TagNames = new string[]{"Machine"};
}
}
}

View File

@@ -0,0 +1,32 @@
//------------------------------------------------------------------------------
// <copyright file="EventLogPermissionAccess.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Diagnostics {
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
[Flags]
public enum EventLogPermissionAccess {
/// <devdoc>
/// <para>[To be supplied.]</para>
/// </devdoc>
None = 0,
Write = 0x10,
Administer = 0x20 | Write,
#pragma warning disable 618
[Obsolete("This member has been deprecated. Please use System.Diagnostics.EventLogPermissionAccess.Administer instead. http://go.microsoft.com/fwlink/?linkid=14202")]
Browse = 0x02,
[Obsolete("This member has been deprecated. Please use System.Diagnostics.EventLogPermissionAccess.Write instead. http://go.microsoft.com/fwlink/?linkid=14202")]
Instrument = 0x04 | Browse,
[Obsolete("This member has been deprecated. Please use System.Diagnostics.EventLogPermissionAccess.Administer instead. http://go.microsoft.com/fwlink/?linkid=14202")]
Audit = 0x08 | Browse,
#pragma warning restore 618
}
}

View File

@@ -0,0 +1,58 @@
//------------------------------------------------------------------------------
// <copyright file="EventLogPermissionAttribute.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Diagnostics {
using System.ComponentModel;
using System.Security;
using System.Security.Permissions;
[
AttributeUsage(AttributeTargets.Method | AttributeTargets.Constructor | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Assembly | AttributeTargets.Event, AllowMultiple = true, Inherited = false ),
Serializable()
]
public class EventLogPermissionAttribute : CodeAccessSecurityAttribute {
private string machineName;
private EventLogPermissionAccess permissionAccess;
public EventLogPermissionAttribute(SecurityAction action)
: base(action) {
this.machineName = ".";
this.permissionAccess = EventLogPermissionAccess.Write;
}
public string MachineName {
get {
return this.machineName;
}
set {
if (!SyntaxCheck.CheckMachineName(value))
throw new ArgumentException(SR.GetString(SR.InvalidProperty, "MachineName", value));
this.machineName = value;
}
}
public EventLogPermissionAccess PermissionAccess {
get {
return this.permissionAccess;
}
set {
this.permissionAccess = value;
}
}
public override IPermission CreatePermission() {
if (Unrestricted)
return new EventLogPermission(PermissionState.Unrestricted);
return new EventLogPermission(this.PermissionAccess, this.MachineName);
}
}
}

View File

@@ -0,0 +1,52 @@
//----------------------------------------------------
// <copyright file="EventLogPermissionEntry.cs" company="Microsoft">
// Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
//------------------------------------------------------------------------------
namespace System.Diagnostics {
using System.ComponentModel;
using System.Security.Permissions;
[
Serializable()
]
public class EventLogPermissionEntry {
private string machineName;
private EventLogPermissionAccess permissionAccess;
public EventLogPermissionEntry(EventLogPermissionAccess permissionAccess, string machineName) {
if (!SyntaxCheck.CheckMachineName(machineName))
throw new ArgumentException(SR.GetString(SR.InvalidParameter, "MachineName", machineName));
this.permissionAccess = permissionAccess;
this.machineName = machineName;
}
///<internalonly/>
internal EventLogPermissionEntry(ResourcePermissionBaseEntry baseEntry) {
this.permissionAccess = (EventLogPermissionAccess)baseEntry.PermissionAccess;
this.machineName = baseEntry.PermissionAccessPath[0];
}
public string MachineName {
get {
return this.machineName;
}
}
public EventLogPermissionAccess PermissionAccess {
get {
return this.permissionAccess;
}
}
///<internalonly/>
internal ResourcePermissionBaseEntry GetBaseEntry() {
ResourcePermissionBaseEntry baseEntry = new ResourcePermissionBaseEntry((int)this.PermissionAccess, new string[] {this.MachineName});
return baseEntry;
}
}
}

Some files were not shown because too many files have changed in this diff Show More