Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / Monitoring / System / Diagnostics / Design / LogConverter.cs / 1 / LogConverter.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
*/
namespace System.Diagnostics.Design {
using System.Runtime.Serialization.Formatters;
using System.ComponentModel;
using System.Diagnostics;
using System;
using System.Collections;
using System.Windows.Forms;
using Microsoft.Win32;
using System.ComponentModel.Design;
using System.Globalization;
///
///
/// LogConverter is the TypeConverter for the Log property on EventLog. It returns
/// a list of all event logs on the system.
///
[System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand, Flags=System.Security.Permissions.SecurityPermissionFlag.UnmanagedCode)]
public class LogConverter : TypeConverter {
///
///
///
/// Provides a that specifies the
/// possible values for the enumeration.
///
///
private StandardValuesCollection values;
private string oldMachineName;
///
///
///
/// Initializes a new instance of the LogConverter class for the given
/// type.
///
///
public LogConverter() {
}
///
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) {
if (sourceType == typeof(string)) {
return true;
}
return base.CanConvertFrom(context, sourceType);
}
///
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) {
if (value is string) {
string text = ((string)value).Trim();
return text;
}
return base.ConvertFrom(context, culture, value);
}
///
///
///
/// Gets a collection of standard values for the data type this validator is
/// designed for.
///
public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) {
EventLog component = (context == null) ? null : context.Instance as EventLog;
string machineName = ".";
if (component != null)
machineName = component.MachineName;
if (values == null || machineName != oldMachineName) {
try {
EventLog[] eventLogs = EventLog.GetEventLogs(machineName);
object[] names = new object[eventLogs.Length];
for (int i = 0; i < names.Length; i++)
names[i] = eventLogs[i].Log;
values = new StandardValuesCollection(names);
oldMachineName = machineName;
}
catch(Exception) {
//Do Nothing
}
}
return values;
}
///
///
///
/// Gets a value indicating
/// whether this object
/// supports a standard set of values that can be picked
/// from a list using the specified context.
///
public override bool GetStandardValuesSupported(ITypeDescriptorContext context) {
return true;
}
}
}
// 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
- login.cs
- Schema.cs
- DynamicFilter.cs
- Vector3DConverter.cs
- ContractSearchPattern.cs
- ACL.cs
- ViewStateModeByIdAttribute.cs
- RadioButtonBaseAdapter.cs
- DriveInfo.cs
- WpfSharedBamlSchemaContext.cs
- TypeToStringValueConverter.cs
- DataRowExtensions.cs
- Base64Decoder.cs
- _SingleItemRequestCache.cs
- TableParagraph.cs
- TextEndOfParagraph.cs
- SortExpressionBuilder.cs
- Size3D.cs
- DotAtomReader.cs
- StyleTypedPropertyAttribute.cs
- ExpressionWriter.cs
- ObservableCollectionDefaultValueFactory.cs
- XamlTemplateSerializer.cs
- WindowsBrush.cs
- ReadOnlyNameValueCollection.cs
- MatrixCamera.cs
- ToolStripSeparator.cs
- MultiByteCodec.cs
- ExportException.cs
- ConfigXmlDocument.cs
- QueryTreeBuilder.cs
- MDIClient.cs
- Color.cs
- RowParagraph.cs
- SymmetricSecurityProtocol.cs
- Signature.cs
- WpfKnownType.cs
- LoaderAllocator.cs
- Compiler.cs
- ECDiffieHellman.cs
- SignatureToken.cs
- GridEntryCollection.cs
- AliasedSlot.cs
- ClientData.cs
- Triplet.cs
- GiveFeedbackEvent.cs
- WebPartMenu.cs
- CodeRegionDirective.cs
- StorageMappingItemLoader.cs
- ITextView.cs
- ImageCodecInfoPrivate.cs
- IndexedEnumerable.cs
- WorkflowServiceBehavior.cs
- PlainXmlWriter.cs
- TcpClientSocketManager.cs
- HtmlTable.cs
- AddressAlreadyInUseException.cs
- Query.cs
- GeneralTransform2DTo3D.cs
- AssemblySettingAttributes.cs
- _NegotiateClient.cs
- UserInitiatedNavigationPermission.cs
- Process.cs
- ProfessionalColors.cs
- DecimalKeyFrameCollection.cs
- TypeRefElement.cs
- PopOutPanel.cs
- SystemFonts.cs
- ArraySegment.cs
- MenuStrip.cs
- MetadataCache.cs
- StsCommunicationException.cs
- RoutedEvent.cs
- EventProviderWriter.cs
- DispatcherObject.cs
- Transform3DGroup.cs
- DefaultPrintController.cs
- LinearQuaternionKeyFrame.cs
- Missing.cs
- NamespaceCollection.cs
- DrawingImage.cs
- CodeLinePragma.cs
- ReadOnlyObservableCollection.cs
- UndirectedGraph.cs
- MenuBase.cs
- ObjectRef.cs
- FixedTextBuilder.cs
- panel.cs
- PointHitTestParameters.cs
- FrameworkElement.cs
- Comparer.cs
- cookiecontainer.cs
- Font.cs
- _SafeNetHandles.cs
- ClientProtocol.cs
- LineGeometry.cs
- FixedSOMTableCell.cs
- LocatorGroup.cs
- CustomMenuItemCollection.cs
- DataTableReaderListener.cs