상속: SoapTypeElement
예제 #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");
                    }
                }
            }
        }
        protected SqlCommand CreateDescriptor(out Guid newDescriptorUid, SoapDescriptorType descriptorType, TransactionToken nodeUid, Guid relationshipUid)
        {
            SqlCommand createDescriptorCommand = new SqlCommand();
            createDescriptorCommand.CommandText = "INSERT INTO dbo.[Descriptors] (DescriptorUid, DescriptorTypeUid, NodeUid, RelationshipUid) VALUES (@DescriptorUid, @DescriptorTypeUid, @NodeUid, @RelationshipUid)";
            createDescriptorCommand.Connection = Connection;

            newDescriptorUid = Guid.NewGuid();

            createDescriptorCommand.Parameters.AddWithValue("@DescriptorUid", newDescriptorUid);
            createDescriptorCommand.Parameters.AddWithValue("@DescriptorTypeUid", descriptorType.Id);
            createDescriptorCommand.Parameters.AddWithValue("@NodeUid", nodeUid.GetValue());
            createDescriptorCommand.Parameters.AddWithValue("@RelationshipUid", relationshipUid);

            return createDescriptorCommand;
        }
예제 #3
0
        protected SqlCommand CreateDescriptor(out Guid newDescriptorUid, SoapDescriptorType descriptorType, TransactionToken nodeUid, Guid relationshipUid)
        {
            SqlCommand createDescriptorCommand = new SqlCommand();

            createDescriptorCommand.CommandText = "INSERT INTO dbo.[Descriptors] (DescriptorUid, DescriptorTypeUid, NodeUid, RelationshipUid) VALUES (@DescriptorUid, @DescriptorTypeUid, @NodeUid, @RelationshipUid)";
            createDescriptorCommand.Connection  = Connection;

            newDescriptorUid = Guid.NewGuid();

            createDescriptorCommand.Parameters.AddWithValue("@DescriptorUid", newDescriptorUid);
            createDescriptorCommand.Parameters.AddWithValue("@DescriptorTypeUid", descriptorType.Id);
            createDescriptorCommand.Parameters.AddWithValue("@NodeUid", nodeUid.GetValue());
            createDescriptorCommand.Parameters.AddWithValue("@RelationshipUid", relationshipUid);

            return(createDescriptorCommand);
        }
예제 #4
0
        public static SoapRelationship ToSoapObject(this Relationship relationship)
        {
            if (relationship != null)
            {
                SoapRelationship soapRelationship = new SoapRelationship();

                soapRelationship.Id = relationship.RelationshipUid;

                if (relationship.RelationshipTypeUid == null || !relationship.RelationshipTypeUid.HasValue)
                {
                    throw new NullReferenceException("There is no Relationship Type for this relationship.");
                }

                soapRelationship.RelationshipType = (SoapRelationshipType)SoapTypeFactory.GetSoapType <SoapRelationshipType>(relationship.RelationshipTypeUid.Value);

                soapRelationship.Relationship = relationship;

                var allMetadata = relationship.Metadatas.OrderBy(x => (x.DescriptorTypeUid != null) ? x.DescriptorTypeUid : Guid.Empty);

                foreach (var datum in allMetadata)
                {
                    SoapMetadata soapDatum = new SoapMetadata();
                    soapDatum.MetadataName  = datum.MetadataName;
                    soapDatum.MetadataValue = datum.MetadataValue;

                    if (datum.MetadataTypeUid.HasValue)
                    {
                        soapDatum.MetadataType = (SoapMetadataType)SoapTypeFactory.GetSoapType <SoapMetadataType>(datum.MetadataTypeUid.Value);
                    }

                    soapRelationship.Metadata[datum.MetadataName] = soapDatum;
                }

                foreach (var descriptor in relationship.Descriptors)
                {
                    SoapDescriptorType soapDescriptor = (SoapDescriptorType)SoapTypeFactory.GetSoapType <SoapDescriptorType>(descriptor.DescriptorTypeUid.Value);

                    soapRelationship.Nodes.Add(soapDescriptor, descriptor.NodeUid.Value);
                }

                return(soapRelationship);
            }
            return(null);
        }
예제 #5
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;
        }
