/// <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;
            }
        }
Ejemplo n.º 2
0
        protected override void ProcessRecord()
        {
            try
            {
                base.ProcessRecord();

                ManagementPackView view = new ManagementPackView(ManagementPack, SMHelpers.MakeMPElementSafeUniqueIdentifier("View"), ManagementPackAccessibility.Internal);
                view.DisplayName = _DisplayName;     //Set the display name according to what the user specified
                view.Target      = _Class;           //Set the class according to what the user specified

                //TODO: Parameterize these later
                view.Visible       = true;
                view.Accessibility = ManagementPackAccessibility.Public;
                view.Enabled       = true;
                view.Category      = "NotUsed";

                //Set the parent folder that was passed in
                ManagementPackFolderItem folderitem = new ManagementPackFolderItem(view, _Folder);

                //Add the management pack references to the MP
                if (_ManagementPackReferences != null)
                {
                    foreach (KeyValuePair <string, ManagementPackReference> kvp in _ManagementPackReferences)
                    {
                        _ManagementPack.References.Add(kvp);
                    }
                }

                //Get the Grid view type and set it for the view
                ManagementPack mpConsole = SMHelpers.GetManagementPack(ManagementPacks.Microsoft_EnterpriseManagement_ServiceManager_UI_Console, _mg);
                view.TypeID = mpConsole.GetViewType("GridViewType");

                #region DataAdapters

                DataAdapter daEMO          = new DataAdapter();
                DataAdapter daAdvancedList = new DataAdapter();

                if (_Projection != null)
                {
                    daEMO.Name = "dataportal:EnterpriseManagementObjectAdapter";
                    daEMO.Type = "Microsoft.EnterpriseManagement.UI.SdkDataAccess.DataAdapters.EnterpriseManagementObjectProjectionAdapter";
                }
                else
                {
                    daEMO.Name = "dataportal:EnterpriseManagementObjectProjectionAdapter";
                    daEMO.Type = "Microsoft.EnterpriseManagement.UI.SdkDataAccess.DataAdapters.EnterpriseManagementObjectAdapter";
                }

                daEMO.Assembly = "Microsoft.EnterpriseManagement.UI.SdkDataAccess";

                daAdvancedList.Name     = "viewframework://Adapters/AdvancedList";
                daAdvancedList.Assembly = "Microsoft.EnterpriseManagement.UI.ViewFramework";
                daAdvancedList.Type     = "Microsoft.EnterpriseManagement.UI.ViewFramework.AdvancedListSupportAdapter";

                Collection <DataAdapter> collDataAdpaters = new Collection <DataAdapter>();
                collDataAdpaters.Add(daEMO);
                collDataAdpaters.Add(daAdvancedList);

                #endregion DataAdapters

                view.Configuration = CreateViewConfiguration(collDataAdpaters, _columns);

                foreach (Column column in _columns)
                {
                    ManagementPackStringResource mpsr = new ManagementPackStringResource(view.GetManagementPack(), column.DisplayNameId);
                    mpsr.DisplayName = column.DisplayNameString;
                }

                //Set the image
                if (_image != null)
                {
                    ManagementPackElementReference <ManagementPackImage> viewIconReference = (ManagementPackElementReference <ManagementPackImage>)_mg.Resources.GetResource <ManagementPackImage>(_image.Name, _image.GetManagementPack());
                    ManagementPackImageReference imageref = new ManagementPackImageReference(view, viewIconReference, view.GetManagementPack());
                }

                view.GetManagementPack().AcceptChanges();

                if (PassThru)
                {
                    //Pass the new object to the pipeline
                    WriteObject(view);
                }
            }
            catch (Exception ex)
            {
                WriteError(new ErrorRecord(ex, "NewView", ErrorCategory.InvalidOperation, DisplayName));
            }
        }