/// <summary> /// Gets current Property/ScoredProperty's integer value from its "Value" child-element /// </summary> /// <exception cref="FormatException">either can't find the value or find invalid value number</exception> /// <exception cref="XmlException">XML is not well-formed.</exception> public int GetCurrentPropertyIntValueWithException() { // Do the assignment outside of try-catch so the FormatException of value-not-found could be thrown properly. string textValue = GetCurrentPropertyFullValueWithException(); int intValue = 0; try { intValue = XmlConvertHelper.ConvertStringToInt32(textValue); } catch (FormatException e) { throw NewPrintCapFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.InvalidXMLIntValue"), CurrentElementTextValue, _xmlReader.LineNumber, _xmlReader.LinePosition), e); } return(intValue); }
/// <exception cref="XmlException">XML is not well-formed.</exception> internal override sealed bool OptionPropCallback(PrintCapabilityOption baseOption, XmlPrintCapReader reader) { FixedMediaSizeOption option = baseOption as FixedMediaSizeOption; bool handled = false; if (reader.CurrentElementNodeType == PrintSchemaNodeTypes.ScoredProperty) { handled = true; string sPropertyName = reader.CurrentElementNameAttrValue; if ((sPropertyName == PrintSchemaTags.Keywords.PageMediaSizeKeys.MediaSizeWidth) || (sPropertyName == PrintSchemaTags.Keywords.PageMediaSizeKeys.MediaSizeHeight)) { if (reader.MoveToNextSchemaElement(reader.CurrentElementDepth + 1, PrintSchemaNodeTypes.ScoredPropertyLevelTypes)) { if (reader.CurrentElementNodeType == PrintSchemaNodeTypes.Value) { // Child property is Value for fixed media size int intValue = 0; bool convertOK = false; try { intValue = XmlConvertHelper.ConvertStringToInt32(reader.CurrentElementTextValue); convertOK = true; } // We want to catch internal FormatException to skip recoverable XML content syntax error #pragma warning suppress 56502 #if _DEBUG catch (FormatException e) #else catch (FormatException) #endif { #if _DEBUG Trace.WriteLine("-Error- Invalid int value '" + reader.CurrentElementTextValue + "' at line number " + reader._xmlReader.LineNumber + ", line position " + reader._xmlReader.LinePosition + ": " + e.Message); #endif } if (convertOK) { if (sPropertyName == PrintSchemaTags.Keywords.PageMediaSizeKeys.MediaSizeWidth) { option._mediaSizeWidth = intValue; } else { option._mediaSizeHeight = intValue; } } } } else { #if _DEBUG Trace.WriteLine("-Error- Missing required Value or ParameterRef child-element at line number " + reader._xmlReader.LineNumber + ", line position " + reader._xmlReader.LinePosition); #endif } } else { handled = false; #if _DEBUG Trace.WriteLine("-Warning- skip unknown ScoredProperty '" + reader.CurrentElementNameAttrValue + "' at line " + reader._xmlReader.LineNumber + ", position " + reader._xmlReader.LinePosition); #endif } } return(handled); }