public void Start(ScopeNode owner) { if (owner == null) { throw new ArgumentNullException("owner"); } if (this._owner != null) { throw new InvalidOperationException(Microsoft.ManagementConsole.Internal.Utility.Resources.GetString(Microsoft.ManagementConsole.Internal.Strings.MicrosoftManagementConsoleCustomStatusRequestAlreadyStarted, CultureInfo.CurrentUICulture)); } NamespaceSnapInBase snapInInstance = SnapInBase.SnapInInstance as NamespaceSnapInBase; if ((snapInInstance == null) || (owner.SnapIn != snapInInstance)) { throw new InvalidOperationException(Microsoft.ManagementConsole.Internal.Utility.LoadResourceString(Microsoft.ManagementConsole.Internal.Strings.PropertySheetWrongThread)); } this._owner = owner; this._owner.AddCustomStatus(this); try { this.AttachRequestStatus(); } catch { this.InternalComplete(string.Empty, false); throw; } }
private void Notify(int index, ScopeNode[] items, ScopeNodeCollectionChangeType action) { if (this.ItemsChanged != null) { this.ItemsChanged(this, new ScopeNodeCollectionEventArgs(index, items, action)); } }
internal IMessageClient CreateView(ScopeNode scopeNode, int componentId, int viewInstanceId) { if (scopeNode == null) { throw new ArgumentNullException("scopeNode"); } View view = (View) Activator.CreateInstance(this._viewType); view.Initialize(scopeNode, componentId, viewInstanceId, this); return view.MessageClient; }
internal IMessageClient CreateView(int id, ScopeNode node, int componentId, int viewInstanceId) { ViewDescription viewDescriptionById = this.GetViewDescriptionById(id); if (viewDescriptionById == null) { TraceSources.ExecutiveSource.TraceEvent(TraceEventType.Information, 12, "ViewDescription id:{0} not found. Cannot create view.", new object[] { id }); return null; } return viewDescriptionById.CreateView(node, componentId, viewInstanceId); }
private void AddTreeToDeletionList(List<ScopeNode> nodeList, ScopeNode[] nodes) { foreach (ScopeNode node in nodes) { nodeList.Add(node); if (node.Children.Count > 0) { this.AddTreeToDeletionList(nodeList, node.Children.ToArray()); } } }
private void RemoveItemAuthorizationScopeNode(MMC.ScopeNode itemAuthorizationsScopeNode, ItemDefinitionScopeNode itemDefinitionToRemove) { foreach (ItemAuthorizationScopeNode itemAuthorizationScopeNode in itemAuthorizationsScopeNode.Children) { if (itemAuthorizationScopeNode.Item.Name == itemDefinitionToRemove.Item.Name) { itemAuthorizationsScopeNode.Children.Remove(itemAuthorizationScopeNode); break; } } }
protected override void OnItemsRemoved(int index, object[] items) { foreach (ScopeNode node in items) { node.Changed -= new Node.NodeChangedEventHandler(this.ItemChanged); node.SetParent(null); } ScopeNode[] destinationArray = new ScopeNode[items.Length]; Array.Copy(items, destinationArray, items.Length); this.Notify(index, destinationArray, ScopeNodeCollectionChangeType.Remove); }
internal override void InternalComplete(string completionText, bool success) { if (base.RequestStatus != null) { base.InternalComplete(completionText, success); } if (this._owner != null) { this._owner.RemoveCustomStatus(this); this.DetachRequestStatus(); this._owner = null; } }
protected override void OnInitialize() { this.RootNode = new ScopeNode(); this.RootNode.DisplayName = "SiteView.ECC"; ScopeNode node = new ScopeNode(); node.DisplayName = "Users"; this.RootNode.Children.Add(node); node = new ScopeNode(); node.DisplayName = "Files"; this.RootNode.Children.Add(node); }
void deleteItemDefinitionsAction_Triggered(object sender, MMC.SyncActionEventArgs e) { MessageBoxParameters mbp = new MessageBoxParameters(); mbp.Buttons = MessageBoxButtons.YesNo; mbp.Caption = e.Action.DisplayName; mbp.DefaultButton = MessageBoxDefaultButton.Button2; mbp.Icon = MessageBoxIcon.Question; mbp.Text = Globalization.MultilanguageResource.GetString("ItemDefinitionsListView_Msg10"); DialogResult dr = this.SnapIn.Console.ShowDialog(mbp); if (dr == DialogResult.Yes) { try { foreach (ItemDefinitionScopeNode itemDefinitionScopeNode in this.SelectedNodes) { itemDefinitionScopeNode.Item.Delete(); //Remove relative child in Item Authorizations MMC.ScopeNode itemDefinitionsScopeNode = itemDefinitionScopeNode.Parent; while (itemDefinitionsScopeNode as ItemDefinitionsScopeNode == null) { itemDefinitionsScopeNode = itemDefinitionsScopeNode.Parent; //go up one level } ItemAuthorizationsScopeNode itemAuthorizationsScopeNode = (ItemAuthorizationsScopeNode)itemDefinitionsScopeNode.Parent.Children[2]; foreach (MMC.ScopeNode itemAuthorizationsScopeNodeChild in itemAuthorizationsScopeNode.Children) { bool founded = false; foreach (ItemAuthorizationScopeNode itemAuthorizationScopeNode in itemAuthorizationsScopeNodeChild.Children) { if (itemDefinitionScopeNode.Item.Name == itemAuthorizationScopeNode.Item.Name) { itemAuthorizationScopeNode.Parent.Children.Remove(itemAuthorizationScopeNode); founded = true; break; } } if (founded) { break; } } this.ScopeNode.Children.Remove(itemDefinitionScopeNode); } } catch (Exception ex) { this.ShowError(ex.Message, Globalization.MultilanguageResource.GetString("ItemDefinitionsListView_Tit20")); } } }
internal void AddNodes(ScopeNode[] items, int index) { if (!this._initialized) { throw new Exception(Microsoft.ManagementConsole.Internal.Utility.LoadResourceString(Microsoft.ManagementConsole.Internal.Strings.NodeSyncManagerNotInitialized)); } if (items.Length != 0) { int capacity = this.CountNodesForInsertion(items); InsertScopeNodesCommandWriter writer = new InsertScopeNodesCommandWriter(capacity); ScopeNode[] nodeList = new ScopeNode[capacity]; int currentNodesIndex = 0; try { this.AddTreeToInsertionList(writer, nodeList, ref currentNodesIndex, index, items); foreach (ScopeNode node in nodeList) { ViewDescriptionCollection viewDescriptionsInternal = node.ViewDescriptionsInternal; if (viewDescriptionsInternal != null) { viewDescriptionsInternal.Initialize(); } } this._snapInPlatform.ProcessCommand(writer.Flush()); } catch { TraceSources.ExecutiveSource.TraceEvent(TraceEventType.Warning, 12, "NodeSyncManager.AddNodes() failed"); throw; } finally { writer.Dispose(); } foreach (ScopeNode node2 in nodeList) { node2.Children.ItemsChanged += new ScopeNodeCollection.ScopeNodeCollectionEventHandler(this.OnNodesChanged); node2.Changed += new Node.NodeChangedEventHandler(this.OnNodeChanged); node2.SharedDataChanged += new ScopeNode.SharedDataChangedEventHandler(this.OnNodeSharedDataChanged); this._nodes.Add(node2.Id, node2); node2.OnNodeSyncManagerAdd(); } } }
void newOperationDefinitionAction_Triggered(object sender, MMC.SyncActionEventArgs e) { MMC.ScopeNode itemNode = (MMC.ScopeNode)sender; frmItemProperties frm = new frmItemProperties(); frm.application = this.application; frm.item = null; frm.itemType = ItemType.Operation; DialogResult dr = this.SnapIn.Console.ShowDialog(frm); if (dr == DialogResult.OK) { this.Children.Add(new ItemDefinitionScopeNode(frm.item)); //Add relative child in Item Authorizations if opened try { if ( this.Parent != null && this.Parent.Parent != null && this.Parent.Parent.Children.Count >= 3 && this.Parent.Parent.Children[2].Children.Count >= 3 ) { MMC.ScopeNode itemDefinitionsScopeNode = this.Parent; OperationAuthorizationsScopeNode itemAuthorizationsScopeNode = (itemDefinitionsScopeNode.Parent.Children[2].Children[2]) as OperationAuthorizationsScopeNode; if (itemAuthorizationsScopeNode != null) { itemAuthorizationsScopeNode.Children.Add(new ItemAuthorizationScopeNode(frm.item)); } } } catch { } /*System.Windows.Forms.Application.DoEvents();*/ } }
private void AddTreeToInsertionList(InsertScopeNodesCommandWriter writer, ScopeNode[] nodeList, ref int currentNodesIndex, int index, ScopeNode[] nodes) { foreach (ScopeNode node in nodes) { if (this._nodes.ContainsKey(node.Id)) { throw new Exception(Microsoft.ManagementConsole.Internal.Utility.LoadResourceString(Microsoft.ManagementConsole.Internal.Strings.NodeSyncManagerAddTreeToInsertionListNodeExistInOneLocation)); } if (node == null) { throw new Exception(Microsoft.ManagementConsole.Internal.Utility.LoadResourceString(Microsoft.ManagementConsole.Internal.Strings.NodeSyncManagerInvalidNodeType)); } ScopeNodeInsert insert = new ScopeNodeInsert(); insert.NodeData = (ScopeNodeData) node.Data; ActionsPaneRootData data = new ActionsPaneRootData(); data.Write(node.ActionsPaneItems.Data); insert.Actions = data; data = new ActionsPaneRootData(); data.Write(node.ActionsPaneHelpItems.Data); insert.HelpActions = data; insert.InitialSharedData.SetAddedFormats(this.GenerateSharedDataFormatConfiguration(node)); insert.InitialSharedData.SetUpdatedData(this.GenerateClipboardData(node)); if (node.Parent != null) { insert.ParentScopeNodeId = node.Parent.Id; } insert.InsertionIndex = index; writer.WriteScopeNodeInsert(insert); nodeList[currentNodesIndex++] = node; index++; if (node.Children.Count > 0) { this.AddTreeToInsertionList(writer, nodeList, ref currentNodesIndex, 0, node.Children.ToArray()); } } }
private int CountNodesForInsertion(ScopeNode[] nodes) { int length = nodes.Length; Stack<ScopeNode> stack = new Stack<ScopeNode>(); for (int i = 0; i < nodes.Length; i++) { ScopeNode item = nodes[i]; if (item.Children.Count > 0) { stack.Push(item); } } while (stack.Count > 0) { ScopeNode node2 = stack.Pop(); length += node2.Children.Count; foreach (ScopeNode node3 in node2.Children) { if (node3.Children.Count > 0) { stack.Push(node3); } } } return length; }
void itemDefinitionPropertiesAction_Triggered(object sender, MMC.SyncActionEventArgs e) { frmItemProperties frm = new frmItemProperties(); frm.Text += " - " + this.item.Name; frm.application = this.item.Application; frm.item = this.item; frm.itemType = this.item.ItemType; string oldItemName = this.item.Name; DialogResult dr = this.SnapIn.Console.ShowDialog(frm); /*Application.DoEvents();*/ frm.Dispose(); /*Application.DoEvents();*/ if (dr == DialogResult.OK) { this.Render(); try { try { this.NotifyChanged(); /*Application.DoEvents();*/ } catch { } //Update relative child in Item Authorizations ItemDefinitionsScopeNode itemDefinitionsScopeNode = (ItemDefinitionsScopeNode)this.Parent.Parent; MMC.ScopeNode itemAuthorizationsScopeNode = itemDefinitionsScopeNode.Parent.Children[2]; switch (this.item.ItemType) { case ItemType.Role: if (itemAuthorizationsScopeNode != null && itemAuthorizationsScopeNode.Children.Count >= 1) { itemAuthorizationsScopeNode = itemAuthorizationsScopeNode.Children[0]; } else { return; } break; case ItemType.Task: if (itemAuthorizationsScopeNode != null && itemAuthorizationsScopeNode.Children.Count >= 2) { itemAuthorizationsScopeNode = itemAuthorizationsScopeNode.Children[1]; } else { return; } break; case ItemType.Operation: if (itemAuthorizationsScopeNode != null && itemAuthorizationsScopeNode.Children.Count >= 3) { itemAuthorizationsScopeNode = itemAuthorizationsScopeNode.Children[2]; } else { return; } break; } foreach (ItemAuthorizationScopeNode itemAuthorizationScopeNode in itemAuthorizationsScopeNode.Children) { if (oldItemName == itemAuthorizationScopeNode.Item.Name) { itemAuthorizationScopeNode.Item = this.item; itemAuthorizationScopeNode.RenderItemAuthorizationScopeNode(); break; } } } catch { } /*Application.DoEvents();*/ } }
private void LoadCompanies() { foreach (ICompanyInfo companyInfo in GetCompanyElements()) { CompanyScopeNode companyScopeNode = new CompanyScopeNode(companyInfo); this.Children.Add(companyScopeNode); // Domain Alias #if DEBUG ScopeNode domainAliasesScopeNode = new ScopeNode(); companyScopeNode.Children.Add(domainAliasesScopeNode); DataElement domainAliases = new DataElement(DataElementType.DomainAliases, string.Empty, SnapInResources.ScopeNodeDispayName_DomainAliases); domainAliasesScopeNode.DisplayName = domainAliases.DisplayName; domainAliasesScopeNode.Tag = domainAliases; domainAliasesScopeNode.ImageIndex = 5; domainAliasesScopeNode.SelectedImageIndex = 5; #endif } }
/// <summary>Initializes the nodes and the views attached to each node in the SnapIn tree.</summary> private void InitializeNodes() { // Primary Node for the SnapIn. Create it, and then add it to the Parent Node which belongs // to Computer Management _snapInNode = new ScopeNode { DisplayName = "WMI Demo Snap-In", ImageIndex = SnapInShared.WmiDemoImage, SelectedImageIndex = SnapInShared.WmiDemoImage }; PrimaryNode.Children.Add(_snapInNode); // Node which contains a report view of all the tasks that are in the system ScopeNode taskListNode = new ScopeNode { DisplayName = "Tasks", ImageIndex = SnapInShared.TaskImage, SelectedImageIndex = SnapInShared.TaskImage }; _snapInNode.Children.Add(taskListNode); // View Description for the Task List MmcListViewDescription scheduledLvd = new MmcListViewDescription { DisplayName = "Scheduled Task List", ViewType = typeof(Views.TaskListView), Options = MmcListViewOptions.ExcludeScopeNodes }; taskListNode.ViewDescriptions.Add(scheduledLvd); taskListNode.ViewDescriptions.DefaultIndex = 0; // Node for the Web site Link ScopeNode htmlNode = new ScopeNode { DisplayName = "Web Site", ImageIndex = SnapInShared.WebsiteImage, SelectedImageIndex = SnapInShared.WebsiteImage }; _snapInNode.Children.Add(htmlNode); HtmlViewDescription htmlDesc = new HtmlViewDescription { DisplayName = "The Coding Monkey", Url = new Uri("http://www.thecodingmonkey.net") }; // attach the view and set it as the default to show htmlNode.ViewDescriptions.Add(htmlDesc); htmlNode.ViewDescriptions.DefaultIndex = 0; // Node for the "Performance" Pane ScopeNode perfNode = new ScopeNode { DisplayName = "Performance", ImageIndex = SnapInShared.Performance, SelectedImageIndex = SnapInShared.Performance }; _snapInNode.Children.Add(perfNode); FormViewDescription perfFvd = new FormViewDescription { DisplayName = "Performance", ViewType = typeof(Views.PerformanceCounterFormView), ControlType = typeof(Views.PerformanceCounterViewControl) }; perfNode.ViewDescriptions.Add(perfFvd); perfNode.ViewDescriptions.DefaultIndex = 0; }
/// <summary> /// Loads the server child scope nodes. /// </summary> /// <param name="serverConfigurator">The server configurator.</param> /// <param name="serverScopeNode">The server scope node.</param> private void LoadServerChildScopeNodes(ScopeNode serverScopeNode) { // Companies CompaniesScopeNode companiesScopeNode = new CompaniesScopeNode(this.Configurator); serverScopeNode.Children.Add(companiesScopeNode); // License LicenseScopeNode licenseScopeNode = new LicenseScopeNode(this.Configurator); serverScopeNode.Children.Add(licenseScopeNode); // Updates UpgradesScopeNode upgradesScopeNode = new UpgradesScopeNode(this.Configurator); serverScopeNode.Children.Add(upgradesScopeNode); foreach (int version in GetUpgradeElements(this.Configurator)) { UpgradeScopeNode upgradeScopeNode = new UpgradeScopeNode(this.Configurator, version); upgradesScopeNode.Children.Add(upgradeScopeNode); } // Properties ServerPropertiesScopeNode serverPropertiesScopeNode = new ServerPropertiesScopeNode(this.Configurator); serverScopeNode.Children.Add(serverPropertiesScopeNode); }
public void CopyTo(ScopeNode[] array, int index) { this.CopyTo(array, index); }
internal void SetParent(ScopeNode parent) { this._parent = parent; }
/// <summary> /// Use shared data /// </summary> protected override void OnInitialize() { // create extension node extensionRootNode = new ScopeNode(); PrimaryNode.Children.Add(extensionRootNode); // get shared data SetDisplayName(extensionRootNode, PrimaryNode.SharedData.GetItem(machineNameClipboardFormatId)); }
public void Insert(int index, ScopeNode item) { base.Insert(index, item); }
public int Add(ScopeNode item) { return base.List.Add(item); }
/// <summary> /// The DisplayName of the extension node will be the computer name /// published by the primary. Note: this defaults to an empty string for localhost. /// </summary> void SetDisplayName(ScopeNode scopeNode, SharedDataItem sharedDataItem) { // get buffer containing the machine name string machineName = Encoding.Unicode.GetString(sharedDataItem.GetData()); // find first null terminated string in buffer. if (machineName.IndexOf('\0') <= 0) { // either not found in buffer or first entry in buffer machineName = String.Empty; } else { machineName = machineName.Substring(0, machineName.IndexOf('\0')); } // if empty then localhost if (machineName == string.Empty) { scopeNode.DisplayName = "Sample Extension to (localhost)"; } else { scopeNode.DisplayName = "Sample Extension to (" + machineName + ")"; } }
public void AddRange(ScopeNode[] items) { base.AddRange(items); }
public bool Contains(ScopeNode item) { return base.List.Contains(item); }
private DataFormatConfiguration[] GenerateSharedDataFormatConfiguration(ScopeNode node) { DataFormatConfiguration[] configurationArray = null; WritableSharedDataItem[] items = node.SharedData.GetItems(); if (items.Length > 0) { configurationArray = new DataFormatConfiguration[items.Length]; for (int i = 0; i < items.Length; i++) { configurationArray[i] = new DataFormatConfiguration(); configurationArray[i].RequiresQuery = items[i].RequiresCallback; configurationArray[i].ClipboardFormatId = items[i].ClipboardFormatId; } } return configurationArray; }
private ClipboardData[] GenerateClipboardData(ScopeNode node) { WritableSharedDataItem[] items = node.SharedData.GetItems(); List<ClipboardData> list = new List<ClipboardData>(); foreach (WritableSharedDataItem item in items) { if (!item.RequiresCallback) { ClipboardData data = new ClipboardData(); data.ClipboardFormatId = item.ClipboardFormatId; data.SetValue(item.GetData()); list.Add(data); } } if (list.Count > 0) { return list.ToArray(); } return null; }
public void Remove(ScopeNode item) { base.List.Remove(item); }
public int IndexOf(ScopeNode item) { return base.List.IndexOf(item); }
public void InsertRange(int index, ScopeNode[] items) { base.InsertRange(index, items); }
internal void RemoveNodes(ScopeNode[] items) { if (!this._initialized) { throw new Exception(Microsoft.ManagementConsole.Internal.Utility.LoadResourceString(Microsoft.ManagementConsole.Internal.Strings.NodeSyncManagerNotInitialized)); } if (items.Length != 0) { List<ScopeNode> nodeList = new List<ScopeNode>(); try { int[] ids = new int[items.Length]; for (int i = 0; i < items.Length; i++) { ids[i] = items[i].Id; } this.AddTreeToDeletionList(nodeList, items); DeleteScopeNodesCommand command = new DeleteScopeNodesCommand(); command.SetIds(ids); this._snapInPlatform.ProcessCommand(command); } catch { TraceSources.ExecutiveSource.TraceEvent(TraceEventType.Warning, 12, "NodeSyncManager.RemoveNodes() failed"); throw; } foreach (ScopeNode node in nodeList) { node.Children.ItemsChanged -= new ScopeNodeCollection.ScopeNodeCollectionEventHandler(this.OnNodesChanged); node.Changed -= new Node.NodeChangedEventHandler(this.OnNodeChanged); node.SharedDataChanged -= new ScopeNode.SharedDataChangedEventHandler(this.OnNodeSharedDataChanged); this._nodes.Remove(node.Id); node.OnNodeSyncManagerRemove(); } } }
public ScopeNodeCollectionEventArgs(int index, ScopeNode[] items, ScopeNodeCollectionChangeType changeType) { this._index = index; this._items = items; this._changeType = changeType; }
/// <summary> /// Intialize the extension to add new nodes attached to the Primary, etc. /// </summary> protected override void OnInitialize() { string sampleData1FromPrimary = Encoding.Unicode.GetString(PrimaryNode.SharedData.GetItem(Data1ClipboardFormatId).GetData()); ScopeNode scopeNode = new ScopeNode(); scopeNode.DisplayName = "Extension - Shared: (" + sampleData1FromPrimary + ")"; PrimaryNode.Children.Add(scopeNode); }
protected override void OnDelete(MMC.SyncStatus status) { MessageBoxParameters msg = new MessageBoxParameters(); switch (this.item.ItemType) { case ItemType.Role: msg.Caption = Globalization.MultilanguageResource.GetString("ListView_Msg90"); msg.Text = String.Format("{0}\r\n{1}", Globalization.MultilanguageResource.GetString("ListView_Msg100"), this.item.Name); break; case ItemType.Task: msg.Caption = Globalization.MultilanguageResource.GetString("ListView_Msg110"); msg.Text = String.Format("{0}\r\n{1}", Globalization.MultilanguageResource.GetString("ListView_Msg120"), this.item.Name); break; case ItemType.Operation: msg.Caption = Globalization.MultilanguageResource.GetString("ListView_Msg130"); msg.Text = String.Format("{0}\r\n{1}", Globalization.MultilanguageResource.GetString("ListView_Msg140"), this.item.Name); break; } msg.Icon = MessageBoxIcon.Question; msg.Buttons = MessageBoxButtons.YesNo; msg.DefaultButton = MessageBoxDefaultButton.Button2; DialogResult dr = this.SnapIn.Console.ShowDialog(msg); if (dr == DialogResult.Yes) { try { this.item.Delete(); try { //Remove relative child and all its children in Item Authorizations MMC.ScopeNode itemDefinitionsScopeNode = this.Parent.Parent; MMC.ScopeNode itemAuthorizationsScopeNode = itemDefinitionsScopeNode.Parent.Children[2]; switch (this.item.ItemType) { case ItemType.Role: if (itemAuthorizationsScopeNode.Children.Count >= 1) { itemAuthorizationsScopeNode = itemAuthorizationsScopeNode.Children[0]; } else { return; } break; case ItemType.Task: if (itemAuthorizationsScopeNode.Children.Count >= 2) { itemAuthorizationsScopeNode = itemAuthorizationsScopeNode.Children[1]; } else { return; } break; case ItemType.Operation: if (itemAuthorizationsScopeNode.Children.Count >= 3) { itemAuthorizationsScopeNode = itemAuthorizationsScopeNode.Children[2]; } else { return; } break; } this.RemoveItemAuthorizationScopeNode(itemAuthorizationsScopeNode, this); } catch { } } catch (Exception ex) { this.ShowError(ex.Message, Globalization.MultilanguageResource.GetString("DeleteError_Msg10")); } finally { this.Parent.Children.Remove(this); } } }