private static void Initialize(Assembly assembly)
 {
     lock (Instrumentation.instrumentedAssemblies)
     {
         if (!Instrumentation.instrumentedAssemblies.ContainsKey(assembly))
         {
             SchemaNaming schemaNaming = SchemaNaming.GetSchemaNaming(assembly);
             if (schemaNaming != null)
             {
                 if (!schemaNaming.IsAssemblyRegistered())
                 {
                     if (WMICapabilities.IsUserAdmin())
                     {
                         schemaNaming.DecoupledProviderInstanceName = AssemblyNameUtility.UniqueToAssemblyFullVersion(assembly);
                         schemaNaming.RegisterNonAssemblySpecificSchema(null);
                         schemaNaming.RegisterAssemblySpecificSchema();
                     }
                     else
                     {
                         throw new Exception(RC.GetString("ASSEMBLY_NOT_REGISTERED"));
                     }
                 }
                 InstrumentedAssembly instrumentedAssembly = new InstrumentedAssembly(assembly, schemaNaming);
                 Instrumentation.instrumentedAssemblies.Add(assembly, instrumentedAssembly);
             }
         }
     }
 }
        public override void Install(IDictionary savedState)
        {
            FileIOPermission fileIOPermission = new FileIOPermission(FileIOPermissionAccess.Read, base.Context.Parameters["assemblypath"]);

            fileIOPermission.Demand();
            base.Install(savedState);
            base.Context.LogMessage(RC.GetString("WMISCHEMA_INSTALLATIONSTART"));
            string       item         = base.Context.Parameters["assemblypath"];
            Assembly     assembly     = Assembly.LoadFrom(item);
            SchemaNaming schemaNaming = SchemaNaming.GetSchemaNaming(assembly);

            schemaNaming.DecoupledProviderInstanceName = AssemblyNameUtility.UniqueToAssemblyFullVersion(assembly);
            if (schemaNaming != null)
            {
                if (!schemaNaming.IsAssemblyRegistered() || base.Context.Parameters.ContainsKey("force") || base.Context.Parameters.ContainsKey("f"))
                {
                    base.Context.LogMessage(string.Concat(RC.GetString("REGESTRING_ASSEMBLY"), " ", schemaNaming.DecoupledProviderInstanceName));
                    schemaNaming.RegisterNonAssemblySpecificSchema(base.Context);
                    schemaNaming.RegisterAssemblySpecificSchema();
                }
                this.mof = schemaNaming.Mof;
                base.Context.LogMessage(RC.GetString("WMISCHEMA_INSTALLATIONEND"));
                return;
            }
            else
            {
                return;
            }
        }
 public AssemblySpecificNaming(string namespaceName, string securityDescriptor, Assembly assembly)
 {
     this.namespaceName                 = namespaceName;
     this.securityDescriptor            = securityDescriptor;
     this.decoupledProviderInstanceName = AssemblyNameUtility.UniqueToAssemblyMinorVersion(assembly);
     this.assemblyUniqueIdentifier      = AssemblyNameUtility.UniqueToAssemblyBuild(assembly);
     this.assemblyName = assembly.GetName().FullName;
     this.assemblyPath = assembly.Location;
 }
 private SchemaNaming(string namespaceName, string securityDescriptor, Assembly assembly)
 {
     this.assembly     = assembly;
     this.assemblyInfo = new AssemblySpecificNaming(namespaceName, securityDescriptor, assembly);
     if (!DoesInstanceExist(this.RegistrationPath))
     {
         this.assemblyInfo.DecoupledProviderInstanceName = AssemblyNameUtility.UniqueToAssemblyMinorVersion(assembly);
     }
 }
        public static string UniqueToAssemblyMinorVersion(Assembly assembly)
        {
            AssemblyName name = assembly.GetName(true);

            object[] str = new object[7];
            str[0] = name.Name;
            str[1] = "_SN_";
            str[2] = AssemblyNameUtility.BinToString(name.GetPublicKeyToken());
            str[3] = "_Version_";
            str[4] = name.Version.Major;
            str[5] = ".";
            str[6] = name.Version.Minor;
            return(string.Concat(str));
        }
        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"));
        }
Exemple #7
0
        private static void Initialize(Assembly assembly)
        {
            lock (instrumentedAssemblies)
            {
                if (instrumentedAssemblies.ContainsKey(assembly))
                {
                    return;
                }

                SchemaNaming naming = SchemaNaming.GetSchemaNaming(assembly);
                if (naming == null)
                {
                    return;
                }

                if (false == naming.IsAssemblyRegistered())
                {
                    // If we are not an administrator, don't try to JIT install the schema
                    if (!WMICapabilities.IsUserAdmin())
                    {
                        throw new Exception(RC.GetString("ASSEMBLY_NOT_REGISTERED"));
                    }

                    //
                    // We always use the full version number for Whidbey.
                    //
                    naming.DecoupledProviderInstanceName = AssemblyNameUtility.UniqueToAssemblyFullVersion(assembly);

                    naming.RegisterNonAssemblySpecificSchema(null);
                    naming.RegisterAssemblySpecificSchema();
                }

                InstrumentedAssembly instrumentedAssembly = new InstrumentedAssembly(assembly, naming);
                instrumentedAssemblies.Add(assembly, instrumentedAssembly);
            }
        }
        public static string UniqueToAssemblyBuild(Assembly assembly)
        {
            Guid mvid = MetaDataInfo.GetMvid(assembly);

            return(string.Concat(AssemblyNameUtility.UniqueToAssemblyVersion(assembly), "_Mvid_", mvid.ToString().ToLower(CultureInfo.InvariantCulture)));
        }