Beispiel #1
0
        private void diagramXmlParseBodySpecific(string xmlFilePath, TreeNode treeNode, XmlNode body, string diagramElementName)
        {
            string localName = DiagramContentModelHelper.StripNSPrefix(diagramElementName);

            foreach (XmlNode diagramElementNode in XmlDocumentHelper.GetChildrenElementsOrSelfWithName(body, false, localName, DiagramContentModelHelper.NS_URL_DIAGRAM, false))
            {
                if (diagramElementNode.NodeType != XmlNodeType.Element || diagramElementNode.LocalName != localName)
                {
#if DEBUG
                    Debugger.Break();
#endif
                    // DEBUG
                    continue;
                }

                diagramXmlParseBody_(diagramElementNode, xmlFilePath, treeNode, 0);
            }
        }
Beispiel #2
0
        private void diagramXmlParseBody_(XmlNode diagramElementNode, string xmlFilePath, TreeNode treeNode, int objectIndex)
        {
            string diagramElementName = diagramElementNode.Name;

            AlternateContent           altContent     = treeNode.Presentation.AlternateContentFactory.CreateAlternateContent();
            AlternateContentAddCommand cmd_AltContent =
                treeNode.Presentation.CommandFactory.CreateAlternateContentAddCommand(treeNode, altContent);

            treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent);



            Metadata diagramElementName_Metadata = treeNode.Presentation.MetadataFactory.CreateMetadata();

            diagramElementName_Metadata.NameContentAttribute              = new MetadataAttribute();
            diagramElementName_Metadata.NameContentAttribute.Name         = DiagramContentModelHelper.DiagramElementName;
            diagramElementName_Metadata.NameContentAttribute.NamespaceUri = null;
            diagramElementName_Metadata.NameContentAttribute.Value        = diagramElementName;
            AlternateContentMetadataAddCommand cmd_AltContent_diagramElementName_Metadata =
                treeNode.Presentation.CommandFactory.CreateAlternateContentMetadataAddCommand(
                    treeNode,
                    null,
                    altContent,
                    diagramElementName_Metadata,
                    null
                    );

            treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent_diagramElementName_Metadata);


            if (diagramElementNode.Attributes != null)
            {
                for (int i = 0; i < diagramElementNode.Attributes.Count; i++)
                {
                    XmlAttribute attribute = diagramElementNode.Attributes[i];


                    if (attribute.Name.StartsWith(XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":"))
                    {
                        //
                    }
                    else if (attribute.Name == XmlReaderWriterHelper.NS_PREFIX_XMLNS)
                    {
                        //
                    }
                    else if (attribute.Name == DiagramContentModelHelper.TOBI_Audio)
                    {
                        string fullPath = null;
                        if (FileDataProvider.isHTTPFile(attribute.Value))
                        {
                            fullPath = FileDataProvider.EnsureLocalFilePathDownloadTempDirectory(attribute.Value);
                        }
                        else
                        {
                            fullPath = Path.Combine(Path.GetDirectoryName(xmlFilePath), attribute.Value);
                        }
                        if (fullPath != null && File.Exists(fullPath))
                        {
                            string extension = Path.GetExtension(fullPath);

                            bool isWav = extension.Equals(DataProviderFactory.AUDIO_WAV_EXTENSION, StringComparison.OrdinalIgnoreCase);

                            AudioLibPCMFormat wavFormat = null;
                            if (isWav)
                            {
                                Stream fileStream = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                                try
                                {
                                    uint dataLength;
                                    wavFormat = AudioLibPCMFormat.RiffHeaderParse(fileStream, out dataLength);
                                }
                                finally
                                {
                                    fileStream.Close();
                                }
                            }
                            string originalFilePath = null;

                            DebugFix.Assert(treeNode.Presentation.MediaDataManager.EnforceSinglePCMFormat);

                            bool wavNeedsConversion = false;
                            if (wavFormat != null)
                            {
                                wavNeedsConversion = !wavFormat.IsCompatibleWith(treeNode.Presentation.MediaDataManager.DefaultPCMFormat.Data);
                            }
                            if (!isWav || wavNeedsConversion)
                            {
                                originalFilePath = fullPath;

                                var audioFormatConvertorSession =
                                    new AudioFormatConvertorSession(
                                        //AudioFormatConvertorSession.TEMP_AUDIO_DIRECTORY,
                                        treeNode.Presentation.DataProviderManager.DataFileDirectoryFullPath,
                                        treeNode.Presentation.MediaDataManager.DefaultPCMFormat,
                                        false,
                                        m_UrakawaSession.IsAcmCodecsDisabled);

                                //filePath = m_AudioFormatConvertorSession.ConvertAudioFileFormat(filePath);

                                bool cancelled = false;

                                var converter = new AudioClipConverter(audioFormatConvertorSession, fullPath);

                                bool error = ShellView.RunModalCancellableProgressTask(true,
                                                                                       "Converting audio...",
                                                                                       converter,
                                                                                       () =>
                                {
                                    m_Logger.Log(@"Audio conversion CANCELLED", Category.Debug, Priority.Medium);
                                    cancelled = true;
                                },
                                                                                       () =>
                                {
                                    m_Logger.Log(@"Audio conversion DONE", Category.Debug, Priority.Medium);
                                    cancelled = false;
                                });

                                if (cancelled)
                                {
                                    //DebugFix.Assert(!result);
                                    break;
                                }

                                fullPath = converter.ConvertedFilePath;
                                if (string.IsNullOrEmpty(fullPath))
                                {
                                    break;
                                }

                                m_Logger.Log(string.Format("Converted audio {0} to {1}", originalFilePath, fullPath),
                                             Category.Debug, Priority.Medium);

                                //Stream fileStream = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read);
                                //try
                                //{
                                //    uint dataLength;
                                //    wavFormat = AudioLibPCMFormat.RiffHeaderParse(fileStream, out dataLength);
                                //}
                                //finally
                                //{
                                //    fileStream.Close();
                                //}
                            }


                            ManagedAudioMedia manAudioMedia  = treeNode.Presentation.MediaFactory.CreateManagedAudioMedia();
                            AudioMediaData    audioMediaData = treeNode.Presentation.MediaDataFactory.CreateAudioMediaData(DataProviderFactory.AUDIO_WAV_EXTENSION);
                            manAudioMedia.AudioMediaData = audioMediaData;

                            FileDataProvider dataProv = (FileDataProvider)treeNode.Presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE);
                            dataProv.InitByCopyingExistingFile(fullPath);
                            audioMediaData.AppendPcmData(dataProv);

                            //                            Stream wavStream = null;
                            //                            try
                            //                            {
                            //                                wavStream = File.Open(fullPath, FileMode.Open, FileAccess.Read, FileShare.Read);

                            //                                uint dataLength;
                            //                                AudioLibPCMFormat pcmInfo = AudioLibPCMFormat.RiffHeaderParse(wavStream, out dataLength);

                            //                                if (!treeNode.Presentation.MediaDataManager.DefaultPCMFormat.Data.IsCompatibleWith(pcmInfo))
                            //                                {
                            //#if DEBUG
                            //                                    Debugger.Break();
                            //#endif //DEBUG
                            //                                    wavStream.Close();
                            //                                    wavStream = null;

                            //                                    var audioFormatConvertorSession =
                            //                                        new AudioFormatConvertorSession(
                            //                                        //AudioFormatConvertorSession.TEMP_AUDIO_DIRECTORY,
                            //                                        treeNode.Presentation.DataProviderManager.DataFileDirectoryFullPath,
                            //                                    treeNode.Presentation.MediaDataManager.DefaultPCMFormat, m_UrakawaSession.IsAcmCodecsDisabled);

                            //                                    string newfullWavPath = audioFormatConvertorSession.ConvertAudioFileFormat(fullPath);

                            //                                    FileDataProvider dataProv = (FileDataProvider)treeNode.Presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE);
                            //                                    dataProv.InitByMovingExistingFile(newfullWavPath);
                            //                                    audioMediaData.AppendPcmData(dataProv);
                            //                                }
                            //                                else // use original wav file by copying it to data directory
                            //                                {
                            //                                    FileDataProvider dataProv = (FileDataProvider)treeNode.Presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE);
                            //                                    dataProv.InitByCopyingExistingFile(fullPath);
                            //                                    audioMediaData.AppendPcmData(dataProv);
                            //                                }
                            //                            }
                            //                            finally
                            //                            {
                            //                                if (wavStream != null) wavStream.Close();
                            //                            }



                            AlternateContentSetManagedMediaCommand cmd_AltContent_diagramElement_Audio =
                                treeNode.Presentation.CommandFactory.CreateAlternateContentSetManagedMediaCommand(treeNode, altContent, manAudioMedia);
                            treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent_diagramElement_Audio);

                            //SetDescriptionAudio(altContent, audio, treeNode);
                        }
                    }
                    else
                    {
                        Metadata diagramElementAttribute_Metadata = treeNode.Presentation.MetadataFactory.CreateMetadata();
                        diagramElementAttribute_Metadata.NameContentAttribute              = new MetadataAttribute();
                        diagramElementAttribute_Metadata.NameContentAttribute.Name         = attribute.Name;
                        diagramElementAttribute_Metadata.NameContentAttribute.NamespaceUri = attribute.NamespaceURI;
                        diagramElementAttribute_Metadata.NameContentAttribute.Value        = attribute.Value;
                        AlternateContentMetadataAddCommand cmd_AltContent_diagramElementAttribute_Metadata =
                            treeNode.Presentation.CommandFactory.CreateAlternateContentMetadataAddCommand(
                                treeNode,
                                null,
                                altContent,
                                diagramElementAttribute_Metadata,
                                null
                                );
                        treeNode.Presentation.UndoRedoManager.Execute(
                            cmd_AltContent_diagramElementAttribute_Metadata);
                    }
                }
            }

            int nObjects = -1;

            XmlNode textNode = diagramElementNode;

            if (diagramElementName == DiagramContentModelHelper.D_SimplifiedImage ||
                diagramElementName == DiagramContentModelHelper.D_Tactile)
            {
                string  localTourName = DiagramContentModelHelper.StripNSPrefix(DiagramContentModelHelper.D_Tour);
                XmlNode tour          =
                    XmlDocumentHelper.GetFirstChildElementOrSelfWithName(diagramElementNode, false,
                                                                         localTourName,
                                                                         DiagramContentModelHelper.NS_URL_DIAGRAM);
                textNode = tour;

                IEnumerable <XmlNode> objects = XmlDocumentHelper.GetChildrenElementsOrSelfWithName(diagramElementNode, false,
                                                                                                    DiagramContentModelHelper.
                                                                                                    Object,
                                                                                                    DiagramContentModelHelper.
                                                                                                    NS_URL_ZAI, false);
                nObjects = 0;
                foreach (XmlNode obj in objects)
                {
                    nObjects++;
                }

                int i = -1;
                foreach (XmlNode obj in objects)
                {
                    i++;
                    if (i != objectIndex)
                    {
                        continue;
                    }

                    if (obj.Attributes == null || obj.Attributes.Count <= 0)
                    {
                        break;
                    }

                    for (int j = 0; j < obj.Attributes.Count; j++)
                    {
                        XmlAttribute attribute = obj.Attributes[j];


                        if (attribute.Name.StartsWith(XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":"))
                        {
                            //
                        }
                        else if (attribute.Name == XmlReaderWriterHelper.NS_PREFIX_XMLNS)
                        {
                            //
                        }
                        else if (attribute.Name == DiagramContentModelHelper.Src)
                        {
                            //
                        }
                        else if (attribute.Name == DiagramContentModelHelper.SrcType)
                        {
                            //
                        }
                        else
                        {
                            Metadata diagramElementAttribute_Metadata = treeNode.Presentation.MetadataFactory.CreateMetadata();
                            diagramElementAttribute_Metadata.NameContentAttribute              = new MetadataAttribute();
                            diagramElementAttribute_Metadata.NameContentAttribute.Name         = attribute.Name;
                            diagramElementAttribute_Metadata.NameContentAttribute.NamespaceUri = attribute.NamespaceURI;
                            diagramElementAttribute_Metadata.NameContentAttribute.Value        = attribute.Value;
                            AlternateContentMetadataAddCommand cmd_AltContent_diagramElementAttribute_Metadata =
                                treeNode.Presentation.CommandFactory.CreateAlternateContentMetadataAddCommand(
                                    treeNode,
                                    null,
                                    altContent,
                                    diagramElementAttribute_Metadata,
                                    null
                                    );
                            treeNode.Presentation.UndoRedoManager.Execute(
                                cmd_AltContent_diagramElementAttribute_Metadata);
                        }
                    }

                    XmlAttribute srcAttr = (XmlAttribute)obj.Attributes.GetNamedItem(DiagramContentModelHelper.Src);
                    if (srcAttr != null)
                    {
                        XmlAttribute srcType =
                            (XmlAttribute)obj.Attributes.GetNamedItem(DiagramContentModelHelper.SrcType);

                        ManagedImageMedia img = treeNode.Presentation.MediaFactory.CreateManagedImageMedia();

                        string imgFullPath = null;
                        if (FileDataProvider.isHTTPFile(srcAttr.Value))
                        {
                            imgFullPath = FileDataProvider.EnsureLocalFilePathDownloadTempDirectory(srcAttr.Value);
                        }
                        else
                        {
                            imgFullPath = Path.Combine(Path.GetDirectoryName(xmlFilePath), srcAttr.Value);
                        }
                        if (imgFullPath != null && File.Exists(imgFullPath))
                        {
                            string extension = Path.GetExtension(imgFullPath);

                            ImageMediaData imgData = treeNode.Presentation.MediaDataFactory.CreateImageMediaData(extension);
                            if (imgData != null)
                            {
                                imgData.InitializeImage(imgFullPath, Path.GetFileName(imgFullPath));
                                img.ImageMediaData = imgData;

                                AlternateContentSetManagedMediaCommand cmd_AltContent_Image =
                                    treeNode.Presentation.CommandFactory.CreateAlternateContentSetManagedMediaCommand(
                                        treeNode, altContent, img);
                                treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent_Image);
                            }
                        }
                    }
                }
            }

            if (textNode != null)
            {
                string strText = textNode.InnerXml;

                if (!string.IsNullOrEmpty(strText))
                {
                    strText = strText.Trim();
                    strText = Regex.Replace(strText, @"\s+", " ");
                    strText = strText.Replace("\r\n", "\n");
                }

                if (!string.IsNullOrEmpty(strText))
                {
                    TextMedia txtMedia = treeNode.Presentation.MediaFactory.CreateTextMedia();
                    txtMedia.Text = strText;
                    AlternateContentSetManagedMediaCommand cmd_AltContent_Text =
                        treeNode.Presentation.CommandFactory.CreateAlternateContentSetManagedMediaCommand(treeNode,
                                                                                                          altContent,
                                                                                                          txtMedia);
                    treeNode.Presentation.UndoRedoManager.Execute(cmd_AltContent_Text);
                }
            }

            if (nObjects > 0 && ++objectIndex <= nObjects - 1)
            {
                diagramXmlParseBody_(diagramElementNode, xmlFilePath, treeNode, objectIndex);
            }
        }
