/// <summary> /// Add child nodes during expansion /// </summary> private void Expand() { int foundChildren = 10; // report progress expandStatus.ReportProgress(0, foundChildren, "Loading Sample children..."); // find results for (int child = 1; child < foundChildren; child++) { // The Thread.Sleep statement below is for demo purposes only. When doing your // development you should not block your snap-in thread to service an // async request like OnExpand unless you only use the scope tree and // list view and never show any WinForms views or WinForms property pages. // The reason is that your WinForms views and property pages will be blocked, // and in certain cases that can also block MMC. // sleep for a second Thread.Sleep(1000); // New scope nodes must be created on the snapin's thread DelegateWithNode delegateWithNode = new DelegateWithNode(AddChildNode); this.SnapIn.BeginInvoke(delegateWithNode, new object[] {this}); // update the progress expandStatus.ReportProgress(child, foundChildren, "Loading Sample children..."); } // update progress expandStatus.Complete("Loading Sample complete.", true); }
/// <summary> /// Node plus sign clicked to expand the node. Load in children. /// </summary> /// <param name="status">asynchronous status for updating the console</param> protected override void OnExpand(AsyncStatus status) { int foundChildren = 10; // report progress status.ReportProgress(0, foundChildren, "Loading Sample children..."); // find results for (int child = 1; child < foundChildren; child++) { // The Thread.Sleep statement below is for demo purposes only. When doing your // development you should not block your snap-in thread to service an // async request like OnExpand unless you only use the scope tree and // list view and never show any WinForms views or WinForms property pages. // The reason is that your WinForms views and property pages will be blocked, // and in certain cases that can also block MMC. // Sleep for a second. Thread.Sleep(1000); // add the child ScopeNode childNode = new StatusNode(); childNode.DisplayName = "Added " + System.DateTime.Now.ToLongTimeString(); this.Children.Add(childNode); // update the progress status.ReportProgress(child, foundChildren, "Loading Sample children..."); } // update progress status.Complete("Loading Sample complete.", true); }
/// <summary> /// Load in any saved data /// </summary> /// <param name="status">asynchronous status for updating the console</param> /// <param name="persistenceData">binary data stored in the console file</param> protected override void OnLoadCustomData(AsyncStatus status, byte[] persistenceData) { status.ReportProgress(0, 10, "Loading.."); // Deserialize the object try { MemoryStream stream = new MemoryStream(persistenceData); BinaryFormatter deserializer = new BinaryFormatter(); mgrConfig.SetInitData((InitialisationData)deserializer.Deserialize(stream)); // Initialise the config object mgrConfig.Initialise(); // Load the CA data into the root node ((OSCAroot)RootNode).Load(); status.Complete("Manager configuration: " + mgrConfig.InitData.configFile, true); } catch (SerializationException) { MessageBox.Show("No configuration data defined", "OSCA", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void OnCompleted() { _status.Complete("Load complete.", true); }
/// <summary> /// Handle node actions /// </summary> /// <param name="action">action that was triggered</param> /// <param name="status">asynchronous status for updating the console</param> protected override void OnAction(Microsoft.ManagementConsole.Action action, AsyncStatus status) { switch ((string)action.Tag) { case "CreateIntCA": CreateCA newCA = new CreateCA() { mgrConfig = mgrConfig }; if (newCA.ShowDialog() == DialogResult.OK) { CA ca = mgrConfig.CaList.Last <CA>(); status.Complete("CA Created", true); MessageBox.Show("CA Created: " + ca.CaName, "Create CA", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Children.Add(new CANode(ca) { DisplayName = ca.CaName }); } else { status.Complete("Creation aborted", false); } break; case "CreateExtCA": break; case "AddCA": AddCA addCA = new AddCA(); if (addCA.ShowDialog() == DialogResult.OK) { CA ca = mgrConfig.CaList.Last <CA>(); status.Complete("CA Added", true); MessageBox.Show("CA Added: " + ca.CaName, "Add CA", MessageBoxButtons.OK, MessageBoxIcon.Information); this.Children.Add(new CANode(ca) { DisplayName = ca.CaName }); } else { status.Complete("Creation aborted", false); } break; case "AdminMode": AdminPassword pwd = new AdminPassword(); if (pwd.ShowDialog() == DialogResult.OK) { mgrConfig.SwitchMode(Mode.AdminMode); refreshActions(); } break; case "AdminPassword": ChangeAdminPassword newpwd = new ChangeAdminPassword(); if (newpwd.ShowDialog() == DialogResult.OK) { MessageBox.Show("Password changed", "Change Admin Password", MessageBoxButtons.OK, MessageBoxIcon.Information); } break; case "UserMode": mgrConfig.SwitchMode(Mode.UserMode); refreshActions(); break; } }