Esempio n. 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();
            }
        }
        //-------------------------------------
        // Production helper methods.

        ///////////////////////////////////////////////////////////////////////////////
        // Description: Adds the Album Art part to the package and creates a package relationship to that has the Album Art part as its target.
        ///////////////////////////////////////////////////////////////////////////////
        private static void AddAlbumArtToBundle(IOpcFactory opcFactory,
                                                IOpcPartSet packagePartSet,                 // Represents the set of parts (excluding Relationships parts) in a package.
                                                IOpcRelationshipSet packageRelationshipSet, // Represents the Relationships part that stores package relationships.
                                                string inputDirectory                       // Directory location of the files specified in trackName and lyricsName.
                                                )
        {
            // Add Album Art part.
            AddPartToBundle(opcFactory, g_albumArt, packagePartSet, g_albumArtContentType, OPC_COMPRESSION_OPTIONS.OPC_COMPRESSION_NONE, inputDirectory, out IOpcPartUri albumArtPartUri, out _);

            // Add a package relationship that has the Album Art part as its target.
            packageRelationshipSet.CreateRelationship(default,                                           // Use auto-generated relationship ID.
Esempio n. 3
0
        public void LoadTest()
        {
            Assert.That(factory.CreateStreamOnFile(TestCaseSources.WordDoc, OPC_STREAM_IO_MODE.OPC_STREAM_IO_READ, null, 0, out var sourceFileStream), ResultIs.Successful);
            using var psourceFileString = ComReleaserFactory.Create(sourceFileStream);

            Assert.That(factory.ReadPackageFromStream(sourceFileStream, OPC_READ_FLAGS.OPC_CACHE_ON_ACCESS, out var outPackage), ResultIs.Successful);
            using var poutPackage = ComReleaserFactory.Create(outPackage);

            IOpcPartSet pset = null;

            Assert.That(() => pset = outPackage.GetPartSet(), Throws.Nothing);
            using var ppset        = ComReleaserFactory.Create(pset);

            IOpcPartEnumerator penum = null;

            Assert.That(() => penum = pset.GetEnumerator(), Throws.Nothing);
            using var ppenum        = new OpcEnumerator <IOpcPartEnumerator, IOpcPart>(penum);

            while (ppenum.MoveNext())
            {
                TestContext.WriteLine($"{ppenum.Current.GetContentType()}, {ppenum.Current.GetCompressionOptions()}");
            }
            TestContext.WriteLine();

            IOpcRelationshipSet rset = null;

            Assert.That(() => rset = outPackage.GetRelationshipSet(), Throws.Nothing);
            using var prset        = ComReleaserFactory.Create(rset);

            IOpcRelationshipEnumerator renum = null;

            Assert.That(() => renum = rset.GetEnumerator(), Throws.Nothing);
            using var prenum        = new OpcEnumerator <IOpcRelationshipEnumerator, IOpcRelationship>(renum);

            while (prenum.MoveNext())
            {
                TestContext.WriteLine($"{prenum.Current.GetId()}, {prenum.Current.GetRelationshipType()}, {prenum.Current.GetTargetMode()}");
            }
            TestContext.WriteLine();
        }