Beispiel #3
0
        private static XmlNode addFlatDiagramHeadMetadata(
            MetadataAttribute metaAttr, IEnumerable <MetadataAttribute> metaAttrs,
            XmlNode parentNode, XmlDocument descriptionDocument, XmlNode descriptionNode)
        {
            XmlNode metaNode = descriptionDocument.CreateElement(
                DiagramContentModelHelper.StripNSPrefix(DiagramContentModelHelper.Meta),
                DiagramContentModelHelper.NS_URL_ZAI);

            parentNode.AppendChild(metaNode);

            if (metaAttr != null)
            {
                if (metaAttr.Name != DiagramContentModelHelper.NA)
                {
                    XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, metaNode,
                                                               DiagramContentModelHelper.Property,
                                                               metaAttr.Name,
                                                               DiagramContentModelHelper.NS_URL_ZAI);
                }

                if (metaAttr.Value != DiagramContentModelHelper.NA)
                {
                    // TODO: INNER_TEXT vs CONTENT_ATTR => is this specified anywhere?
                    if (
                        DiagramContentModelHelper.DIAGRAM_Purpose.Equals(metaAttr.Name, StringComparison.OrdinalIgnoreCase) ||
                        DiagramContentModelHelper.DIAGRAM_Credentials.Equals(metaAttr.Name, StringComparison.OrdinalIgnoreCase) ||
                        SupportedMetadata_Z39862005.DC_AccessRights.Equals(metaAttr.Name, StringComparison.OrdinalIgnoreCase)
                        //
                        || SupportedMetadata_Z39862005.DC_Creator.Equals(metaAttr.Name, StringComparison.OrdinalIgnoreCase) ||
                        SupportedMetadata_Z39862005.DC_Description.Equals(metaAttr.Name, StringComparison.OrdinalIgnoreCase) ||
                        SupportedMetadata_Z39862005.DC_Title.Equals(metaAttr.Name, StringComparison.OrdinalIgnoreCase) ||
                        SupportedMetadata_Z39862005.DC_Subject.Equals(metaAttr.Name, StringComparison.OrdinalIgnoreCase)
                        )
                    {
                        metaNode.InnerText = metaAttr.Value;
                    }
                    else
                    {
                        XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, metaNode,
                                                                   DiagramContentModelHelper.Content,
                                                                   metaAttr.Value,
                                                                   DiagramContentModelHelper.NS_URL_ZAI);
                    }
                }
            }

            if (metaAttrs != null)
            {
                foreach (MetadataAttribute metaAttribute in metaAttrs)
                {
                    if (metaAttribute.Name == Metadata.PrimaryIdentifierMark)
                    {
                        continue;
                    }

                    if (metaAttribute.Name.StartsWith(XmlReaderWriterHelper.NS_PREFIX_XML + ":"))
                    {
                        XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, metaNode,
                                                                   metaAttribute.Name,
                                                                   metaAttribute.Value,
                                                                   XmlReaderWriterHelper.NS_URL_XML);
                    }
                    else if (metaAttribute.Name.StartsWith(DiagramContentModelHelper.NS_PREFIX_ZAI + ":"))
                    {
                        XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, metaNode,
                                                                   metaAttribute.Name,
                                                                   metaAttribute.Value,
                                                                   DiagramContentModelHelper.NS_URL_ZAI);
                    }
                    else if (metaAttribute.Name.StartsWith(DiagramContentModelHelper.NS_PREFIX_DIAGRAM + ":"))
                    {
                        XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, metaNode,
                                                                   metaAttribute.Name,
                                                                   metaAttribute.Value,
                                                                   DiagramContentModelHelper.NS_URL_DIAGRAM);
                    }
                    else if (DiagramContentModelHelper.Rel.Equals(metaAttribute.Name, StringComparison.OrdinalIgnoreCase) ||
                             DiagramContentModelHelper.Resource.Equals(metaAttribute.Name, StringComparison.OrdinalIgnoreCase) ||
                             DiagramContentModelHelper.About.Equals(metaAttribute.Name, StringComparison.OrdinalIgnoreCase))
                    {
                        XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, metaNode,
                                                                   metaAttribute.Name.ToLower(),
                                                                   metaAttribute.Value,
                                                                   DiagramContentModelHelper.NS_URL_ZAI);
                    }
                    else
                    {
                        XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, metaNode,
                                                                   DiagramContentModelHelper.StripNSPrefix(metaAttribute.Name),
                                                                   metaAttribute.Value,
                                                                   descriptionNode.NamespaceURI);
                    }
                }
            }

            return(metaNode);
        }
        public static string CreateImageDescription(
            bool skipACM,
            AudioLibPCMFormat pcmFormat,
            bool encodeToMp3,
            double bitRate_Mp3,
            string imageDescriptionDirectoryPath,
            string imageSRC,
            AlternateContentProperty altProperty,
            Dictionary <string, List <string> > map_DiagramElementName_TO_TextualDescriptions,
            Dictionary <AlternateContentProperty, Description> map_AltProperty_TO_Description,
            Dictionary <AlternateContent, string> map_AltContentAudio_TO_RelativeExportedFilePath
            )
        {
#if DEBUG
            DebugFix.Assert(!altProperty.IsEmpty);
#endif //DEBUG

            XmlDocument descriptionDocument = new XmlDocument();

            //m_AltProperrty_DiagramDocument.Add(altProperty, descriptionDocument);

            // <?xml-stylesheet type="text/xsl" href="desc2html.xsl"?>
            //string processingInstructionData = "type=\"text/xsl\" href=\"desc2html.xsl\"";
            //descriptionDocument.AppendChild(descriptionDocument.CreateProcessingInstruction("xml-stylesheet", processingInstructionData));
            //string xsltFileName = "desc2html.xsl";
            //string sourceXsltPath = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, xsltFileName);
            //string destXsltPath = Path.Combine(imageDescriptionDirectoryPath, xsltFileName);
            //if (!File.Exists(destXsltPath)) File.Copy(sourceXsltPath, destXsltPath);

            XmlNode descriptionNode = descriptionDocument.CreateElement(
                DiagramContentModelHelper.NS_PREFIX_DIAGRAM,
                DiagramContentModelHelper.StripNSPrefix(DiagramContentModelHelper.D_Description),
                DiagramContentModelHelper.NS_URL_DIAGRAM);

            XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, descriptionNode,
                                                       XmlReaderWriterHelper.NS_PREFIX_XMLNS,
                                                       DiagramContentModelHelper.NS_URL_ZAI);
            descriptionDocument.AppendChild(descriptionNode);

            XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, descriptionNode,
                                                       XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DIAGRAM,
                                                       DiagramContentModelHelper.NS_URL_DIAGRAM);

            XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, descriptionNode,
                                                       XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DIAGRAM_METADATA,
                                                       DiagramContentModelHelper.NS_URL_DIAGRAM);

            XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, descriptionNode,
                                                       XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DC,
                                                       DiagramContentModelHelper.NS_URL_DC);

            XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, descriptionNode,
                                                       XmlReaderWriterHelper.NS_PREFIX_XMLNS + ":" + DiagramContentModelHelper.NS_PREFIX_DCTERMS,
                                                       DiagramContentModelHelper.NS_URL_DCTERMS);

            createDiagramHeadMetadata(descriptionDocument, descriptionNode, altProperty);

            createDiagramBodyContent(skipACM, descriptionDocument, descriptionNode,
                                     altProperty, map_DiagramElementName_TO_TextualDescriptions,
                                     imageDescriptionDirectoryPath,
                                     map_AltProperty_TO_Description, encodeToMp3, bitRate_Mp3, pcmFormat,
                                     map_AltContentAudio_TO_RelativeExportedFilePath);

            string descFileName = Path.GetFileNameWithoutExtension(imageSRC) + IMAGE_DESCRIPTION_XML_SUFFIX + DataProviderFactory.XML_EXTENSION;
            XmlReaderWriterHelper.WriteXmlDocument(descriptionDocument, Path.Combine(imageDescriptionDirectoryPath, descFileName), null);

            string        relativePath = Path.GetFileName(imageDescriptionDirectoryPath);
            DirectoryInfo d            = new DirectoryInfo(imageDescriptionDirectoryPath);
            DebugFix.Assert(relativePath == d.Name);

            return(Path.Combine(relativePath, descFileName));
        }
