Example #1
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);
            }
        }
Example #2
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;
            }
        }