Inheritance: SoapTypeElement
Exemplo n.º 1
0
        public static ISoapTypeElement GetSoapType <SoapType>(Guid typeUid) where SoapType : ISoapTypeElement
        {
            lock (_lock)
            {
                if (_soapTypes.ContainsKey(typeUid))
                {
                    return(_soapTypes[typeUid]);
                }

                using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext())
                {
                    if (typeof(SoapType).IsAssignableFrom(typeof(SoapNodeType)))
                    {
                        var nodeType = (from dbNodeType in mappingDb.NodeTypes where dbNodeType.NodeTypeUid == typeUid select dbNodeType).First();

                        SoapNodeType soapNodeType = new SoapNodeType();
                        soapNodeType.Id   = nodeType.NodeTypeUid;
                        soapNodeType.Name = nodeType.NodeTypeName;

                        return((ISoapTypeElement)soapNodeType);
                    }
                    else if (typeof(SoapType).IsAssignableFrom(typeof(SoapDescriptorType)))
                    {
                        var nodeType = (from dbNodeType in mappingDb.DescriptorTypes where dbNodeType.DescriptorTypeUid == typeUid select dbNodeType).First();

                        SoapDescriptorType soapDescriptorType = new SoapDescriptorType();
                        soapDescriptorType.Id   = nodeType.DescriptorTypeUid;
                        soapDescriptorType.Name = nodeType.DescriptorTypeName;

                        return((ISoapTypeElement)soapDescriptorType);
                    }
                    else if (typeof(SoapType).IsAssignableFrom(typeof(SoapRelationshipType)))
                    {
                        var nodeType = (from dbNodeType in mappingDb.RelationshipTypes where dbNodeType.RelationshipTypeUid == typeUid select dbNodeType).First();

                        SoapRelationshipType soapRelationshipType = new SoapRelationshipType();
                        soapRelationshipType.Id   = nodeType.RelationshipTypeUid;
                        soapRelationshipType.Name = nodeType.RelationshipTypeName;

                        return((ISoapTypeElement)soapRelationshipType);
                    }
                    else if (typeof(SoapType).IsAssignableFrom(typeof(SoapMetadataType)))
                    {
                        var nodeType = (from dbNodeType in mappingDb.MetadataTypes where dbNodeType.MetadataTypeUid == typeUid select dbNodeType).First();

                        SoapMetadataType soapMetadataType = new SoapMetadataType();
                        soapMetadataType.Id   = nodeType.MetadataTypeUid;
                        soapMetadataType.Name = nodeType.MetadataTypeName;

                        return((ISoapTypeElement)soapMetadataType);
                    }
                    else
                    {
                        throw new NotSupportedException("The requested type is not supported");
                    }
                }
            }
        }
Exemplo n.º 2
0
        public List<SoapTypeElement> GetAllSoapTypes()
        {
            List<SoapTypeElement> soapTypes = new List<SoapTypeElement>();
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext())
                {
                    var metadataTypes = from dbMetadataTypes in mappingDb.MetadataTypes select dbMetadataTypes;
                    var nodeTypes = from dbNodeTypes in mappingDb.NodeTypes select dbNodeTypes;
                    var descriptorTypes = from dbDescriptorTypes in mappingDb.DescriptorTypes select dbDescriptorTypes;
                    var relationshipTypes = from dbRelationshipTypes in mappingDb.RelationshipTypes select dbRelationshipTypes;

                    foreach (var metadataType in metadataTypes)
                    {
                        SoapMetadataType soapMetadataType = new SoapMetadataType();
                        soapMetadataType.Id = metadataType.MetadataTypeUid;
                        soapMetadataType.Name = metadataType.MetadataTypeName;

                        soapTypes.Add(soapMetadataType);
                    }

                    foreach (var nodeType in nodeTypes)
                    {
                        SoapNodeType soapNodeType = new SoapNodeType();
                        soapNodeType.Id = nodeType.NodeTypeUid;
                        soapNodeType.Name = nodeType.NodeTypeName;

                        soapTypes.Add(soapNodeType);
                    }

                    foreach (var descriptorType in descriptorTypes)
                    {
                        SoapDescriptorType soapDescriptorType = new SoapDescriptorType();
                        soapDescriptorType.Id = descriptorType.DescriptorTypeUid;
                        soapDescriptorType.Name = descriptorType.DescriptorTypeName;

                        soapTypes.Add(soapDescriptorType);
                    }

                    foreach (var relationshipType in relationshipTypes)
                    {
                        SoapRelationshipType soapRelationshipType = new SoapRelationshipType();
                        soapRelationshipType.Id = relationshipType.RelationshipTypeUid;
                        soapRelationshipType.Name = relationshipType.RelationshipTypeName;

                        soapTypes.Add(soapRelationshipType);
                    }
                }
            });
            return soapTypes;
        }
        public TransactionToken AddRelationship(TransactionToken domainId, Dictionary<SoapDescriptorType, TransactionToken> nodes, SoapRelationshipType relationshipType, string originalId)
        {
            AddRelationshipTransactionOperation operation = new AddRelationshipTransactionOperation(Connection, TokenFactory);

            foreach (KeyValuePair<SoapDescriptorType, TransactionToken> keyValuePair in nodes)
            {
                nodes[keyValuePair.Key] = TokenFactory.ProcessToken(keyValuePair.Value);
            }

            operation.DomainId = TokenFactory.ProcessToken(domainId);
            operation.Nodes = nodes;
            operation.RelationshipType = relationshipType;
            operation.OriginalId = originalId;

            Operations.Enqueue(operation);

            return operation.ResultTokens.First();
        }
