Example #1
0
        ///////////////////////////////////////////////////////////////////////////////
        // Description: Gets the target part of a relationship with the 'Internal' target mode.
        ///////////////////////////////////////////////////////////////////////////////
        private static void GetRelationshipTargetPart(IOpcPartSet partSet,           // Set of the parts in the package.
                                                      IOpcRelationship relationship, // Relationship that targets the required part.
                                                      string expectedContentType,    // Content type expected for the target part.
                                                      out IOpcPart targetPart        // Recieves pointer to target part. Method may return a valid
                                                                                     // pointer even on failure, and the caller must always release if a non-default value is returned.
                                                      )
        {
            targetPart = null;

            OPC_URI_TARGET_MODE targetMode = relationship.GetTargetMode();

            if (targetMode != OPC_URI_TARGET_MODE.OPC_URI_TARGET_MODE_INTERNAL)
            {
                // The relationship's target is not a part.
                var relationshipType = relationship.GetRelationshipType();

                Console.Error.Write("Invalid music bundle package: relationship with type {0} must have Internal target mode.\n", relationshipType);

                // Set the return code to an error.
                throw new InvalidOperationException();
            }

            // Relationship's target is a part; the target mode is 'Internal'.

            // Get the URI of the relationship source.
            IOpcUri sourceUri = relationship.GetSourceUri();

            // Get the URI of the relationship target.
            IUri targetUri = relationship.GetTargetUri();

            // Resolve the target URI to the part name of the target part.
            IOpcPartUri targetPartUri = sourceUri.CombinePartUri(targetUri);

            // Check that a part with the resolved part name exists in the part set.
            var partExists = partSet.PartExists(targetPartUri);

            if (!partExists)
            {
                // The part does not exist in the part set.
                Console.Error.Write("Invalid music bundle package: the target part of relationship does not exist.\n");

                // Set the return code to an error.
                throw new InvalidOperationException();
            }

            // Get the part.
            targetPart = partSet.GetPart(targetPartUri);

            // Get the content type of the part.
            var contentType = targetPart.GetContentType();

            if (contentType != expectedContentType)
            {
                // Content type of the part did not match the expected content type.
                Console.Error.Write("Invalid music bundle package: the target part does not have correct content type.\n");

                // Set the return code to an error.
                throw new InvalidOperationException();
            }
        }
Example #2
0
        public void RootTest()
        {
            IOpcUri rootUri = null;

            Assert.That(() => rootUri = factory.CreatePackageRootUri(), Throws.Nothing);
            Assert.That(rootUri, Is.Not.Null);
            Marshal.ReleaseComObject(rootUri);
        }