Esempio n. 1
0
        public static void MoveStruct(this BitmapMetadata bitmapMetadata, string sourceNameSpace, string sourceStructName, string destinationNameSpace, string destinationStructName, bool overWriteExistingData, bool ignoreInvalidSource)
        {
            // Rewrite Structnames
            string sourceStruct = @"/xmp/" + sourceNameSpace + sourceStructName;
            string sourceQuery  = sourceStruct + "/" + sourceNameSpace;

            string destinationStruct = @"/xmp/" + destinationNameSpace + destinationStructName;
            string destinationQuery  = destinationStruct + "/" + destinationNameSpace;

            // Check Source exists
            bool sourceExists = bitmapMetadata.ContainsQuery(sourceStruct);

            if (sourceExists)
            {
                // Create a new Struct, if it doesn't exist
                if (!bitmapMetadata.ContainsQuery(destinationStruct))
                {
                    bitmapMetadata.SetQuery(destinationStruct, new BitmapMetadata("xmpstruct"));
                }

                List <string> sourceSubQueries = bitmapMetadata.GetSubQueries(sourceStruct);

                // Loop through all data in the struct
                foreach (string sourceProperty in sourceSubQueries)
                {
                    // Construct the full query
                    string destinationProperty = sourceProperty.Replace(sourceQuery, destinationQuery);

                    bitmapMetadata.MoveQuery(sourceProperty, destinationProperty, overWriteExistingData);
                }

                // Remove the old struct
                bitmapMetadata.RemoveQuery(sourceStruct);

                // Get Destination Queries
                List <string> destinationSubQueries = bitmapMetadata.GetSubQueries(destinationStruct);

                // Check the destination has at least as many subqueries as the source
                if (destinationSubQueries.Count < sourceSubQueries.Count)
                {
                    throw new Exception("Source Struct was not fully moved to Destination");
                }
            }
            else if (!sourceExists && !ignoreInvalidSource)
            {
                throw new Exception("Source Struct does not exist:" + sourceStruct);
            }
        }