//-------------------------------------
        // 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.
Example #2
0
        ///////////////////////////////////////////////////////////////////////////////
        // Description: Gets the relationship of the specified type from a specified relationship set.
        // Note: Method expects exactly one relationship of the specified type. This limitation is described in the Music Bundle Package
        // specification--and is not imposed by the Packaging APIs or the OPC.
        ///////////////////////////////////////////////////////////////////////////////
        private static void GetRelationshipByType(IOpcRelationshipSet relsSet,            // Relationship set that contains the relationship.
                                                  string relationshipType,                // The relationship type of the relationship.
                                                  out IOpcRelationship targetRelationship // Recieves the relationship. Method may return a valid
                                                                                          // pointer even on failure, and the caller must always release if a non-default value is returned.
                                                  )
        {
            targetRelationship = null;
            HRESULT hr = HRESULT.S_OK;

            // Get an enumerator of all relationships of the required type.
            IOpcRelationshipEnumerator relsEnumerator = relsSet.GetEnumeratorForType(relationshipType);

            // Enumerate through relationships, ensuring that there is exactly one relationship that has the specified type.
            var count = 0;

            while (hr.Succeeded && (hr = relsEnumerator.MoveNext(out var hasNext)).Succeeded && hasNext)
            {
                count++;

                if (count > 1)
                {
                    // There is more than one relationship of the specified type.
                    Console.Error.Write("Invalid music bundle package: cannot have more than 1 relationship with type: {0}.\n", relationshipType);

                    // Set the return code to an error.
                    hr = HRESULT.E_FAIL;

                    // An error was encountered; stop enumerating.
                    break;
                }

                if (hr.Succeeded)
                {
                    // Get the relationship at the current position of the enumerator.
                    hr = relsEnumerator.GetCurrent(out targetRelationship);
                }
            }

            if (hr.Succeeded)
            {
                if (count == 0)
                {
                    // There were no relationships in the set that had the specified type.
                    Console.Error.Write("Invalid music bundle package: relationship with type {0} does not exist.\n", relationshipType);

                    throw new InvalidOperationException();
                }
            }
            else
            {
                throw new InvalidOperationException();
            }
        }
Example #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();
        }