/// <summary> /// Create a dictionary of the unique key values of related nodes /// As a side effect, also populate MergeInfoData.NodePair.NodeReferences /// </summary> private Dictionary <CswDelimitedString, CswPrimaryKey> _getUniqueKeysDict(MergeInfoData.MergeInfoNodePair NodePair, CswNbtNode Node, CswNbtMetaDataNodeTypeProp NodeReferenceProp) { Dictionary <CswDelimitedString, CswPrimaryKey> ret = new Dictionary <CswDelimitedString, CswPrimaryKey>(); char delimiter = '|'; // Find unique properties for this reference's nodetype IEnumerable <CswNbtMetaDataNodeTypeProp> UniqueProps = NodeReferenceProp.getNodeType().getUniqueProps(); // Create a view of nodes that point to the target node via this reference CswNbtView view = new CswNbtView(_CswNbtResources); CswNbtViewRelationship rel1 = view.AddViewRelationship(Node.getNodeType(), false); rel1.NodeIdsToFilterIn.Add(Node.NodeId); CswNbtViewRelationship rel2 = view.AddViewRelationship(rel1, CswEnumNbtViewPropOwnerType.Second, NodeReferenceProp, false); foreach (CswNbtMetaDataNodeTypeProp uniqueProp in UniqueProps) { view.AddViewProperty(rel2, uniqueProp); } // Iterate children and store unique property values in a dictionary key ICswNbtTree tree = _CswNbtResources.Trees.getTreeFromView(view, RequireViewPermissions: false, IncludeHiddenNodes: true, IncludeSystemNodes: true); if (tree.getChildNodeCount() > 0) { tree.goToNthChild(0); for (Int32 c = 0; c < tree.getChildNodeCount(); c++) { tree.goToNthChild(c); CswPrimaryKey thisNodeId = tree.getNodeIdForCurrentPosition(); // Populate MergeInfoData.NodePair.NodeReferences while we're here NodePair.NodeReferences.Add(new MergeInfoData.MergeInfoNodeReference() { NodeId = thisNodeId.ToString(), NodeTypePropId = NodeReferenceProp.PropId }); CswDelimitedString key; if (_AllUniqueKeys.ContainsKey(thisNodeId)) { // If we've seen this node before, use the existing key but override the merge property // (this will allow us to merge correctly if a nodetype has // multiple compound unique references that are all involved in the merge) key = _AllUniqueKeys[thisNodeId]; for (Int32 u = 0; u < UniqueProps.Count(); u++) { if (UniqueProps.ElementAt(u).PropId == NodeReferenceProp.PropId) { // This value will be equal after the merge key[u] = "[mergeresult]"; } } // foreach( CswNbtMetaDataNodeTypeProp uniqueProp in UniqueProps ) } // if( _AllUniqueKeys.ContainsKey( thisNodeId ) ) else { // generate a new key key = new CswDelimitedString(delimiter); foreach (CswNbtMetaDataNodeTypeProp uniqueProp in UniqueProps) { CswNbtTreeNodeProp prop = tree.getChildNodePropsOfNode().FirstOrDefault(p => p.NodeTypePropId == uniqueProp.PropId); if (null != prop) { if (prop.NodeTypePropId == NodeReferenceProp.PropId) { // This value will be equal after the merge key.Add("[mergeresult]"); } else { key.Add(prop.Gestalt); } } else { key.Add(""); } } // foreach( CswNbtMetaDataNodeTypeProp uniqueProp in UniqueProps ) } // if-else( _AllUniqueKeys.ContainsKey( thisNodeId ) ) if (key.Count > 0) { ret.Add(key, thisNodeId); _AllUniqueKeys[thisNodeId] = key; } tree.goToParentNode(); } // for( Int32 c = 0; c < tree.getChildNodeCount(); c++ ) } // if( tree.getChildNodeCount() > 0 ) return(ret); } // _getUniqueKeysDict()
public void assignPropsToLocations( string LocationNodeKeys, bool UpdateInventoryGroup, string SelectedInventoryGroupNodeId, bool UpdateAllowInventory, string AllowInventory, bool UpdateControlZone, string SelectedControlZoneNodeId, bool UpdateStorageCompatability, string SelectedImages ) { if( false == string.IsNullOrEmpty( LocationNodeKeys ) ) { ///we don't pre-load he allowinventory value because there's no extra expense ///to doing so repeatedly in the loop CswNbtNode InventoryGroupNode = null; if( ( true == UpdateInventoryGroup ) && ( false == string.IsNullOrEmpty( SelectedInventoryGroupNodeId ) ) ) { CswPrimaryKey IGKey = new CswPrimaryKey(); IGKey.FromString( SelectedInventoryGroupNodeId ); InventoryGroupNode = _CswNbtResources.Nodes[IGKey]; } CswNbtNode ControlZoneNode = null; if( ( true == UpdateControlZone ) && ( false == string.IsNullOrEmpty( SelectedControlZoneNodeId ) ) ) { CswPrimaryKey IGKey = new CswPrimaryKey(); IGKey.FromString( SelectedControlZoneNodeId ); ControlZoneNode = _CswNbtResources.Nodes[IGKey]; } CswDelimitedString Images = new CswDelimitedString( ',' ); if( true == UpdateStorageCompatability ) { if( false == string.IsNullOrEmpty( SelectedImages ) ) { Images.FromString( SelectedImages ); } } foreach( string CurrentLocationKey in LocationNodeKeys.Split( ',' ) ) { if( false == string.IsNullOrEmpty( CurrentLocationKey ) ) { CswNbtNodeKey LKey = new CswNbtNodeKey( CurrentLocationKey ); CswNbtObjClassLocation CurrentLocationNode = _CswNbtResources.Nodes[LKey]; if( null != CurrentLocationNode ) { if( true == UpdateInventoryGroup ) { if( null != InventoryGroupNode ) { CurrentLocationNode.InventoryGroup.RelatedNodeId = InventoryGroupNode.NodeId; } else { CurrentLocationNode.InventoryGroup.RelatedNodeId = null; } } if( true == UpdateControlZone ) { if( null != ControlZoneNode ) { CurrentLocationNode.ControlZone.RelatedNodeId = ControlZoneNode.NodeId; } else { CurrentLocationNode.ControlZone.RelatedNodeId = null; } } if( UpdateAllowInventory ) { CurrentLocationNode.AllowInventory.Checked = CswConvert.ToTristate( AllowInventory ); } if( UpdateStorageCompatability ) { CurrentLocationNode.StorageCompatibility.Value = Images; } CurrentLocationNode.postChanges( true ); }//if current key yielded a node } //if there is a location keye } //iterate locations }//if we have location keys }//assignInventoryGroupToLocations()