private void OnConnectNodesCompletedNodeArgs(object sender, ConnectedNodesEventArgs e) { List<INodeProxy> nodes = new List<INodeProxy>(); TypeManager typeManager = IoC.IoCContainer.GetInjectionInstance().GetInstance<TypeManager>(); IMetadataTypeProxy metaDataTypeProxy = typeManager.GetMetadataType("double"); if (e.Relationship.RelationshipType.Name == "TransclusionRelationship") { foreach (IDescriptorProxy descriptorProxy in e.Relationship.Descriptors.GetByDescriptorTypeName("To")) { nodes.Add(descriptorProxy.Node); } if (e.Nodes.Length == 2) //TODO: Fix this, currently checking if it's just a transcluded node to map relationship { IDescriptorTypeProxy transclusionMapDesc = typeManager.GetDescriptorType("TransclusionMap"); MetadataContext xPositionKey = new MetadataContext() { NodeUid = e.Nodes[1].Id, MetadataName = "XPosition", RelationshipUid = e.Relationship.Id, DescriptorTypeUid = transclusionMapDesc.Id }; MetadataContext yPositionKey = new MetadataContext() { NodeUid = e.Nodes[1].Id, MetadataName = "YPosition", RelationshipUid = e.Relationship.Id, DescriptorTypeUid = transclusionMapDesc.Id }; //it'll be the second node that is the added node, the first node is the map - this is unsafe to assume so needs to be fixed UpdateNodeMetadataAsync(e.Nodes[1], e.Relationship.Id, transclusionMapDesc, "XPosition", e.Nodes[1].GetNodeMetadata(xPositionKey).MetadataValue, metaDataTypeProxy); UpdateNodeMetadataAsync(e.Nodes[1], e.Relationship.Id, transclusionMapDesc, "YPosition", e.Nodes[1].GetNodeMetadata(yPositionKey).MetadataValue, metaDataTypeProxy); } } else if (e.Relationship.RelationshipType.Name == "MapContainerRelationship") { //if it's a MapContainerRelationship update the positioning based on the context of this map it's being added to IDescriptorTypeProxy fromDescriptorTypeProxy = null; if (e.Relationship != null) { fromDescriptorTypeProxy = typeManager.GetDescriptorType("From"); MetadataContext xPositionKey = new MetadataContext() { NodeUid = e.Nodes[1].Id, MetadataName = "XPosition", RelationshipUid = e.Relationship.Id, DescriptorTypeUid = fromDescriptorTypeProxy.Id }; MetadataContext yPositionKey = new MetadataContext() { NodeUid = e.Nodes[1].Id, MetadataName = "YPosition", RelationshipUid = e.Relationship.Id, DescriptorTypeUid = fromDescriptorTypeProxy.Id }; //it'll be the second node that is the added node, the first node is the map - this is unsafe to assume so needs to be fixed UpdateNodeMetadataAsync(e.Nodes[1], e.Relationship.Id, fromDescriptorTypeProxy, "XPosition", e.Nodes[1].GetNodeMetadata(xPositionKey).MetadataValue, metaDataTypeProxy); UpdateNodeMetadataAsync(e.Nodes[1], e.Relationship.Id, fromDescriptorTypeProxy, "YPosition", e.Nodes[1].GetNodeMetadata(yPositionKey).MetadataValue, metaDataTypeProxy); nodes.Add(e.Nodes[1]); } } else { foreach (INodeProxy nodeProxy in e.Nodes) { nodes.Add(nodeProxy); } } NodesEventArgs nodesEventArgs = new NodesEventArgs(null, null, nodes.ToArray()); if (ConnectNodesCompleted != null) { ConnectNodesCompleted.Invoke(this, nodesEventArgs); } }
private void OnConnectNodesCompletedNodeArgs(object sender, ConnectedNodesEventArgs e) { List <INodeProxy> nodes = new List <INodeProxy>(); TypeManager typeManager = IoC.IoCContainer.GetInjectionInstance().GetInstance <TypeManager>(); IMetadataTypeProxy metaDataTypeProxy = typeManager.GetMetadataType("double"); if (e.Relationship.RelationshipType.Name == "TransclusionRelationship") { foreach (IDescriptorProxy descriptorProxy in e.Relationship.Descriptors.GetByDescriptorTypeName("To")) { nodes.Add(descriptorProxy.Node); } if (e.Nodes.Length == 2) //TODO: Fix this, currently checking if it's just a transcluded node to map relationship { IDescriptorTypeProxy transclusionMapDesc = typeManager.GetDescriptorType("TransclusionMap"); MetadataContext xPositionKey = new MetadataContext() { NodeUid = e.Nodes[1].Id, MetadataName = "XPosition", RelationshipUid = e.Relationship.Id, DescriptorTypeUid = transclusionMapDesc.Id }; MetadataContext yPositionKey = new MetadataContext() { NodeUid = e.Nodes[1].Id, MetadataName = "YPosition", RelationshipUid = e.Relationship.Id, DescriptorTypeUid = transclusionMapDesc.Id }; //it'll be the second node that is the added node, the first node is the map - this is unsafe to assume so needs to be fixed UpdateNodeMetadataAsync(e.Nodes[1], e.Relationship.Id, transclusionMapDesc, "XPosition", e.Nodes[1].GetNodeMetadata(xPositionKey).MetadataValue, metaDataTypeProxy); UpdateNodeMetadataAsync(e.Nodes[1], e.Relationship.Id, transclusionMapDesc, "YPosition", e.Nodes[1].GetNodeMetadata(yPositionKey).MetadataValue, metaDataTypeProxy); } } else if (e.Relationship.RelationshipType.Name == "MapContainerRelationship") { //if it's a MapContainerRelationship update the positioning based on the context of this map it's being added to IDescriptorTypeProxy fromDescriptorTypeProxy = null; if (e.Relationship != null) { fromDescriptorTypeProxy = typeManager.GetDescriptorType("From"); MetadataContext xPositionKey = new MetadataContext() { NodeUid = e.Nodes[1].Id, MetadataName = "XPosition", RelationshipUid = e.Relationship.Id, DescriptorTypeUid = fromDescriptorTypeProxy.Id }; MetadataContext yPositionKey = new MetadataContext() { NodeUid = e.Nodes[1].Id, MetadataName = "YPosition", RelationshipUid = e.Relationship.Id, DescriptorTypeUid = fromDescriptorTypeProxy.Id }; //it'll be the second node that is the added node, the first node is the map - this is unsafe to assume so needs to be fixed UpdateNodeMetadataAsync(e.Nodes[1], e.Relationship.Id, fromDescriptorTypeProxy, "XPosition", e.Nodes[1].GetNodeMetadata(xPositionKey).MetadataValue, metaDataTypeProxy); UpdateNodeMetadataAsync(e.Nodes[1], e.Relationship.Id, fromDescriptorTypeProxy, "YPosition", e.Nodes[1].GetNodeMetadata(yPositionKey).MetadataValue, metaDataTypeProxy); nodes.Add(e.Nodes[1]); } } else { foreach (INodeProxy nodeProxy in e.Nodes) { nodes.Add(nodeProxy); } } NodesEventArgs nodesEventArgs = new NodesEventArgs(null, null, nodes.ToArray()); if (ConnectNodesCompleted != null) { ConnectNodesCompleted.Invoke(this, nodesEventArgs); } }
private void OnConnectNodesCompleted(object sender, ConnectNodesCompletedEventArgs e) { if (e.Error == null) { List <INodeProxy> nodes = new List <INodeProxy>(); ConnectedNodesResult connectResult = e.Result; foreach (SoapNode soapNode in connectResult.Nodes.Values) { if (_cachedNodes.ContainsKey(soapNode.Id)) { _cachedNodes.Remove(soapNode.Id); } NodeProxy node = new NodeProxy(soapNode); _cachedNodes.Add(soapNode.Id, node); nodes.Add(node); } foreach (INodeProxy nodeProxy in nodes) { foreach (IDescriptorProxy descriptorProxy in nodeProxy.Descriptors) { CompleteRelationship(descriptorProxy.Relationship); } } ConnectedNodesEventArgs connectedNodesEventArgs = new ConnectedNodesEventArgs(); connectedNodesEventArgs.Nodes = nodes.ToArray(); connectedNodesEventArgs.Relationship = new RelationshipProxy(e.Result.Relationship); CompleteRelationship(connectedNodesEventArgs.Relationship); //When a node is connected via a MapContainerRelationship the UserState will be the location of the new node //on the map, it can't be stored in the db until the relationship exists since it's the contectual relationship //that determines where it is located in it's view in this map (it may be elsewhere in transclusions) if (e.UserState != null) { INodeProxy nodeProxy = connectedNodesEventArgs.Nodes[1]; Point location = (Point)e.UserState; if (location != null) { TypeManager typeManager = IoC.IoCContainer.GetInjectionInstance().GetInstance <TypeManager>(); IDescriptorTypeProxy descriptorType = null; if (e.Result.Relationship.RelationshipType.Name == "TransclusionRelationship") { descriptorType = typeManager.GetDescriptorType("TransclusionMap"); } else { descriptorType = typeManager.GetDescriptorType("From"); } MetadataContext xPositionKey = new MetadataContext() { NodeUid = nodeProxy.Id, RelationshipUid = e.Result.Relationship.Id, DescriptorTypeUid = descriptorType.Id, MetadataName = "XPosition" }; MetadataContext yPositionKey = new MetadataContext() { NodeUid = nodeProxy.Id, RelationshipUid = e.Result.Relationship.Id, DescriptorTypeUid = descriptorType.Id, MetadataName = "YPosition" }; if (nodeProxy.Metadata != null && nodeProxy.GetNodeMetadata(xPositionKey) != null) { nodeProxy.GetNodeMetadata(xPositionKey).MetadataValue = location.X.ToString(); } else { MetadataTypeProxy metaDataTypeProxy = typeManager.GetMetadataType("double") as MetadataTypeProxy; if (metaDataTypeProxy != null) { SoapMetadata soapMetadata = new SoapMetadata(); soapMetadata.MetadataName = "XPosition"; soapMetadata.MetadataType = metaDataTypeProxy.BaseSoapNodeType; soapMetadata.MetadataValue = location.X.ToString(); nodeProxy.Metadata.Add(xPositionKey, soapMetadata); } } if (nodeProxy.Metadata != null && nodeProxy.GetNodeMetadata(yPositionKey) != null) { nodeProxy.GetNodeMetadata(yPositionKey).MetadataValue = location.Y.ToString(); } else { MetadataTypeProxy metaDataTypeProxy = typeManager.GetMetadataType("double") as MetadataTypeProxy; if (metaDataTypeProxy != null) { SoapMetadata soapMetadata = new SoapMetadata(); soapMetadata.MetadataName = "YPosition"; soapMetadata.MetadataType = metaDataTypeProxy.BaseSoapNodeType; soapMetadata.MetadataValue = location.Y.ToString(); nodeProxy.Metadata.Add(yPositionKey, soapMetadata); } } } } if (ConnectNodesCompleted != null) { ConnectNodesCompleted.Invoke(this, connectedNodesEventArgs); } } }
private void OnConnectNodesCompleted(object sender, ConnectNodesCompletedEventArgs e) { if (e.Error == null) { List<INodeProxy> nodes = new List<INodeProxy>(); ConnectedNodesResult connectResult = e.Result; foreach (SoapNode soapNode in connectResult.Nodes.Values) { if (_cachedNodes.ContainsKey(soapNode.Id)) { _cachedNodes.Remove(soapNode.Id); } NodeProxy node = new NodeProxy(soapNode); _cachedNodes.Add(soapNode.Id, node); nodes.Add(node); } foreach (INodeProxy nodeProxy in nodes) { foreach (IDescriptorProxy descriptorProxy in nodeProxy.Descriptors) { CompleteRelationship(descriptorProxy.Relationship); } } ConnectedNodesEventArgs connectedNodesEventArgs = new ConnectedNodesEventArgs(); connectedNodesEventArgs.Nodes = nodes.ToArray(); connectedNodesEventArgs.Relationship = new RelationshipProxy(e.Result.Relationship); CompleteRelationship(connectedNodesEventArgs.Relationship); //When a node is connected via a MapContainerRelationship the UserState will be the location of the new node //on the map, it can't be stored in the db until the relationship exists since it's the contectual relationship //that determines where it is located in it's view in this map (it may be elsewhere in transclusions) if (e.UserState != null) { INodeProxy nodeProxy = connectedNodesEventArgs.Nodes[1]; Point location = (Point)e.UserState; if (location != null) { TypeManager typeManager = IoC.IoCContainer.GetInjectionInstance().GetInstance<TypeManager>(); IDescriptorTypeProxy descriptorType = null; if (e.Result.Relationship.RelationshipType.Name == "TransclusionRelationship") { descriptorType = typeManager.GetDescriptorType("TransclusionMap"); } else { descriptorType = typeManager.GetDescriptorType("From"); } MetadataContext xPositionKey = new MetadataContext() { NodeUid = nodeProxy.Id, RelationshipUid = e.Result.Relationship.Id, DescriptorTypeUid = descriptorType.Id, MetadataName = "XPosition" }; MetadataContext yPositionKey = new MetadataContext() { NodeUid = nodeProxy.Id, RelationshipUid = e.Result.Relationship.Id, DescriptorTypeUid = descriptorType.Id, MetadataName = "YPosition" }; if (nodeProxy.Metadata != null && nodeProxy.GetNodeMetadata(xPositionKey) != null) { nodeProxy.GetNodeMetadata(xPositionKey).MetadataValue = location.X.ToString(); } else { MetadataTypeProxy metaDataTypeProxy = typeManager.GetMetadataType("double") as MetadataTypeProxy; if (metaDataTypeProxy != null) { SoapMetadata soapMetadata = new SoapMetadata(); soapMetadata.MetadataName = "XPosition"; soapMetadata.MetadataType = metaDataTypeProxy.BaseSoapNodeType; soapMetadata.MetadataValue = location.X.ToString(); nodeProxy.Metadata.Add(xPositionKey, soapMetadata); } } if (nodeProxy.Metadata != null && nodeProxy.GetNodeMetadata(yPositionKey) != null) { nodeProxy.GetNodeMetadata(yPositionKey).MetadataValue = location.Y.ToString(); } else { MetadataTypeProxy metaDataTypeProxy = typeManager.GetMetadataType("double") as MetadataTypeProxy; if (metaDataTypeProxy != null) { SoapMetadata soapMetadata = new SoapMetadata(); soapMetadata.MetadataName = "YPosition"; soapMetadata.MetadataType = metaDataTypeProxy.BaseSoapNodeType; soapMetadata.MetadataValue = location.Y.ToString(); nodeProxy.Metadata.Add(yPositionKey, soapMetadata); } } } } if (ConnectNodesCompleted != null) { ConnectNodesCompleted.Invoke(this, connectedNodesEventArgs); } } }