Ejemplo n.º 1
0
 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();
         }
     }
 }
Ejemplo n.º 2
0
 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());
         }
     }
 }