Beispiel #5
0
        private static void createDiagramHeadMetadata(XmlDocument descriptionDocument, XmlNode descriptionNode, AlternateContentProperty altProperty)
        {
            XmlNode headNode = descriptionDocument.CreateElement(
                DiagramContentModelHelper.NS_PREFIX_DIAGRAM,
                DiagramContentModelHelper.StripNSPrefix(DiagramContentModelHelper.D_Head),
                DiagramContentModelHelper.NS_URL_DIAGRAM);

            descriptionNode.AppendChild(headNode);

            //TODO: ALWAYS DISABLE THE DEBUG CODE BELOW UNLESS NEEDED FOR TESTING!!
#if false && DEBUG
            foreach (Metadata md in altProperty.Metadatas.ContentsAs_Enumerable)
            {
                addFlatDiagramHeadMetadata(
                    md.NameContentAttribute, md.OtherAttributes.ContentsAs_Enumerable,
                    headNode, descriptionDocument, descriptionNode);
            }
#endif // DEBUG

            List <Metadata> flatMetadatas = new List <Metadata>();
            Dictionary <string, List <Metadata> > groupedMetadata_Id          = new Dictionary <string, List <Metadata> >();
            Dictionary <string, List <Metadata> > groupedMetadata_RelResource = new Dictionary <string, List <Metadata> >();

            foreach (Metadata md in altProperty.Metadatas.ContentsAs_Enumerable)
            {
                if (md.NameContentAttribute == null)
                {
#if DEBUG
                    Debugger.Break();
#endif // DEBUG
                    continue;
                }

                if (
                    md.NameContentAttribute.Name.StartsWith(XmlReaderWriterHelper.NS_PREFIX_XML + ":")

                    //&& (md.OtherAttributes == null || md.OtherAttributes.Count == 0)

                    && (descriptionNode.Attributes == null || descriptionNode.Attributes.GetNamedItem(md.NameContentAttribute.Name) == null))
                {
                    XmlDocumentHelper.CreateAppendXmlAttribute(descriptionDocument, descriptionNode,
                                                               md.NameContentAttribute.Name,
                                                               md.NameContentAttribute.Value,
                                                               XmlReaderWriterHelper.NS_URL_XML);
                }
                else
                {
                    if (md.OtherAttributes != null && md.OtherAttributes.Count > 0)
                    {
                        MetadataAttribute mdAttr_Rel      = null;
                        MetadataAttribute mdAttr_Resource = null;
                        MetadataAttribute mdAttr_Id       = null;
                        bool hasOtherAttrs = false;
                        foreach (MetadataAttribute mdAttr in md.OtherAttributes.ContentsAs_Enumerable)
                        {
                            if (mdAttr.Name == Metadata.PrimaryIdentifierMark)
                            {
                                continue;
                            }

                            if (mdAttr.Name == DiagramContentModelHelper.Rel)
                            {
                                mdAttr_Rel = mdAttr;
                                continue;
                            }
                            if (mdAttr.Name == DiagramContentModelHelper.Resource)
                            {
                                mdAttr_Resource = mdAttr;
                                continue;
                            }
                            if (mdAttr.Name == XmlReaderWriterHelper.XmlId)
                            {
                                mdAttr_Id = mdAttr;
                                continue;
                            }

                            hasOtherAttrs = true;
                        }

                        if (mdAttr_Id != null)
                        {
                            addDic_(groupedMetadata_Id, mdAttr_Id.Value, md);

                            continue;
                        }
                        else if (mdAttr_Rel != null || mdAttr_Resource != null)
                        {
                            string key = (mdAttr_Rel != null ? mdAttr_Rel.Value : "")
                                         + "_-_"
                                         + (mdAttr_Resource != null ? mdAttr_Resource.Value : "");
                            addDic_(groupedMetadata_RelResource, key, md);

                            continue;
                        }
                    }

                    //md.NameContentAttribute.Name != DiagramContentModelHelper.NA
                    //    && md.NameContentAttribute.Value != DiagramContentModelHelper.NA

                    flatMetadatas.Add(md);
                }
            }

            foreach (Metadata md in flatMetadatas)
            {
                addFlatDiagramHeadMetadata(
                    md.NameContentAttribute, md.OtherAttributes.ContentsAs_Enumerable,
                    headNode, descriptionDocument, descriptionNode);
            }

            handleMetadataGroup(headNode, descriptionDocument, descriptionNode, groupedMetadata_Id);
            handleMetadataGroup(headNode, descriptionDocument, descriptionNode, groupedMetadata_RelResource);
        }