예제 #6
0
        private static SoapMetadata UpdateMetadata(MappingToolDatabaseDataContext mappingDb, Guid soapNodeId, Guid soapRelationshipId, SoapDescriptorType soapDescriptorType, string metadataName, string metadataValue, SoapMetadataType soapMetadataType, Node node)
        {
            SoapMetadata soapMetadata = new SoapMetadata();
            soapMetadata.MetadataName = metadataName;
            soapMetadata.MetadataValue = metadataValue;
            soapMetadata.MetadataType = soapMetadataType;

            bool existingMetaData = false;
            foreach (Metadata metadatum in node.Metadatas.Where(x => x.MetadataName == metadataName))
            {
                if (soapNodeId != Guid.Empty)
                {
                    if (metadatum.NodeUid != soapNodeId)
                    {
                        continue;
                    }
                }
                if (soapRelationshipId != Guid.Empty)
                {
                    if (metadatum.RelationshipUid != soapRelationshipId)
                    {
                        continue;
                    }
                }
                if (soapDescriptorType != null)
                {
                    if (metadatum.DescriptorTypeUid != soapDescriptorType.Id)
                    {
                        continue;
                    }
                }
                existingMetaData = true;
                if (metadatum.MetadataTypeUid != soapMetadataType.Id)
                {
                    //change in MetadataType
                     metadatum.MetadataType = mappingDb.MetadataTypes.Single(mdt => mdt.MetadataTypeUid == soapMetadataType.Id);
                }
                metadatum.MetadataValue = metadataValue;
                break;
            }
            if (!existingMetaData)
            {
                Metadata metadata = new Metadata();
                metadata.MetadataId = Guid.NewGuid();
                metadata.MetadataTypeUid = soapMetadataType.Id;

                if (soapNodeId != Guid.Empty)
                {
                    metadata.NodeUid = soapNodeId;
                }

                if (soapRelationshipId != Guid.Empty)
                {
                    metadata.RelationshipUid = soapRelationshipId;
                }

                if (soapDescriptorType != null)
                {
                    metadata.DescriptorTypeUid = soapDescriptorType.Id;
                }

                metadata.MetadataName = metadataName;
                metadata.MetadataValue = metadataValue;

                node.Metadatas.Add(metadata);
            }

            return soapMetadata;
        }
예제 #7
0
        public SoapNode UpdateNodeMetadata(Guid domainId, Guid soapNodeId, Guid soapRelationshipId, SoapDescriptorType soapDescriptorType, string metadataName, string metadataValue, SoapMetadataType soapMetadataType)
        {
            SoapNode soapNode = null;
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext())
                {
                    var nodes = from dbNode in mappingDb.Nodes where dbNode.DomainUid == domainId && dbNode.NodeUid == soapNodeId select dbNode;

                    var node = nodes.First();

                    SoapMetadata soapMetadata = UpdateMetadata(mappingDb, soapNodeId, soapRelationshipId, soapDescriptorType, metadataName, metadataValue, soapMetadataType, node);
                    soapNode = node.ToSoapObject();
                    mappingDb.SubmitChanges();
                }
            });
            return soapNode;
        }
예제 #8
0
        public bool RenameNodeMetadata(Guid domainId, Guid soapNodeId, Guid soapRelationshipId, SoapDescriptorType soapDescriptorType, string originalMetadataName, string newMetadataName)
        {
            bool success = false;
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (MappingToolDatabaseDataContext mappingDb = new MappingToolDatabaseDataContext())
                {
                    try
                    {
                        var nodes = from dbNode in mappingDb.Nodes where dbNode.DomainUid == domainId && dbNode.NodeUid == soapNodeId select dbNode;
                        Node node = nodes.Single();

                        foreach (Metadata metadatum in node.Metadatas.Where(x => x.MetadataName == originalMetadataName))
                        {
                            if (soapNodeId != Guid.Empty)
                            {
                                if (metadatum.NodeUid != soapNodeId)
                                {
                                    continue; //this should never happen since it's the node's metadata
                                }
                            }
                            if (soapRelationshipId != Guid.Empty)
                            {
                                if (metadatum.RelationshipUid != soapRelationshipId)
                                {
                                    continue;
                                }
                            }
                            if (soapDescriptorType != null)
                            {
                                if (metadatum.DescriptorTypeUid != soapDescriptorType.Id)
                                {
                                    continue;
                                }
                            }

                            //same context so we can rename it
                            metadatum.MetadataName = newMetadataName;
                            mappingDb.SubmitChanges();
                        }
                    }
                    catch (Exception ex)
                    {
                        LoggingService.WriteTrace(LoggingService.Categories.WcfServices, TraceSeverity.Unexpected,
                            "An error occurred renaming the metadata entry {0}, exception={1}", originalMetadataName, ex.Message);
                    }
                    finally
                    {
                        success = true;
                        LoggingService.WriteTrace(LoggingService.Categories.WcfServices, TraceSeverity.Verbose, 
                            "Metadata property on Node with Id: {0} with name: {1} was renamed to: {2}", 
                            soapNodeId.ToString(), originalMetadataName, newMetadataName);
                    }
                }
            });
            return success;
        }