SilverlightMappingToolBasic.MapDepth.MapDepthNavigator.OnConnectNodesCompletedNodeArgs C# (CSharp) Method

OnConnectNodesCompletedNodeArgs() private method

private OnConnectNodesCompletedNodeArgs ( object sender, ConnectedNodesEventArgs e ) : void
sender object
e ConnectedNodesEventArgs
return void
        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);
            }
        }