/// <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.");
            }
        }
Exemplo n.º 2
0
        private static ManagementPack LoadManagementPack(string[] args)
        {
            ManagementPackBundle bundle;

            ManagementPackFileStore store = Utilities.GetManagementPackStoreFromPath(args[0]);

            ManagementPack mp;

            if (System.IO.Path.GetExtension(args[0]).Equals(".mpb"))
            {
                ManagementPackBundleReader reader = ManagementPackBundleFactory.CreateBundleReader();
                bundle = reader.Read(args[0], store);

                // 1 at the time is ok
                if (bundle.ManagementPacks.Count == 1)
                {
                    mp = bundle.ManagementPacks[0];
                    return(mp);
                }
                else
                {
                    // too many MPs contained in this MPB! - can onlhy open one at the time!
                    // do something sensible here
                    throw new ApplicationException("This MPB contains multiple MPs. " +
                                                   "In an upcoming version a dialog will open, asking you to choose which one you want to see. " +
                                                   "For now, we just are going to crash.");
                }
            }
            else // we are dealing with an MP or XML - the old stuff works as it did for 2007
            {
                mp = new ManagementPack(args[0], store);
                return(mp);
            }
        }
Exemplo n.º 3
0
        //---------------------------------------------------------------------
        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);
        }
Exemplo n.º 4
0
        //---------------------------------------------------------------------
        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;
            }
        }
Exemplo n.º 6
0
        //---------------------------------------------------------------------
        private void loadManagementPackToolStripMenuItem_Click(object sender, EventArgs e)
        {
            m_openFileDialog = new OpenFileDialog();

            m_openFileDialog.AddExtension    = true;
            m_openFileDialog.CheckPathExists = true;
            m_openFileDialog.DefaultExt      = "mp";
            m_openFileDialog.Filter          = "Sealed MP files (*.mp)|*.mp|Sealed MP bundles (*.mpb)|*.mpb|Unsealed MP files (*.xml)|*.xml";

            m_openFileDialog.InitialDirectory = (string)Application.UserAppDataRegistry.GetValue("MPFolder", (object)"C:\\");

            if (m_openFileDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            Cursor = Cursors.WaitCursor;

            ManagementPackFileStore store = Utilities.GetManagementPackStoreFromPath(m_openFileDialog.FileName);


            if (System.IO.Path.GetExtension(m_openFileDialog.FileName).Equals(".mpb", StringComparison.InvariantCultureIgnoreCase))
            {
                ManagementPackBundleReader reader = ManagementPackBundleFactory.CreateBundleReader();
                m_bundle = reader.Read(m_openFileDialog.FileName, store);

                // 1 at the time is ok
                if (m_bundle.ManagementPacks.Count == 1)
                {
                    m_managementPack = m_bundle.ManagementPacks[0];
                }
                else
                {
                    // multiple MPs contained in this MPB! - can only open one at the time! Need to ask the user which one.
                    MultipleMPSelectionForm MPListForm = new MultipleMPSelectionForm(m_bundle.ManagementPacks);
                    MPListForm.ShowDialog();

                    //selected in the form
                    m_managementPack = MPListForm.ChosenMP;
                }
            }
            else // we are dealing with an MP or XML - the old stuff works as it did for 2007
            {
                m_managementPack = new ManagementPack(m_openFileDialog.FileName, store);
            }


            ClearViews();

            PopulateObjectTypeTree();


            Application.UserAppDataRegistry.SetValue("MPFolder",
                                                     Path.GetDirectoryName(m_openFileDialog.FileName));

            if (m_managementPack.KeyToken != null)
            {
                Text = string.Format("Management Pack Viewer 2012 - {0} {1} {2}",
                                     Utilities.GetBestManagementPackName(m_managementPack),
                                     m_managementPack.Version.ToString(),
                                     m_managementPack.KeyToken.ToString());
            }
            else
            {
                //TODO - Unsealed don't have keytoken!
                Text = string.Format("Management Pack Viewer 2012 - {0} {1} Unsealed",
                                     Utilities.GetBestManagementPackName(m_managementPack),
                                     m_managementPack.Version.ToString());
            }


            //loading dataset is memory expensive and can take time... so moved to a worker thread
            this.m_progressDialog = new ProgressDialog();
            this.m_progressDialog.Show(this);
            this.backgroundWorker.RunWorkerAsync();



            Cursor = Cursors.Default;

            // now that an MP is loaded, enable the menus
            saveToHTMLToolStripMenuItem.Enabled  = true;
            saveToExcelToolStripMenuItem.Enabled = true;

            //this might make sense or not, if we have loaded XML...
            if (System.IO.Path.GetExtension(m_openFileDialog.FileName).Equals(".mpb", StringComparison.InvariantCultureIgnoreCase) ||
                System.IO.Path.GetExtension(m_openFileDialog.FileName).Equals(".mp", StringComparison.InvariantCultureIgnoreCase))
            {
                unsealManagementPackToolStripMenuItem.Enabled = true;
            }
        }