/// <summary> /// Installs the MPB. /// </summary> /// <param name="path">The path.</param> public void InstallMpb(string path) { var mpStore = new ManagementPackFileStore(); mpStore.AddDirectory(Path.GetDirectoryName(path)); var reader = ManagementPackBundleFactory.CreateBundleReader(); var bundle = reader.Read(path, mpStore); var newMp = bundle.ManagementPacks.FirstOrDefault(); if (newMp == null) { HWLogger.Install.Warn($"Install faild. can not find ManagementPack in the path :{path}"); return; } var criteria = new ManagementPackCriteria($"Name = '{newMp.Name}'"); var oldMp = this.ManagementPacks.GetManagementPacks(criteria).FirstOrDefault(); if (oldMp != null) { HWLogger.Install.Warn($"Skip install:{oldMp.Name}-{oldMp.Version} has Installed."); } else { this.ManagementPacks.ImportBundle(bundle); HWLogger.Install.Warn($"Install {newMp.Name} Finish."); } }
//--------------------------------------------------------------------- internal static ManagementPackFileStore GetManagementPackStoreFromPath(string filePath) { ManagementPackFileStore store = new ManagementPackFileStore(); store.AddDirectory(System.IO.Path.GetDirectoryName(filePath)); //standard OpsMgr paths store.AddDirectory(@"%ProgramFiles%\System Center Operations Manager 2007"); store.AddDirectory(@"%ProgramFiles%\System Center 2012\Operations Manager\Console"); store.AddDirectory(@"%ProgramFiles%\System Center 2012\Operations Manager\Server"); //standard VSAC's paths store.AddDirectory(@"%ProgramFiles%\System Center 2012 Visual Studio Authoring Extensions\References\OM2007R2"); store.AddDirectory(@"%ProgramFiles(x86)%\System Center 2012 Visual Studio Authoring Extensions\References\OM2007R2"); store.AddDirectory(@"%ProgramFiles%\System Center 2012 Visual Studio Authoring Extensions\References\OM2012"); store.AddDirectory(@"%ProgramFiles(x86)%\System Center 2012 Visual Studio Authoring Extensions\References\OM2012"); store.AddDirectory(@"%ProgramFiles%\System Center 2012 Visual Studio Authoring Extensions\References\SM2012"); store.AddDirectory(@"%ProgramFiles(x86)%\System Center 2012 Visual Studio Authoring Extensions\References\SM2012"); return(store); }
//--------------------------------------------------------------------- internal static ManagementPackFileStore GetManagementPackStoreFromPath(string filePath) { ManagementPackFileStore store = new ManagementPackFileStore(); store.AddDirectory(System.IO.Path.GetDirectoryName(filePath)); //standard OpsMgr paths store.AddDirectory(@"%ProgramFiles%\System Center Operations Manager 2007"); store.AddDirectory(@"%ProgramFiles%\System Center 2012\Operations Manager\Console"); store.AddDirectory(@"%ProgramFiles%\System Center 2012\Operations Manager\Server"); //standard VSAC's paths store.AddDirectory(@"%ProgramFiles%\System Center 2012 Visual Studio Authoring Extensions\References\OM2007R2"); store.AddDirectory(@"%ProgramFiles(x86)%\System Center 2012 Visual Studio Authoring Extensions\References\OM2007R2"); store.AddDirectory(@"%ProgramFiles%\System Center 2012 Visual Studio Authoring Extensions\References\OM2012"); store.AddDirectory(@"%ProgramFiles(x86)%\System Center 2012 Visual Studio Authoring Extensions\References\OM2012"); store.AddDirectory(@"%ProgramFiles%\System Center 2012 Visual Studio Authoring Extensions\References\SM2012"); store.AddDirectory(@"%ProgramFiles(x86)%\System Center 2012 Visual Studio Authoring Extensions\References\SM2012"); return store; }
/// <summary> /// Creates the mp. /// </summary> private static void CreateESightConfigLibraryMp() { try { // var apmMpPath = @"E:\Projects\scom-plugin\SCOM\release\MPFiles\Temp"; OnLog("CreateESightConfigLibraryMp-ScomInstallPath:" + ScomInstallPath); var apmMpPath = $"{ScomInstallPath}\\Server\\ApmConnector"; OnLog(apmMpPath); var keyPath = $"{RunPath}\\..\\MPFiles\\Temp"; string outPath = $"{RunPath}\\..\\MPFiles"; string companyName = "广州摩赛网络技术有限公司"; string copyRight = "Copyright (c) 广州摩赛网络技术有限公司. All rights reserved."; string keyName = "esight.snk"; #region read eSight.View.Library var mpStore = new ManagementPackFileStore(); mpStore.AddDirectory(outPath); var reader = ManagementPackBundleFactory.CreateBundleReader(); var bundle = reader.Read($"{outPath}\\eSight.View.Library.mpb", mpStore); var eSightViewMp = bundle.ManagementPacks.FirstOrDefault(); if (eSightViewMp == null) { throw new Exception($"can not find mp : eSight.View.Library.mpb"); } #endregion var mMpStore = new ManagementPackFileStore(); mMpStore.AddDirectory(apmMpPath); mMpStore.AddDirectory(outPath); var mMp = new ManagementPack(ESightConfigLibraryName, ESightConfigLibraryName, eSightViewMp.Version, mMpStore); #region AddReferences var mLibraryMp = new ManagementPack($"{apmMpPath}\\System.Library.mp", mMpStore); var mWindowsLibraryMp = new ManagementPack($"{apmMpPath}\\Microsoft.SystemCenter.Library.mp", mMpStore); mMp.References.Add("System", new ManagementPackReference(mLibraryMp)); mMp.References.Add("SC", new ManagementPackReference(mWindowsLibraryMp)); mMp.References.Add("EVL", new ManagementPackReference(eSightViewMp)); #endregion #region AddView var view = new ManagementPackView(mMp, "ESight.Config.ESightConfigView", ManagementPackAccessibility.Public) { Target = mLibraryMp.GetClass("System.WebSite"), TypeID = mWindowsLibraryMp.GetViewType("Microsoft.SystemCenter.UrlViewType"), Description = "eSight Config View", DisplayName = "eSight Config View", Category = "Operations", Configuration = $"<Criteria><Url>https://localhost:{port}/StaticWeb/eSight.html</Url></Criteria><Presentation></Presentation><Target></Target>" }; var folderItem = new ManagementPackFolderItem("ESight.Config.ESightConfigView.FolderItem", view, eSightViewMp.GetFolder("ESight.Folder")); folderItem.Status = ManagementPackElementStatus.PendingAdd; #endregion mMp.AcceptChanges(); #region seal var mpWriterSettings = new ManagementPackAssemblyWriterSettings(companyName, Path.Combine(keyPath, keyName), false) { OutputDirectory = outPath, Copyright = copyRight }; ManagementPackAssemblyWriter mpWriter = new ManagementPackAssemblyWriter(mpWriterSettings); mpWriter.WriteManagementPack(mMp); #endregion // Remove Temp files if (Directory.Exists(keyPath)) { Directory.Delete(keyPath, true); } var tempFile = Path.Combine(RunPath, "..\\", "MPResources.resources"); if (File.Exists(tempFile)) { File.Delete(tempFile); } } catch (Exception ex) { OnLog($"create {ESightConfigLibraryName} faild", ex); throw; } }