Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Wmi / managed / System / Management / Instrumentation / ManagementInstaller.cs / 1305376 / ManagementInstaller.cs
namespace System.Management.Instrumentation
{
using System;
using System.Reflection;
using System.Collections;
using System.Configuration.Install;
using System.Text;
using System.IO;
using System.Runtime.Versioning;
using System.Globalization;
using System.Security.Permissions;
///
/// Installs instrumented assemblies. Include an instance of this installer class in the project installer for
/// an assembly that includes instrumentation.
///
///
/// If this is the only installer for your application, you may use the helper class
/// provided in this namespace.
///
///
/// If you have a master project installer for your
/// project, add the following code to your project installers constructor:
/// // Instantiate installer for assembly.
/// ManagementInstaller managementInstaller = new ManagementInstaller();
///
/// // Add installer to collection.
/// Installers.Add(managementInstaller);
///
/// 'Instantiate installer for assembly.
/// Dim managementInstaller As New ManagementInstaller()
///
/// 'Add installer to collection.
/// Installers.Add(managementInstaller)
///
///
public class ManagementInstaller : Installer
{
//
private static bool helpPrinted = false;
///
/// Gets or sets installer options for this class.
///
///
/// The help text for all the installers in the installer collection, including
/// the description of what each installer does and the command-line options (for
/// the installation program) that can be passed to and understood by each
/// installer.
///
public override string HelpText {
get {
if (helpPrinted)
return base.HelpText;
else {
helpPrinted = true;
// return Res.GetString(Res.HelpText) + "\r\n" + base.HelpText;
//
StringBuilder help = new StringBuilder();
help.Append("/MOF=[filename]\r\n");
help.Append(" " + RC.GetString("FILETOWRITE_MOF")+"\r\n\r\n");
//
// [RAID: 123895]
// If the force parameter is present, we update registration information independent if it already
// exists.
//
help.Append ( "/Force or /F\r\n" ) ;
help.Append(" " + RC.GetString("FORCE_UPDATE"));
return help.ToString() + base.HelpText;
}
}
}
///
/// Installs the assembly.
///
/// The state of the assembly.
[ResourceExposure(ResourceScope.None),ResourceConsumption(ResourceScope.Machine,ResourceScope.Machine)]
public override void Install(IDictionary savedState)
{
// Demand IO permission required for LoadFrom FXCop 191096
FileIOPermission ioPermission = new FileIOPermission(FileIOPermissionAccess.Read, (string)Context.Parameters["assemblypath"]);
ioPermission.Demand();
base.Install(savedState);
//
Context.LogMessage(RC.GetString("WMISCHEMA_INSTALLATIONSTART"));
string assemblyPath = Context.Parameters["assemblypath"];
Assembly assembly = Assembly.LoadFrom(assemblyPath);
SchemaNaming naming = SchemaNaming.GetSchemaNaming(assembly);
//
// We always use the full version number for Whidbey.
//
naming.DecoupledProviderInstanceName = AssemblyNameUtility.UniqueToAssemblyFullVersion(assembly);
// See if this assembly provides instrumentation
if(null == naming)
return;
//
// [RAID: 123895]
// If the force parameter is present, we update registration information independent if it already
// exists.
//
if( ( naming.IsAssemblyRegistered() == false ) || ( Context.Parameters.ContainsKey ( "force" ) ) || ( Context.Parameters.ContainsKey ( "f" ) ) )
{
Context.LogMessage(RC.GetString("REGESTRING_ASSEMBLY") + " " + naming.DecoupledProviderInstanceName);
naming.RegisterNonAssemblySpecificSchema(Context);
naming.RegisterAssemblySpecificSchema();
}
mof = naming.Mof;
Context.LogMessage(RC.GetString("WMISCHEMA_INSTALLATIONEND"));
}
string mof;
///
/// Commits the assembly to the operation.
///
/// The state of the assembly.
[ResourceExposure(ResourceScope.None),ResourceConsumption(ResourceScope.Machine,ResourceScope.Machine)]
public override void Commit(IDictionary savedState) {
base.Commit(savedState);
// See if we were asked to generate a MOF file
if(Context.Parameters.ContainsKey("mof"))
{
string mofFile = Context.Parameters["mof"];
// bug#62252 - Pick a default MOF file name
if(mofFile == null || mofFile.Length == 0)
{
mofFile = Context.Parameters["assemblypath"];
if(mofFile == null || mofFile.Length == 0)
mofFile = "defaultmoffile";
else
mofFile = Path.GetFileName(mofFile);
}
// Append '.mof' in necessary
if(mofFile.Length<4)
mofFile += ".mof";
else
{
if(String.Compare(mofFile.Substring(mofFile.Length-4,4),".mof",StringComparison.OrdinalIgnoreCase)!=0)
mofFile += ".mof";
}
Context.LogMessage(RC.GetString("MOFFILE_GENERATING") + " " + mofFile);
using(StreamWriter log = new StreamWriter(mofFile, false, Encoding.Unicode))
{
log.WriteLine("//**************************************************************************");
log.WriteLine("//* {0}", mofFile);
log.WriteLine("//**************************************************************************");
log.WriteLine(mof);
}
}
}
///
/// Rolls back the state of the assembly.
///
/// The state of the assembly.
public override void Rollback(IDictionary savedState) {
base.Rollback(savedState);
}
///
/// Uninstalls the assembly.
///
/// The state of the assembly.
public override void Uninstall(IDictionary savedState) {
base.Uninstall(savedState);
}
}
///
/// Installs an instrumented assembly. This class is a default project installer for assemblies that contain
/// management instrumentation and do not use other installers (such as services, or message
/// queues). To use this default project installer, simply derive a class from
/// inside the assembly. No methods need
/// to be overridden.
///
///
/// If your project has a master project
/// installer, use the class instead.
///
///
/// Add the following code to your instrumented assembly to enable the installation step:
/// [System.ComponentModel.RunInstaller(true)]
/// public class MyInstaller : DefaultManagementProjectInstaller {}
///
/// <System.ComponentModel.RunInstaller(true)>
/// public class MyInstaller
/// Inherits DefaultManagementProjectInstaller
///
///
public class DefaultManagementProjectInstaller : Installer
{
///
/// Initializes a new instance of the
/// class. This is the default constructor.
///
public DefaultManagementProjectInstaller()
{
// Instantiate installer for assembly.
ManagementInstaller managementInstaller = new ManagementInstaller();
// Add installers to collection. Order is not important.
Installers.Add(managementInstaller);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
namespace System.Management.Instrumentation
{
using System;
using System.Reflection;
using System.Collections;
using System.Configuration.Install;
using System.Text;
using System.IO;
using System.Runtime.Versioning;
using System.Globalization;
using System.Security.Permissions;
///
/// Installs instrumented assemblies. Include an instance of this installer class in the project installer for
/// an assembly that includes instrumentation.
///
///
/// If this is the only installer for your application, you may use the helper class
/// provided in this namespace.
///
///
/// If you have a master project installer for your
/// project, add the following code to your project installers constructor:
/// // Instantiate installer for assembly.
/// ManagementInstaller managementInstaller = new ManagementInstaller();
///
/// // Add installer to collection.
/// Installers.Add(managementInstaller);
///
/// 'Instantiate installer for assembly.
/// Dim managementInstaller As New ManagementInstaller()
///
/// 'Add installer to collection.
/// Installers.Add(managementInstaller)
///
///
public class ManagementInstaller : Installer
{
//
private static bool helpPrinted = false;
///
/// Gets or sets installer options for this class.
///
///
/// The help text for all the installers in the installer collection, including
/// the description of what each installer does and the command-line options (for
/// the installation program) that can be passed to and understood by each
/// installer.
///
public override string HelpText {
get {
if (helpPrinted)
return base.HelpText;
else {
helpPrinted = true;
// return Res.GetString(Res.HelpText) + "\r\n" + base.HelpText;
//
StringBuilder help = new StringBuilder();
help.Append("/MOF=[filename]\r\n");
help.Append(" " + RC.GetString("FILETOWRITE_MOF")+"\r\n\r\n");
//
// [RAID: 123895]
// If the force parameter is present, we update registration information independent if it already
// exists.
//
help.Append ( "/Force or /F\r\n" ) ;
help.Append(" " + RC.GetString("FORCE_UPDATE"));
return help.ToString() + base.HelpText;
}
}
}
///
/// Installs the assembly.
///
/// The state of the assembly.
[ResourceExposure(ResourceScope.None),ResourceConsumption(ResourceScope.Machine,ResourceScope.Machine)]
public override void Install(IDictionary savedState)
{
// Demand IO permission required for LoadFrom FXCop 191096
FileIOPermission ioPermission = new FileIOPermission(FileIOPermissionAccess.Read, (string)Context.Parameters["assemblypath"]);
ioPermission.Demand();
base.Install(savedState);
//
Context.LogMessage(RC.GetString("WMISCHEMA_INSTALLATIONSTART"));
string assemblyPath = Context.Parameters["assemblypath"];
Assembly assembly = Assembly.LoadFrom(assemblyPath);
SchemaNaming naming = SchemaNaming.GetSchemaNaming(assembly);
//
// We always use the full version number for Whidbey.
//
naming.DecoupledProviderInstanceName = AssemblyNameUtility.UniqueToAssemblyFullVersion(assembly);
// See if this assembly provides instrumentation
if(null == naming)
return;
//
// [RAID: 123895]
// If the force parameter is present, we update registration information independent if it already
// exists.
//
if( ( naming.IsAssemblyRegistered() == false ) || ( Context.Parameters.ContainsKey ( "force" ) ) || ( Context.Parameters.ContainsKey ( "f" ) ) )
{
Context.LogMessage(RC.GetString("REGESTRING_ASSEMBLY") + " " + naming.DecoupledProviderInstanceName);
naming.RegisterNonAssemblySpecificSchema(Context);
naming.RegisterAssemblySpecificSchema();
}
mof = naming.Mof;
Context.LogMessage(RC.GetString("WMISCHEMA_INSTALLATIONEND"));
}
string mof;
///
/// Commits the assembly to the operation.
///
/// The state of the assembly.
[ResourceExposure(ResourceScope.None),ResourceConsumption(ResourceScope.Machine,ResourceScope.Machine)]
public override void Commit(IDictionary savedState) {
base.Commit(savedState);
// See if we were asked to generate a MOF file
if(Context.Parameters.ContainsKey("mof"))
{
string mofFile = Context.Parameters["mof"];
// bug#62252 - Pick a default MOF file name
if(mofFile == null || mofFile.Length == 0)
{
mofFile = Context.Parameters["assemblypath"];
if(mofFile == null || mofFile.Length == 0)
mofFile = "defaultmoffile";
else
mofFile = Path.GetFileName(mofFile);
}
// Append '.mof' in necessary
if(mofFile.Length<4)
mofFile += ".mof";
else
{
if(String.Compare(mofFile.Substring(mofFile.Length-4,4),".mof",StringComparison.OrdinalIgnoreCase)!=0)
mofFile += ".mof";
}
Context.LogMessage(RC.GetString("MOFFILE_GENERATING") + " " + mofFile);
using(StreamWriter log = new StreamWriter(mofFile, false, Encoding.Unicode))
{
log.WriteLine("//**************************************************************************");
log.WriteLine("//* {0}", mofFile);
log.WriteLine("//**************************************************************************");
log.WriteLine(mof);
}
}
}
///
/// Rolls back the state of the assembly.
///
/// The state of the assembly.
public override void Rollback(IDictionary savedState) {
base.Rollback(savedState);
}
///
/// Uninstalls the assembly.
///
/// The state of the assembly.
public override void Uninstall(IDictionary savedState) {
base.Uninstall(savedState);
}
}
///
/// Installs an instrumented assembly. This class is a default project installer for assemblies that contain
/// management instrumentation and do not use other installers (such as services, or message
/// queues). To use this default project installer, simply derive a class from
/// inside the assembly. No methods need
/// to be overridden.
///
///
/// If your project has a master project
/// installer, use the class instead.
///
///
/// Add the following code to your instrumented assembly to enable the installation step:
/// [System.ComponentModel.RunInstaller(true)]
/// public class MyInstaller : DefaultManagementProjectInstaller {}
///
/// <System.ComponentModel.RunInstaller(true)>
/// public class MyInstaller
/// Inherits DefaultManagementProjectInstaller
///
///
public class DefaultManagementProjectInstaller : Installer
{
///
/// Initializes a new instance of the
/// class. This is the default constructor.
///
public DefaultManagementProjectInstaller()
{
// Instantiate installer for assembly.
ManagementInstaller managementInstaller = new ManagementInstaller();
// Add installers to collection. Order is not important.
Installers.Add(managementInstaller);
}
}
}
// 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
- ApplicationSecurityManager.cs
- XmlAttributes.cs
- DNS.cs
- ObjectNotFoundException.cs
- ColorConverter.cs
- ClientRuntimeConfig.cs
- SelectionGlyphBase.cs
- DBNull.cs
- TextBox.cs
- ValidatorUtils.cs
- ToolStripDesignerAvailabilityAttribute.cs
- CustomBindingElement.cs
- DbTransaction.cs
- ListParagraph.cs
- filewebrequest.cs
- DrawListViewSubItemEventArgs.cs
- BackStopAuthenticationModule.cs
- Relationship.cs
- TraceProvider.cs
- UIElementParagraph.cs
- CroppedBitmap.cs
- FullTextLine.cs
- ToolStripHighContrastRenderer.cs
- RuleCache.cs
- LineServicesRun.cs
- Rotation3DKeyFrameCollection.cs
- mongolianshape.cs
- XmlNode.cs
- DefaultProxySection.cs
- BamlResourceSerializer.cs
- ZipIOLocalFileDataDescriptor.cs
- WebReferencesBuildProvider.cs
- MsmqIntegrationAppDomainProtocolHandler.cs
- GrammarBuilder.cs
- Processor.cs
- HandlerWithFactory.cs
- ReflectEventDescriptor.cs
- AsyncResult.cs
- IdentityHolder.cs
- SystemColors.cs
- DataKey.cs
- WebConfigurationManager.cs
- PreviewPrintController.cs
- WebPartConnectionsConfigureVerb.cs
- DesignerUtils.cs
- DecoderFallback.cs
- CollectionViewGroup.cs
- InvalidDataException.cs
- StaticDataManager.cs
- PropertySegmentSerializer.cs
- SqlPersonalizationProvider.cs
- WebPartConnectVerb.cs
- DataGridViewDataConnection.cs
- DefaultAsyncDataDispatcher.cs
- XsdCachingReader.cs
- ArithmeticLiteral.cs
- AlignmentXValidation.cs
- EntityDesignerUtils.cs
- _CacheStreams.cs
- HttpStreamFormatter.cs
- OdbcConnectionString.cs
- BitmapEffectInput.cs
- TdsRecordBufferSetter.cs
- FormViewDeletedEventArgs.cs
- DirectoryNotFoundException.cs
- IsolatedStorageFilePermission.cs
- LinkConverter.cs
- NTAccount.cs
- ParallelDesigner.cs
- VisualStyleRenderer.cs
- ServiceModelEnhancedConfigurationElementCollection.cs
- SecurityCriticalDataForSet.cs
- Lazy.cs
- XmlSchemaInfo.cs
- MultiBindingExpression.cs
- TabControl.cs
- ContainerFilterService.cs
- TableItemPatternIdentifiers.cs
- TemporaryBitmapFile.cs
- ComplexBindingPropertiesAttribute.cs
- XPathQilFactory.cs
- LineInfo.cs
- ObjectDataSourceDisposingEventArgs.cs
- SuppressIldasmAttribute.cs
- ListViewItem.cs
- xmlfixedPageInfo.cs
- LifetimeServices.cs
- XmlUnspecifiedAttribute.cs
- DataGridTemplateColumn.cs
- EntityCommandExecutionException.cs
- MissingSatelliteAssemblyException.cs
- RNGCryptoServiceProvider.cs
- LocalizationParserHooks.cs
- RuntimeCompatibilityAttribute.cs
- MediaElement.cs
- Certificate.cs
- X509Utils.cs
- cookieexception.cs
- FieldDescriptor.cs
- InstancePersistence.cs