public void Load(XmlReader xml) { _xml = xml; List<CompendiumViewRelationship> viewRelationships = new List<CompendiumViewRelationship>(); if (_xml != null && _xml.NodeType == XmlNodeType.Element && _xml.Name == CompendiumDocumentTag) { while (_xml.Read()) { if (_xml.NodeType == XmlNodeType.Element) { switch (_xml.Name) { case NodeDetailsTag: XmlCompendiumNode node = new XmlCompendiumNode(_xml); _nodes.Add(node.Id, node); break; case LinkRelationshipTag: CompendiumLinkRelationship nodeRelationship = new CompendiumLinkRelationship(); nodeRelationship.ConsumeLinkXml(_nodes, _xml); break; case ViewRelationshipTag: CompendiumViewRelationship viewRelationship = new CompendiumViewRelationship(); viewRelationship.ConsumeViewXml(_xml); viewRelationships.Add(viewRelationship); break; default: break; } } else if (_xml.NodeType == XmlNodeType.EndElement) { if (_xml.Name == CompendiumDocumentTag) { break; } } } } foreach (CompendiumViewRelationship viewRelationship in viewRelationships) { viewRelationship.BuildRelationships(_nodes); } }
public bool Load(XmlReader xml, string documentLibraryUrl) { _xml = xml; List <CompendiumViewRelationship> viewRelationships = new List <CompendiumViewRelationship>(); bool isDomainNodeRootMapNode = false; if (_xml != null && _xml.NodeType == XmlNodeType.Element && _xml.Name == COMPENDIUM_DOCUMENT_TAG) { _xml.MoveToAttribute("rootview"); string domainNodeId = _xml.Value; while (_xml.Read()) { if (_xml.NodeType == XmlNodeType.Element) { switch (_xml.Name) { case VIEW_RELATIONSHIP_TAG: CompendiumViewRelationship viewRelationship = new CompendiumViewRelationship(); viewRelationship.ConsumeViewXml(_xml, domainNodeId); viewRelationships.Add(viewRelationship); break; case NODE_DETAILS_TAG: XmlCompendiumNode node = new XmlCompendiumNode(_xml, domainNodeId, documentLibraryUrl); _nodes.Add(node.Id, node); break; case LINK_RELATIONSHIP_TAG: CompendiumLinkRelationship nodeRelationship = new CompendiumLinkRelationship(); if (nodeRelationship.ConsumeLinkXml(_nodes, _xml, domainNodeId)) { isDomainNodeRootMapNode = true; } break; default: break; } } else if (_xml.NodeType == XmlNodeType.EndElement) { if (_xml.Name == COMPENDIUM_DOCUMENT_TAG) { break; } } } if (isDomainNodeRootMapNode) { _nodes[domainNodeId].NodeType = IoCContainer.GetInjectionInstance().GetInstance <IMapManager>().NodeTypes["CompendiumMapNode"]; } } foreach (CompendiumViewRelationship viewRelationship in viewRelationships) { viewRelationship.BuildRelationships(_nodes); if (!_rootViewRelationships.Contains(viewRelationship) && viewRelationship.IsRootView) { _rootViewRelationships.Add(viewRelationship); } } List <string> transcludedNodes = new List <string>(); List <string> nonTranscludedNodes = new List <string>(); foreach (CompendiumViewRelationship viewRelationship in viewRelationships) { if (nonTranscludedNodes.Contains(viewRelationship.FromNode.Id)) { /// If this node is in the non-transcluded nodes list then it means it IS a transclusion and needs to be moved out of the transcluded nodes list. transcludedNodes.Add(viewRelationship.FromNode.Id); nonTranscludedNodes.Remove(viewRelationship.FromNode.Id); /// We need to notify all the link relationships for this node that they are part of a transclusion so their "Map" property means something. foreach (IDescriptor descriptor in viewRelationship.FromNode.Descriptors) { if (descriptor.Relationship is CompendiumLinkRelationship) { CompendiumLinkRelationship linkRelationship = descriptor.Relationship as CompendiumLinkRelationship; linkRelationship.ConvertToTransclusionRelationship(_nodes); } } } else if (!transcludedNodes.Contains(viewRelationship.FromNode.Id)) { /// If this ID isn't in the non-transcluded nodes list and it's not in the transcluded nodes list, then it means we haven't added yet. nonTranscludedNodes.Add(viewRelationship.FromNode.Id); } } return(isDomainNodeRootMapNode); }
private void BuildRelationships(ref Queue <TransactionFramework.TransactionChain> transactionQueue) { int transactionCounts = 0; TransactionFramework.TransactionChain chain = new TransactionFramework.TransactionChain(); foreach (XmlModel.INode node in Nodes) { foreach (XmlModel.IDescriptor descriptor in node.Descriptors) { if (descriptor.DescriptorType == null || descriptor.DescriptorType.Name == "From") { continue; } XmlModel.IRelationship relationship = descriptor.Relationship; XmlModel.INode connectedNode = null; foreach (XmlModel.IDescriptor linkedDescriptor in relationship.Descriptors) { if (linkedDescriptor != descriptor) { connectedNode = linkedDescriptor.Node; break; } } if (connectedNode == null) { // This means that there was no connected nodes or there may have been a circular reference. continue; } Proxy.INode proxyNode; if (ProxyNodes.ContainsKey(node.Id)) { proxyNode = ProxyNodes[node.Id]; } else { continue; } Proxy.INode proxyConnectedNode; if (ProxyNodes.ContainsKey(connectedNode.Id)) { proxyConnectedNode = ProxyNodes[connectedNode.Id]; } else { continue; } if (proxyNode.NodeType == MapManager.NodeTypes["DomainNode"] || proxyConnectedNode.NodeType == MapManager.NodeTypes["DomainNode"]) { continue; } if (transactionCounts >= 150) { transactionQueue.Enqueue(chain); chain = new TransactionFramework.TransactionChain(); transactionCounts = 0; } else { transactionCounts++; } if (relationship is CompendiumLinkRelationship) { CompendiumLinkRelationship linkRelationship = relationship as CompendiumLinkRelationship; if (!linkRelationship.IsTransclusion) { // In this situation the relationship is between two nodes in a map. Proxy.IRelationship newRelationship = MapManager.CreateRelationship(Map.DomainId, Map.RootMapId.Value, MapManager.RelationshipTypes["FromToRelationship"], string.Empty, ref chain); newRelationship.ConnectNode(MapManager.ConnectionTypes["To"], proxyNode, ref chain); newRelationship.ConnectNode(MapManager.ConnectionTypes["From"], proxyConnectedNode, ref chain); } else { Proxy.INode proxyMap = ProxyNodes[linkRelationship.Map.Id]; // In this situation the relationship is a transclusion so we'll need to handle it slightly differently. //Proxy.IRelationship newTranscludedNodeRelationship = MapManager.CreateRelationship(Map.DomainId, MapManager.RelationshipTypes["MapContainerRelationship"], string.Empty, ref chain); //newTranscludedNodeRelationship.ConnectNode(MapManager.ConnectionTypes["To"], proxyMap, ref chain); //newTranscludedNodeRelationship.ConnectNode(MapManager.ConnectionTypes["From"], transclusionNode, ref chain); //transclusionNode.Metadata.Add(newTranscludedNodeRelationship, MapManager.ConnectionTypes["From"], "XPosition", transclusionRelationship.XPosition.ToString(), ref chain); //transclusionNode.Metadata.Add(newTranscludedNodeRelationship, MapManager.ConnectionTypes["From"], "YPosition", transclusionRelationship.YPosition.ToString(), ref chain); Proxy.IRelationship newTransclusionRelationship = MapManager.CreateRelationship(Map.DomainId, Map.RootMapId.Value, MapManager.RelationshipTypes["TransclusionFromToRelationship"], string.Empty, ref chain); newTransclusionRelationship.ConnectNode(MapManager.ConnectionTypes["TransclusionMap"], proxyMap, ref chain); newTransclusionRelationship.ConnectNode(MapManager.ConnectionTypes["To"], proxyNode, ref chain); newTransclusionRelationship.ConnectNode(MapManager.ConnectionTypes["From"], proxyConnectedNode, ref chain); } } else if (relationship is CompendiumViewRelationship) { CompendiumViewRelationship viewRelationship = relationship as CompendiumViewRelationship; if (!viewRelationship.IsRootView) { // In this situation the relationship is between a node and a map node. Proxy.IRelationship newRelationship = MapManager.CreateRelationship(Map.DomainId, Map.RootMapId.Value, MapManager.RelationshipTypes["MapContainerRelationship"], string.Empty, ref chain); newRelationship.ConnectNode(MapManager.ConnectionTypes["To"], proxyNode, ref chain); newRelationship.ConnectNode(MapManager.ConnectionTypes["From"], proxyConnectedNode, ref chain); proxyConnectedNode.Metadata.Add(newRelationship, MapManager.ConnectionTypes["From"], "XPosition", viewRelationship.XPosition.ToString(), ref chain); proxyConnectedNode.Metadata.Add(newRelationship, MapManager.ConnectionTypes["From"], "YPosition", viewRelationship.YPosition.ToString(), ref chain); } } else { // In this situation the relationship is of an unknown type so lets just skip it. continue; } } //chains.Enqueue(chain); //MapManager.ExecuteTransaction(chain); /// } if (chain != null && chain.NumOfTransactions > 0) { transactionQueue.Enqueue(chain); } }