public override IEnumerable <SSMLValidationError> Verify(XElement element, SsmlPlatform platform = SsmlPlatform.All) { var error = VerifyHasOnlySpecificAttributes(element, null, new[] { AttributeNameRate, AttributeNamePitch, AttributeNameVolume }); if (error != null) { yield return(error); } error = RequiresAttribute(element, AttributeNameRate, null, a => VerifyMatchesRegEx(a, m_regExRate), true); if (error != null) { yield return(error); } error = RequiresAttribute(element, AttributeNamePitch, null, a => VerifyMatchesRegEx(a, m_regExPitch), true); if (error != null) { yield return(error); } error = RequiresAttribute(element, AttributeNameVolume, null, a => VerifyMatchesRegEx(a, m_regExVolume), true); if (error != null) { yield return(error); } }
/// <summary> /// Verifies the input ssml. /// </summary> /// <param name="input">The SSML to check</param> /// <param name="platform">The platform to eveluate the SSML against</param> /// <returns>The result of the verification</returns> public IEnumerable <SSMLValidationError> Verify(string input, SsmlPlatform platform = SsmlPlatform.All) { XElement element; try { element = input.ToXElement(); } catch (XmlException ex) { throw new XmlException("The given SSML is malformed.", ex); } var error = VerifyRootTag(element); if (error != null) { yield return(error); } foreach (var childElement in element.Elements()) { foreach (var childError in Verify(childElement, platform)) { yield return(childError); } } }
public override IEnumerable <SSMLValidationError> Verify(XElement element, SsmlPlatform platform = SsmlPlatform.All) { var validInterpretAsValues = GetValidInterpretAsValues(platform); var allowedAttributes = GetAllowedAttributes(platform); var error = VerifyHasOnlySpecificAttributes(element, null, allowedAttributes); if (error != null) { yield return(error); } error = RequiresAttribute(element, AttributeNameInterpretAs, attributeValidationFunc: a => VerifyValues(a, validInterpretAsValues), optional: true); if (error != null) { yield return(error); } error = RequiresAttribute(element, AttributeNameDetail, attributeValidationFunc: a => VerifyValues(a, new [] { "1", "2" }), optional: true); if (error != null) { yield return(error); } error = VerifyFormat(element, platform); if (error != null) { yield return(error); } }
private IEnumerable <SSMLValidationError> Verify(XElement element, SsmlPlatform platform = SsmlPlatform.All) { var elementName = element.GetNameWithAlias(); var tagStrategy = m_strategies.FirstOrDefault( p => p.IsResponsibleFor(elementName) && p.IsValidForPlatform(platform)); if (tagStrategy == null) { yield return(new SSMLValidationError(VerificationState.InvalidTag, $"Invalid tag {elementName}")); yield break; } foreach (var error in tagStrategy.Verify(element, platform)) { yield return(error); } foreach (var childElement in element.Elements()) { foreach (var childError in Verify(childElement, platform)) { yield return(childError); } } }
public override IEnumerable <SSMLValidationError> Verify(XElement element, SsmlPlatform platform = SsmlPlatform.All) { var error = VerifyHasValidParent(element, TagNameAudio); if (error != null) { yield return(error); } }
public override IEnumerable <SSMLValidationError> Verify(XElement element, SsmlPlatform platform = SsmlPlatform.All) { var error = VerifyNoAttributesAllowed(element); if (error != null) { yield return(error); } }
public override IEnumerable <SSMLValidationError> Verify(XElement element, SsmlPlatform platform = SsmlPlatform.All) { var error = RequiresAttribute(element, "role", null, a => VerifyValues(a, m_validRoles)); if (error != null) { yield return(error); } }
public override IEnumerable <SSMLValidationError> Verify(XElement element, SsmlPlatform platform = SsmlPlatform.All) { var error = VerifyHasOnlySpecificAttributes(element, null, new [] { "alias" }); if (error != null) { yield return(error); } }
public override IEnumerable <SSMLValidationError> Verify(XElement element, SsmlPlatform platform = SsmlPlatform.All) { var error = RequiresAttribute(element, AttributeNameName, null, v => VerifyValues(v, m_validSpeakingStyles)); if (error != null) { yield return(error); } }
public override IEnumerable <SSMLValidationError> Verify(XElement element, SsmlPlatform platform = SsmlPlatform.All) { var error = VerifyContainsOnlySpecificElements(element, new List <string> { "par", "seq", "media" }); if (error != null) { yield return(error); } }
public override IEnumerable <SSMLValidationError> Verify(XElement element, SsmlPlatform platform = SsmlPlatform.All) { var error = RequiresAttribute(element, "id", "xml", a => VerifyMatchesRegEx(a, RegExId), true); if (error != null) { yield return(error); } error = RequiresAttribute(element, "begin", null, VerifyTimeDesignation, true); if (error != null) { yield return(error); } error = RequiresAttribute(element, "end", null, VerifyTimeDesignation, true); if (error != null) { yield return(error); } error = RequiresAttribute(element, "repeatCount", null, a => VerifyMatchesRegEx(a, RegularExpressionRepeatCount), true); if (error != null) { yield return(error); } error = RequiresAttribute(element, "repeatDur", null, VerifyTimeDesignation, true); if (error != null) { yield return(error); } error = RequiresAttribute(element, "soundLevel", null, a => VerifyMatchesRegEx(a, RegularExpressionSoundLevel), true); if (error != null) { yield return(error); } error = RequiresAttribute(element, "fadeInDur", null, VerifyTimeDesignation, true); if (error != null) { yield return(error); } error = RequiresAttribute(element, "fadeOutDur", null, VerifyTimeDesignation, true); if (error != null) { yield return(error); } }
public override IEnumerable <SSMLValidationError> Verify(XElement element, SsmlPlatform platform = SsmlPlatform.All) { var error = RequiresAttribute(element, "src"); if (error != null) { yield return(error); } foreach (var result in VerifyGoogleSpecificAttributes(element, platform)) { yield return(result); } }
private IReadOnlyCollection <string> GetAllowedAttributes(SsmlPlatform platform) { var allowedAttributes = new List <string> { AttributeNameInterpretAs, AttributeNameFormat }; if (platform == SsmlPlatform.Google) { allowedAttributes.Add(AttributeNameDetail); } return(allowedAttributes); }
public override IEnumerable <SSMLValidationError> Verify(XElement element, SsmlPlatform platform = SsmlPlatform.All) { var validLevels = m_validLevels.ToList(); if (platform == SsmlPlatform.Google) { validLevels.Add("none"); } var error = RequiresAttribute(element, AttributeNameLevel, null, a => VerifyValues(a, validLevels)); if (error != null) { yield return(error); } }
private IReadOnlyCollection <string> GetValidInterpretAsValues(SsmlPlatform platform) { var validValues = m_validInterpretAsValues.ToList(); if (platform == SsmlPlatform.Amazon) { validValues.AddRange(new[] { "number", "digits", "address", "interjection" }); } else if (platform == SsmlPlatform.Google) { validValues.AddRange(new[] { "bleep", "verbatim" }); } return(validValues); }
public SSMLValidationError VerifyFormat(XElement element, SsmlPlatform platform) { var containsInterpretAsWithDateValue = RequiresAttribute(element, AttributeNameInterpretAs, null, a => VerifyValues(a, new[] { "date" })) == null; if (containsInterpretAsWithDateValue) { return(RequiresAttribute(element, AttributeNameFormat, null, a => VerifyValues(a, m_validFormatValuesWhenInterpretAsIsDate))); } if (platform == SsmlPlatform.Google) { return(RequiresAttribute(element, AttributeNameFormat, null, a => VerifyMatchesRegEx(a, "^[hmsZ^\\s.!?:;(12|24)]*$"))); } return(RequiresAttribute(element, AttributeNameFormat, null, a => new SSMLValidationError(VerificationState.InvalidAttribute, //It doesn't matter what value the attribute has, it's not allowed when interpret-as != date... $"The element {AttributeNameFormat} can only be used, when the \"{AttributeNameInterpretAs}\"-attribute is set to \"date\""), true)); }
public override IEnumerable <SSMLValidationError> Verify(XElement element, SsmlPlatform platform = SsmlPlatform.All) { var error = VerifyHasOnlySpecificAttributes(element, null, new[] { AttributeNameStrength, AttributeNameTime }); if (error != null) { yield return(error); } error = RequiresAttribute(element, AttributeNameStrength, null, a => VerifyValues(a, m_validStrenghts), true); if (error != null) { yield return(error); } error = RequiresAttribute(element, AttributeNameTime, null, VerifyTimeDesignation, true); if (error != null) { yield return(error); } }
public virtual bool IsValidForPlatform(SsmlPlatform platform) { return(SupportedPlatform == SsmlPlatform.All || platform == SupportedPlatform); }
public abstract IEnumerable <SSMLValidationError> Verify(XElement element, SsmlPlatform platform = SsmlPlatform.All);
protected BaseTagStrategy(string tagName, SsmlPlatform platform) { SupportedPlatform = platform; TagName = tagName; }
private IEnumerable <SSMLValidationError> VerifyGoogleSpecificAttributes(XElement element, SsmlPlatform platform) { if (platform != SsmlPlatform.Google) { yield break; } var error = RequiresAttribute(element, "clipBegin", null, VerifyTimeDesignation, true); if (error != null) { yield return(error); } error = RequiresAttribute(element, "clipEnd", null, VerifyTimeDesignation, true); if (error != null) { yield return(error); } error = RequiresAttribute(element, "speed", attributeValidationFunc: a => VerifyMatchesRegEx(a, RegularExpressionSpeed), optional: true); if (error != null) { yield return(error); } error = RequiresAttribute(element, "repeatCount", attributeValidationFunc: a => VerifyMatchesRegEx(a, RegularExpressionRepeatCount), optional: true); if (error != null) { yield return(error); } //todo Time Verification error = RequiresAttribute(element, "repeatDur", null, VerifyTimeDesignation, true); if (error != null) { yield return(error); } error = RequiresAttribute(element, "soundLevel", attributeValidationFunc: a => VerifyMatchesRegEx(a, RegularExpressionSoundLevel), optional: true); if (error != null) { yield return(error); } }