Exemplo n.º 4
0
        public ConnectedNodesResult ConnectNodes(Guid domainId, Dictionary<SoapDescriptorType, Guid> nodes, SoapRelationshipType relationshipType, string originalId)
        {
            ConnectedNodesResult connectedNodesResult = null;
            if (nodes.Values.Distinct().Count() > 1)
            {
                SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext())
                    {
                        List<SoapNode> updatedNodes = new List<SoapNode>();

                        var domains = from dbDomain in mappingDb.Domains where dbDomain.DomainUid == domainId select dbDomain;

                        var domain = domains.First();

                        Relationship relationship = new Relationship();
                        relationship.RelationshipUid = Guid.NewGuid();
                        relationship.RelationshipOriginalId = originalId;
                        relationship.RelationshipTypeUid = relationshipType.Id;

                        SoapRelationship soapRelationship = new SoapRelationship();
                        soapRelationship.Id = relationship.RelationshipUid;
                        soapRelationship.RelationshipType = relationshipType;

                        foreach (KeyValuePair<SoapDescriptorType, Guid> keyValuePair in nodes)
                        {
                            Descriptor descriptor = new Descriptor();
                            descriptor.DescriptorUid = Guid.NewGuid();
                            descriptor.RelationshipUid = relationship.RelationshipUid;
                            descriptor.DescriptorTypeUid = keyValuePair.Key.Id;

                            Node node = domain.Nodes.Single(x => x.NodeUid == keyValuePair.Value);
                            node.Domain = domain;
                            node.Descriptors.Add(descriptor);

                            soapRelationship.Nodes.Add(keyValuePair.Key, node.NodeUid);
                            SoapNode soapNode = node.ToSoapObject();
                            soapNode.Relationships.Add(soapRelationship.Id, soapRelationship);
                            updatedNodes.Add(soapNode);

                            domain.Relationships.Add(relationship);
                        }

                        mappingDb.SubmitChanges();

                        connectedNodesResult = new ConnectedNodesResult();
                        connectedNodesResult.Relationship = soapRelationship;
                        connectedNodesResult.Nodes = new Dictionary<Guid, SoapNode>();
                        foreach (SoapNode soapNode in updatedNodes)
                        {
                            if (!connectedNodesResult.Nodes.ContainsKey(soapNode.Id))
                            {
                                connectedNodesResult.Nodes.Add(soapNode.Id, soapNode);
                            }
                        }
                    }
                });
            }
            else
            {
                LoggingService.WriteTrace(LoggingService.Categories.WcfServices, TraceSeverity.Unexpected, "ConnectNodes() failed: There must be at least 2 distinct nodes connected.");
                //This will cause an error to be returned on the WFC event, over SOAP it won't contain the fault contract.
                throw new FaultException<ConnectNodesFailureFault>(new ConnectNodesFailureFault(), "There must be at least 2 distinct nodes connected.");
            }

            return connectedNodesResult;
        }
Exemplo n.º 5
0
        public TransactionToken AddRelationship(TransactionToken domainId, Dictionary <SoapDescriptorType, TransactionToken> nodes, SoapRelationshipType relationshipType, string originalId)
        {
            AddRelationshipTransactionOperation operation = new AddRelationshipTransactionOperation(Connection, TokenFactory);

            foreach (KeyValuePair <SoapDescriptorType, TransactionToken> keyValuePair in nodes)
            {
                nodes[keyValuePair.Key] = TokenFactory.ProcessToken(keyValuePair.Value);
            }

            operation.DomainId         = TokenFactory.ProcessToken(domainId);
            operation.Nodes            = nodes;
            operation.RelationshipType = relationshipType;
            operation.OriginalId       = originalId;

            Operations.Enqueue(operation);

            return(operation.ResultTokens.First());
        }