public void TryToSetNullProperty() { urakawa.core.TreeNode root = mProject.Presentations.Get(0).RootNode; if (root != null) { try { root.AddProperty(null); } catch (exception.MethodParameterIsNullException) { return; } Assert.Fail("Expected MethodParameterIsNullException"); } }
private void parseDTBookXmlDocAndPopulateDataModel(XmlNode xmlNode, core.TreeNode parentTreeNode) { XmlNodeType xmlType = xmlNode.NodeType; switch (xmlType) { case XmlNodeType.Attribute: { System.Diagnostics.Debug.Fail("Calling this method with an XmlAttribute should never happen !!"); break; } case XmlNodeType.Document: { parseDTBookXmlDocAndPopulateDataModel(((XmlDocument)xmlNode).DocumentElement, parentTreeNode); break; } case XmlNodeType.Element: { Presentation presentation = m_Project.GetPresentation(0); core.TreeNode treeNode = presentation.TreeNodeFactory.Create(); if (parentTreeNode == null) { presentation.RootNode = treeNode; parentTreeNode = presentation.RootNode; } else { parentTreeNode.AppendChild(treeNode); } XmlProperty xmlProp = presentation.PropertyFactory.CreateXmlProperty(); treeNode.AddProperty(xmlProp); xmlProp.LocalName = xmlNode.Name; if (xmlNode.ParentNode != null && xmlNode.ParentNode.NodeType == XmlNodeType.Document) { presentation.PropertyFactory.DefaultXmlNamespaceUri = xmlNode.NamespaceURI; } if (xmlNode.NamespaceURI != presentation.PropertyFactory.DefaultXmlNamespaceUri) { xmlProp.NamespaceUri = xmlNode.NamespaceURI; } XmlAttributeCollection attributeCol = xmlNode.Attributes; if (attributeCol != null) { for (int i = 0; i < attributeCol.Count; i++) { XmlNode attr = attributeCol.Item(i); if (attr.Name != "smilref") { xmlProp.SetAttribute(attr.Name, "", attr.Value); } } if (xmlNode.Name == "meta") { XmlNode attrName = attributeCol.GetNamedItem("name"); XmlNode attrContent = attributeCol.GetNamedItem("content"); if (attrName != null && attrContent != null && !String.IsNullOrEmpty(attrName.Value) && !String.IsNullOrEmpty(attrContent.Value)) { Metadata md = presentation.MetadataFactory.CreateMetadata(); md.Name = attrName.Value; md.Content = attrContent.Value; presentation.AddMetadata(md); } } } foreach (XmlNode childXmlNode in xmlNode.ChildNodes) { parseDTBookXmlDocAndPopulateDataModel(childXmlNode, treeNode); } break; } case XmlNodeType.Text: { Presentation presentation = m_Project.GetPresentation(0); string text = xmlNode.Value; TextMedia textMedia = presentation.MediaFactory.CreateTextMedia(); textMedia.Text = text; ChannelsProperty cProp = presentation.PropertyFactory.CreateChannelsProperty(); cProp.SetMedia(m_textChannel, textMedia); int counter = 0; foreach (XmlNode childXmlNode in xmlNode.ParentNode.ChildNodes) { XmlNodeType childXmlType = childXmlNode.NodeType; if (childXmlType == XmlNodeType.Text || childXmlType == XmlNodeType.Element) { counter++; } } if (counter == 1) { parentTreeNode.AddProperty(cProp); } else { core.TreeNode txtWrapperNode = presentation.TreeNodeFactory.Create(); txtWrapperNode.AddProperty(cProp); parentTreeNode.AppendChild(txtWrapperNode); } break; } default: { return; } } }
private void parseSmil(string fullSmilPath) { Presentation presentation = m_Project.GetPresentation(0); string dirPath = Path.GetDirectoryName(m_Book_FilePath); XmlDocument smilXmlDoc = readXmlDocument(fullSmilPath); XmlNodeList listOfAudioNodes = smilXmlDoc.GetElementsByTagName("audio"); if (listOfAudioNodes != null) { foreach (XmlNode audioNode in listOfAudioNodes) { XmlAttributeCollection attributeCol = audioNode.Attributes; if (attributeCol != null) { XmlNode attrAudioSrc = attributeCol.GetNamedItem("src"); if (attrAudioSrc != null && !String.IsNullOrEmpty(attrAudioSrc.Value)) { XmlNode parent = audioNode.ParentNode; if (parent != null && parent.Name == "a") { parent = parent.ParentNode; } if (parent != null) { XmlNodeList listOfAudioPeers = parent.ChildNodes; foreach (XmlNode peerNode in listOfAudioPeers) { if (peerNode.NodeType == XmlNodeType.Element && peerNode.Name == "text") { XmlAttributeCollection peerAttrs = peerNode.Attributes; if (peerAttrs != null) { XmlNode attrTextSrc = peerAttrs.GetNamedItem("src"); if (attrTextSrc != null && !String.IsNullOrEmpty(attrTextSrc.Value)) { int index = attrTextSrc.Value.LastIndexOf('#'); if (index < (attrTextSrc.Value.Length - 1)) { string dtbookFragmentId = attrTextSrc.Value.Substring(index + 1); core.TreeNode tNode = getTreeNodeWithXmlElementId(dtbookFragmentId); if (tNode != null) { AbstractAudioMedia existingAudioMedia = tNode.GetAudioMedia(); if (existingAudioMedia != null) { //Ignore. //System.Diagnostics.Debug.Fail("TreeNode already has media ??"); } XmlNode attrClipBegin = attributeCol.GetNamedItem("clipBegin"); XmlNode attrClipEnd = attributeCol.GetNamedItem("clipEnd"); Media media = null; if (attrAudioSrc.Value.EndsWith("wav")) { string fullWavPath = Path.Combine(dirPath, attrAudioSrc.Value); PCMDataInfo pcmInfo = null; Stream wavStream = null; try { wavStream = File.Open(fullWavPath, FileMode.Open, FileAccess.Read, FileShare.Read); pcmInfo = PCMDataInfo.ParseRiffWaveHeader(wavStream); presentation.MediaDataManager.DefaultPCMFormat = pcmInfo.Copy(); TimeDelta duration = new TimeDelta(pcmInfo.Duration); Time clipB = Time.Zero; Time clipE = Time.MaxValue; if (attrClipBegin != null && !string.IsNullOrEmpty(attrClipBegin.Value)) { clipB = new Time(TimeSpan.Parse(attrClipBegin.Value)); } if (attrClipEnd != null && !string.IsNullOrEmpty(attrClipEnd.Value)) { clipE = new Time(TimeSpan.Parse(attrClipEnd.Value)); } if (!clipB.IsEqualTo(Time.Zero) || !clipE.IsEqualTo(Time.MaxValue)) { duration = clipE.GetTimeDelta(clipB); } long byteOffset = 0; if (!clipB.IsEqualTo(Time.Zero)) { byteOffset = pcmInfo.GetByteForTime(clipB); } if (byteOffset > 0) { wavStream.Seek(byteOffset, SeekOrigin.Current); } presentation.MediaDataFactory.DefaultAudioMediaDataType = typeof(WavAudioMediaData); WavAudioMediaData mediaData = (WavAudioMediaData) presentation.MediaDataFactory.CreateAudioMediaData(); mediaData.InsertAudioData(wavStream, Time.Zero, duration); media = presentation.MediaFactory.CreateManagedAudioMedia(); ((ManagedAudioMedia)media).AudioMediaData = mediaData; } finally { if (wavStream != null) { wavStream.Close(); } } } else { media = presentation.MediaFactory.CreateExternalAudioMedia(); ((ExternalAudioMedia)media).Src = attrAudioSrc.Value; if (attrClipBegin != null && !string.IsNullOrEmpty(attrClipBegin.Value)) { ((ExternalAudioMedia)media).ClipBegin = new Time(TimeSpan.Parse(attrClipBegin.Value)); } if (attrClipEnd != null && !string.IsNullOrEmpty(attrClipEnd.Value)) { ((ExternalAudioMedia)media).ClipEnd = new Time(TimeSpan.Parse(attrClipEnd.Value)); } } ChannelsProperty chProp = tNode.GetProperty <ChannelsProperty>(); if (chProp == null) { chProp = presentation.PropertyFactory.CreateChannelsProperty(); tNode.AddProperty(chProp); } chProp.SetMedia(m_audioChannel, media); break; // scan peers to audio node } else { System.Diagnostics.Debug.Fail("XmlProperty with ID not found ??"); } } } } } } } } } } } }