/// <summary> /// Converts the given PrintTicket into Win32 DEVMODE. /// </summary> /// <param name="printTicket">MemoryStream containing the XML PrintTicket.</param> /// <param name="baseType">Type of default DEVMODE to use as base of conversion.</param> /// <param name="scope">scope that the input PrintTicket will be limited to</param> /// <returns>Byte buffer that contains the converted Win32 DEVMODE.</returns> /// <exception cref="ObjectDisposedException"> /// The PTProvider instance has already been disposed. /// </exception> /// <exception cref="ArgumentException"> /// The PrintTicket specified by <paramref name="printTicket"/> is not well-formed. /// </exception> /// <exception cref="PrintQueueException"> /// The PTProvider instance failed to convert the PrintTicket to a DEVMODE. /// </exception> public override byte[] ConvertPrintTicketToDevMode(MemoryStream printTicket, BaseDevModeType baseType, PrintTicketScope scope) { VerifyAccess(); InternalPrintTicket ticket = (printTicket != null) ? new InternalPrintTicket(printTicket) : null; DevMode result = GetDEVMODE(baseType); DevModeFields supportedFields; WinSpoolPrinterCapabilities capabilities = GetCapabilities(result); try { supportedFields = capabilities.Fields; } finally { capabilities.Release(); } PrintTicketToDevMode(result, ticket, scope, supportedFields); return(result.ByteData); }
/// <summary> /// Merges delta PrintTicket with base PrintTicket and then validates the merged PrintTicket. /// </summary> /// <param name="basePrintTicket">The MemoryStream that contains base XML PrintTicket.</param> /// <param name="deltaPrintTicket">The MemoryStream that contains delta XML PrintTicket.</param> /// <param name="scope">scope that delta PrintTicket and result PrintTicket will be limited to</param> /// <param name="conflictStatus">The returned conflict resolving status.</param> /// <returns>MemoryStream that contains validated and merged PrintTicket XML.</returns> /// <exception cref="ObjectDisposedException"> /// The PTProvider instance has already been disposed. /// </exception> /// <exception cref="ArgumentException"> /// The base PrintTicket specified by <paramref name="basePrintTicket"/> is not well-formed, /// or delta PrintTicket specified by <paramref name="deltaPrintTicket"/> is not well-formed. /// </exception> /// <exception cref="PrintQueueException"> /// The PTProvider instance failed to merge and validate the input PrintTicket(s). /// </exception> public override MemoryStream MergeAndValidatePrintTicket(MemoryStream basePrintTicket, MemoryStream deltaPrintTicket, PrintTicketScope scope, out ConflictStatus conflictStatus) { VerifyAccess(); DevModeFields supportedFields = DevModeFields.All; DevMode defaultDevMode = GetDEVMODE(BaseDevModeType.PrinterDefault); InternalPrintTicket baseTicket = (basePrintTicket != null) ? new InternalPrintTicket(basePrintTicket) : null; DevMode baseDevMode = defaultDevMode.Clone(); PrintTicketToDevMode(baseDevMode, baseTicket, scope, supportedFields); InternalPrintTicket deltaTicket = (deltaPrintTicket != null) ? new InternalPrintTicket(deltaPrintTicket) : null; DevMode deltaDevMode = defaultDevMode.Clone(); PrintTicketToDevMode(deltaDevMode, deltaTicket, scope, supportedFields); // DevMode Merge - Copy fields set in baseDevMode but not set in deltaDevMode deltaDevMode.Copy(baseDevMode, baseDevMode.Fields & (~deltaDevMode.Fields)); conflictStatus = Validate(deltaDevMode) ? ConflictStatus.NoConflict : ConflictStatus.ConflictResolved; InternalPrintTicket validatedTicket = DevModeToPrintTicket(deltaDevMode, scope, supportedFields); return(validatedTicket.XmlStream); }
/// <summary> /// Constructs a new job copy count setting object. /// </summary> internal JobCopyCountSetting(InternalPrintTicket ownerPrintTicket) : base(ownerPrintTicket, PrintSchemaTags.Keywords.ParameterDefs.JobCopyCount, PrintTicketParamTypes.Parameter, PrintTicketParamValueTypes.IntValue) { }
/// <summary> /// Constructs a new page media size setting object. /// </summary> internal PageMediaSizeSetting(InternalPrintTicket ownerPrintTicket) : base(ownerPrintTicket) { this._featureName = PrintSchemaTags.Keywords.PageMediaSizeKeys.Self; this._propertyMaps = new PTPropertyMapEntry[] { new PTPropertyMapEntry(this, PrintSchemaTags.Framework.OptionNameProperty, PTPropValueTypes.EnumStringValue, PrintSchemaTags.Keywords.PageMediaSizeKeys.MediaSizeNames, PrintSchemaTags.Keywords.PageMediaSizeKeys.MediaSizeEnums), new PTPropertyMapEntry(this, PrintSchemaTags.Keywords.PageMediaSizeKeys.MediaSizeWidth, PTPropValueTypes.PositiveIntValue), new PTPropertyMapEntry(this, PrintSchemaTags.Keywords.PageMediaSizeKeys.MediaSizeHeight, PTPropValueTypes.PositiveIntValue), // property map entries for non-PS custom size new PTPropertyMapEntry(this, PrintSchemaTags.Keywords.PageMediaSizeKeys.CustomMediaSizeWidth, PTPropValueTypes.IntParamRefValue, PrintSchemaTags.Keywords.PageMediaSizeKeys.MediaSizeWidth, PrintSchemaTags.Keywords.ParameterDefs.PageMediaSizeMediaSizeWidth), new PTPropertyMapEntry(this, PrintSchemaTags.Keywords.PageMediaSizeKeys.CustomMediaSizeHeight, PTPropValueTypes.IntParamRefValue, PrintSchemaTags.Keywords.PageMediaSizeKeys.MediaSizeHeight, PrintSchemaTags.Keywords.ParameterDefs.PageMediaSizeMediaSizeHeight), }; }
/// <summary> /// Constructs a new page scaling setting object. /// </summary> internal PageScalingSetting(InternalPrintTicket ownerPrintTicket) : base(ownerPrintTicket) { this._featureName = PrintSchemaTags.Keywords.PageScalingKeys.Self; this._propertyMaps = new PTPropertyMapEntry[] { new PTPropertyMapEntry(this, PrintSchemaTags.Framework.OptionNameProperty, PTPropValueTypes.EnumStringValue, PrintSchemaTags.Keywords.PageScalingKeys.ScalingNames, PrintSchemaTags.Keywords.PageScalingKeys.ScalingEnums), new PTPropertyMapEntry(this, PrintSchemaTags.Keywords.PageScalingKeys.CustomScaleWidth, PTPropValueTypes.IntParamRefValue, PrintSchemaTags.Keywords.PageScalingKeys.CustomScaleWidth, PrintSchemaTags.Keywords.ParameterDefs.PageScalingScaleWidth), new PTPropertyMapEntry(this, PrintSchemaTags.Keywords.PageScalingKeys.CustomScaleHeight, PTPropValueTypes.IntParamRefValue, PrintSchemaTags.Keywords.PageScalingKeys.CustomScaleHeight, PrintSchemaTags.Keywords.ParameterDefs.PageScalingScaleHeight), new PTPropertyMapEntry(this, PrintSchemaTags.Keywords.PageScalingKeys.CustomSquareScale, PTPropValueTypes.IntParamRefValue, PrintSchemaTags.Keywords.PageScalingKeys.CustomSquareScale, PrintSchemaTags.Keywords.ParameterDefs.PageSquareScalingScale), }; }
private InternalPrintTicket DevModeToPrintTicket(DevMode devmode, PrintTicketScope scope, DevModeFields supportedFields) { InternalPrintTicket resultTicket = new InternalPrintTicket(); PrintSchemaShim.TryEmbedDevMode(resultTicket, this.OemDriverNamespace, devmode); PrintSchemaShim.CopyDevModeToTicket(resultTicket, devmode, scope, supportedFields); return(resultTicket); }
public static void SetXsiTypeAttr(InternalPrintTicket pt, XmlElement valueElement, string xsiType) { // the attribute is in the format like: xsi:type="xsd:integer" valueElement.SetAttribute("type", PrintSchemaNamespaces.xsi, XmlDocQName.GetQName(pt.XmlDoc, PrintSchemaNamespaces.xsd, xsiType)); }
/// <summary> /// Creates a duplicate of this InternalPrintTicket object. /// </summary> /// <returns>The duplicated InternalPrintTicket object.</returns> public InternalPrintTicket Clone() { // Design Guideline says do not implement ICloneable since that interface doesn't // specify whether the clone is a deep copy or non-deep copy. So it's recommended // that each type defines its own Clone or Copy methodology. InternalPrintTicket clonePT = new InternalPrintTicket(this.XmlStream); return(clonePT); }
/// <summary> /// Gets the feature XML element in the PrintTicket for the specified feature name. /// Null is returned if the feature XML element can't be found. /// </summary> public static XmlElement GetSchemaElementWithNameAttr(InternalPrintTicket pt, XmlElement parent, string schemaTag, string nameAttrWanted) { XmlElement elementMatched = null; bool foundMatch = false; // Now go through each child element to find the matching schema element XmlNode child = parent.FirstChild; // It's recommended that traversing the node in forward-only movement by using NextSibling // is best for XmlDocument performance. This is because the list is not double-linked. while (child != null) { // We are looking for a standard namespace schema element node if ((child.NodeType != XmlNodeType.Element) || (child.LocalName != schemaTag) || (child.NamespaceURI != PrintSchemaNamespaces.Framework)) { child = child.NextSibling; continue; } if (nameAttrWanted == null) { // Caller is not looking for a "name" attribute value match, so we already // found the wanted schema element. foundMatch = true; } else { // We need to match the "name" attribute value. string childName = ((XmlElement)child).GetAttribute( PrintSchemaTags.Framework.NameAttr, PrintSchemaNamespaces.FrameworkAttrForXmlDOM); if ((childName != null) && (childName.Length != 0) && (XmlDocQName.GetURI(pt.XmlDoc, childName) == PrintSchemaNamespaces.StandardKeywordSet) && (XmlDocQName.GetLocalName(childName) == nameAttrWanted)) { foundMatch = true; } } if (foundMatch) { elementMatched = (XmlElement)child; break; } child = child.NextSibling; } return(elementMatched); }
/// <summary> /// Constructs a new NUp setting object. /// </summary> internal NUpSetting(InternalPrintTicket ownerPrintTicket, string featureName) : base(ownerPrintTicket) { this._featureName = featureName; this._propertyMaps = new PTPropertyMapEntry[] { new PTPropertyMapEntry(this, PrintSchemaTags.Keywords.NUpKeys.PagesPerSheet, PTPropValueTypes.PositiveIntValue), }; }
/// <summary> /// Converts the given Win32 DEVMODE into PrintTicket. /// </summary> /// <param name="devMode">Byte buffer containing the Win32 DEVMODE.</param> /// <param name="scope">scope that the result PrintTicket will be limited to</param> /// <returns>MemoryStream that contains the converted XML PrintTicket.</returns> /// <exception cref="ObjectDisposedException"> /// The PTProvider instance has already been disposed. /// </exception> /// <exception cref="ArgumentException"> /// The DEVMODE specified by <paramref name="devMode"/> is not well-formed. /// </exception> /// <exception cref="PrintQueueException"> /// The PTProvider instance failed to convert the DEVMODE to a PrintTicket. /// </exception> public override MemoryStream ConvertDevModeToPrintTicket(byte[] devMode, PrintTicketScope scope) { VerifyAccess(); if (devMode == null) { throw new ArgumentNullException("devMode"); } InternalPrintTicket result = DevModeToPrintTicket(new DevMode(devMode), scope, DevModeFields.All); return(result.XmlStream); }
/// <summary> /// Constructs a new page output color setting object. /// </summary> internal PageOutputColorSetting(InternalPrintTicket ownerPrintTicket) : base(ownerPrintTicket) { this._featureName = PrintSchemaTags.Keywords.PageOutputColorKeys.Self; this._propertyMaps = new PTPropertyMapEntry[] { new PTPropertyMapEntry(this, PrintSchemaTags.Framework.OptionNameProperty, PTPropValueTypes.EnumStringValue, PrintSchemaTags.Keywords.PageOutputColorKeys.ColorNames, PrintSchemaTags.Keywords.PageOutputColorKeys.ColorEnums), }; }
/// <summary> /// Constructs a new NUp presentation direction setting object. /// </summary> internal NUpPresentationDirectionSetting(InternalPrintTicket ownerPrintTicket) : base(ownerPrintTicket) { this._featureName = PrintSchemaTags.Keywords.NUpKeys.PresentationDirection; this._propertyMaps = new PTPropertyMapEntry[] { new PTPropertyMapEntry(this, PrintSchemaTags.Framework.OptionNameProperty, PTPropValueTypes.EnumStringValue, PrintSchemaTags.Keywords.NUpKeys.DirectionNames, PrintSchemaTags.Keywords.NUpKeys.DirectionEnums), }; }
/// <summary> /// Constructs a new page TrueType font handling mode setting object. /// </summary> internal PageTrueTypeFontModeSetting(InternalPrintTicket ownerPrintTicket) : base(ownerPrintTicket) { this._featureName = PrintSchemaTags.Keywords.PageTrueTypeFontModeKeys.Self; this._propertyMaps = new PTPropertyMapEntry[] { new PTPropertyMapEntry(this, PrintSchemaTags.Framework.OptionNameProperty, PTPropValueTypes.EnumStringValue, PrintSchemaTags.Keywords.PageTrueTypeFontModeKeys.ModeNames, PrintSchemaTags.Keywords.PageTrueTypeFontModeKeys.ModeEnums) }; }
/// <summary> /// Constructs a new duplex setting object. /// </summary> internal DuplexSetting(InternalPrintTicket ownerPrintTicket, string featureName) : base(ownerPrintTicket) { this._featureName = featureName; this._propertyMaps = new PTPropertyMapEntry[] { new PTPropertyMapEntry(this, PrintSchemaTags.Framework.OptionNameProperty, PTPropValueTypes.EnumStringValue, PrintSchemaTags.Keywords.DuplexKeys.DuplexNames, PrintSchemaTags.Keywords.DuplexKeys.DuplexEnums), }; }
private void PrintTicketToDevMode(DevMode devMode, InternalPrintTicket ticket, PrintTicketScope scope, DevModeFields supportedFields) { if (ticket != null) { // Apply the DEVMODE snapshot from the print ticket to our starting DEVMODE, if supported. DevMode ticketDevMode = PrintSchemaShim.TryGetEmbeddedDevMode(ticket, this.OemDriverNamespace); if (ticketDevMode != null) { devMode.CompatibleCopy(ticketDevMode); } PrintSchemaShim.CopyTicketToDevMode(devMode, ticket, scope, supportedFields); } }
/// <summary> /// For PrintTicket XML supplied by client, it may not have all the standard namespace declarations we will need /// in future PrintTicket operations. This function will check and add any missing standard namespace declarations /// to the PrintTicket XML root element. /// </summary> /// <remarks> /// This function should be called after the PrintTicket XML has passed CheckIsWellFormedPrintTicket() validation, /// so it's operating on a well-formed PrintTicket XML. /// </remarks> /// <exception cref="FormatException"> /// Unable to add standard namespace declaration at root element. /// </exception> public static void CheckAndAddMissingStdNamespaces(InternalPrintTicket pt) { XmlElement root = pt.XmlDoc.DocumentElement; bool hasPSK = false, hasXSI = false, hasXSD = false; // Print Schema framework namespace must already exist in the well-formed PrintTicket XML. // first check if any standard namespace declaration is missing in the root element foreach (XmlAttribute attr in root.Attributes) { if (attr.Name.StartsWith("xmlns:", StringComparison.Ordinal) || (attr.Name == "xmlns")) { if (attr.Value == PrintSchemaNamespaces.StandardKeywordSet) { hasPSK = true; } else if (attr.Value == PrintSchemaNamespaces.xsi) { hasXSI = true; } else if (attr.Value == PrintSchemaNamespaces.xsd) { hasXSD = true; } } } // then add the declarations for any missing standard namespaces if (!hasPSK) { AddStdNamespaceDeclaration(root, PrintSchemaPrefixes.StandardKeywordSet, PrintSchemaNamespaces.StandardKeywordSet); } if (!hasXSI) { AddStdNamespaceDeclaration(root, PrintSchemaPrefixes.xsi, PrintSchemaNamespaces.xsi); } if (!hasXSD) { AddStdNamespaceDeclaration(root, PrintSchemaPrefixes.xsd, PrintSchemaNamespaces.xsd); } }
/// <summary> /// Constructs a new page resolution setting object. /// </summary> internal PageResolutionSetting(InternalPrintTicket ownerPrintTicket) : base(ownerPrintTicket) { this._featureName = PrintSchemaTags.Keywords.PageResolutionKeys.Self; this._propertyMaps = new PTPropertyMapEntry[] { new PTPropertyMapEntry(this, PrintSchemaTags.Keywords.PageResolutionKeys.ResolutionX, PTPropValueTypes.PositiveIntValue), new PTPropertyMapEntry(this, PrintSchemaTags.Keywords.PageResolutionKeys.ResolutionY, PTPropValueTypes.PositiveIntValue), new PTPropertyMapEntry(this, PrintSchemaTags.Keywords.PageResolutionKeys.QualitativeResolution, PTPropValueTypes.EnumStringValue, PrintSchemaTags.Keywords.PageResolutionKeys.QualityNames, PrintSchemaTags.Keywords.PageResolutionKeys.QualityEnums), }; }
public static XmlElement AddSchemaElementWithNameAttr(InternalPrintTicket pt, XmlElement parent, string schemaTag, string nameAttr) { string prefix = pt.XmlDoc.DocumentElement.GetPrefixOfNamespace(PrintSchemaNamespaces.Framework); XmlElement newNode = pt.XmlDoc.CreateElement(prefix, schemaTag, PrintSchemaNamespaces.Framework); if (nameAttr != null) { newNode.SetAttribute(PrintSchemaTags.Framework.NameAttr, PrintSchemaNamespaces.FrameworkAttrForXmlDOM, XmlDocQName.GetQName(pt.XmlDoc, PrintSchemaNamespaces.StandardKeywordSet, nameAttr)); } return((XmlElement)parent.AppendChild(newNode)); }
internal PageInputBinSetting(InternalPrintTicket ownerPrintTicket) : base(ownerPrintTicket, PrintSchemaTags.Keywords.InputBinKeys.PageInputBin) { }
internal JobNUpSetting(InternalPrintTicket ownerPrintTicket) : base(ownerPrintTicket, PrintSchemaTags.Keywords.NUpKeys.JobNUp) { }
/// <summary> /// Gets the PrintCapabilities relative to the given PrintTicket. /// </summary> /// <param name="printTicket">The stream that contains XML PrintTicket based on which PrintCapabilities should be built.</param> /// <returns>Stream that contains XML PrintCapabilities.</returns> /// <exception cref="ObjectDisposedException"> /// The PTProvider instance has already been disposed. /// </exception> /// <exception cref="ArgumentException"> /// The input PrintTicket specified by <paramref name="printTicket"/> is not well-formed. /// </exception> /// <exception cref="PrintQueueException"> /// The PTProvider instance failed to retrieve the PrintCapabilities. /// </exception> public override MemoryStream GetPrintCapabilities(MemoryStream printTicket) { VerifyAccess(); InternalPrintTicket internalTicket = null; try { internalTicket = (printTicket != null) ? new InternalPrintTicket(printTicket) : null; } catch (XmlException xmlException) { throw new ArgumentException( String.Format( CultureInfo.CurrentCulture, "{0} {1} {2}", PrintSchemaTags.Framework.PrintTicketRoot, PTUtility.GetTextFromResource("FormatException.XMLNotWellFormed"), xmlException.Message), "printTicket", xmlException); } DevMode defaultDevMode = GetDEVMODE(BaseDevModeType.UserDefault); DevMode devMode = defaultDevMode.Clone(); PrintTicketToDevMode(devMode, internalTicket, PrintTicketScope.JobScope, DevModeFields.All); MemoryStream capabilitiesStream = new MemoryStream(); WinSpoolPrinterCapabilities capabilities = GetCapabilities(devMode); try { PrintCapabilitiesWriter writer = new PrintCapabilitiesWriter(capabilitiesStream, "ns0000", this.OemDriverNamespace, false); try { writer.WriteStartDocument(); { writer.WritePageDevmodeSnapshot(devMode.ByteData); if (capabilities.HasICMIntent) { writer.WritePageICMRenderingIntentFeature(); } if (capabilities.HasICMMethod) { writer.WritePageColorManagementFeature(); } if (capabilities.CanCollate) { writer.WriteDocumentCollateFeature(); } int minCopies = capabilities.MinCopies; int maxCopies = capabilities.MaxCopies; int defaultCopies = minCopies; defaultCopies = Math.Max(minCopies, Math.Min(defaultDevMode.Copies, maxCopies)); writer.WriteJobCopiesAllDocumentsParameterDef(minCopies, maxCopies, defaultCopies); writer.WriteJobNUpAllDocumentsContiguously(capabilities.NUp); writer.WriteJobDuplexAllDocumentsContiguouslyFeature(capabilities.CanDuplex); if (capabilities.CanScale) { writer.WritePageScalingFeature(1, 1000, 100); } writer.WritePageMediaSizeFeature( capabilities.Papers, capabilities.PaperNames, PrintSchemaShim.TenthOfMillimeterToMicrons(capabilities.PaperSizes) ); writer.WritePageResolutionFeature(capabilities.Resolutions); int logicalPixelsX, logicalPixelsY; int physicalWidth, physicalHeight; int physicalOffsetX, physicalOffsetY; int horizontalResolution, verticalResolution; bool gotDevCaps = capabilities.TryGetDeviceCapabilities( out logicalPixelsX, out logicalPixelsY, out physicalWidth, out physicalHeight, out physicalOffsetX, out physicalOffsetY, out horizontalResolution, out verticalResolution); if (gotDevCaps && logicalPixelsX > 0 && logicalPixelsY > 0) { int imageableSizeWidth = PrintSchemaShim.DpiToMicrons(physicalWidth, logicalPixelsX); int imageableSizeHeight = PrintSchemaShim.DpiToMicrons(physicalHeight, logicalPixelsY); int originWidth = PrintSchemaShim.DpiToMicrons(physicalOffsetX, logicalPixelsY); int originHeight = PrintSchemaShim.DpiToMicrons(physicalOffsetY, logicalPixelsY); int extentWidth = PrintSchemaShim.DpiToMicrons(horizontalResolution, logicalPixelsY); int extentHeight = PrintSchemaShim.DpiToMicrons(verticalResolution, logicalPixelsY); writer.WritePageImageableSizeProperty( imageableSizeWidth, imageableSizeHeight, originWidth, originHeight, extentWidth, extentHeight); } writer.WritePageOrientationFeature(capabilities.LandscapeOrientation); writer.WritePageOutputColorFeature(capabilities.HasColor); writer.WriteJobInputBinFeature(capabilities.Bins, capabilities.BinNames); writer.WritePageMediaTypeFeature(capabilities.MediaTypes, capabilities.MediaTypeNames); if (capabilities.TrueType) { writer.WritePageTrueTypeFontModeFeature(); writer.WritePageDeviceFontSubstitutionFeature(); } } writer.WriteEndDocument(); } finally { writer.Release(); writer = null; } } finally { capabilities.Release(); capabilities = null; } // calls Security Critical Dispose on a private resource capabilitiesStream.Position = 0; return(capabilitiesStream); }
/// <summary> /// Verifies if the PrintTicket is well-formed /// </summary> /// <exception cref="FormatException"> /// The PrintTicket is not well-formed. /// </exception> public static void CheckIsWellFormedPrintTicket(InternalPrintTicket pt) { XmlElement root = pt.XmlDoc.DocumentElement; // Root element should be in our standard namespace and should be <PrintTicket>. if ((root.NamespaceURI != PrintSchemaNamespaces.Framework) || (root.LocalName != PrintSchemaTags.Framework.PrintTicketRoot)) { throw NewPTFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.InvalidRootElement"), root.NamespaceURI, root.LocalName)); } string version = root.GetAttribute(PrintSchemaTags.Framework.RootVersionAttr, PrintSchemaNamespaces.FrameworkAttrForXmlDOM); // Root element should have the "version" attribute // (XmlElement.GetAttribute returns empty string when the attribute is not found, but // (XmlTextReader.GetAttribute returns null when the attribute is not found) if ((version == null) || (version.Length == 0)) { throw NewPTFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.RootMissingAttribute"), PrintSchemaTags.Framework.RootVersionAttr)); } decimal versionNum; try { versionNum = XmlConvertHelper.ConvertStringToDecimal(version); } catch (FormatException e) { throw NewPTFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.RootInvalidAttribute"), PrintSchemaTags.Framework.RootVersionAttr, version), e); } // and the "version" attribute value should be what we support if (versionNum != PrintSchemaTags.Framework.SchemaVersion) { throw NewPTFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.VersionNotSupported"), versionNum)); } // Now go through each root child element and verify they are valid children XmlNode rootChild = root.FirstChild; // It's recommended that traversing the node in forward-only movement by using NextSibling // is best for XmlDocument performance. This is because the list is not double-linked. while (rootChild != null) { // If the root child doesn't live in our standard namespace, we should ignore it // rather than rejecting it since it's acceptable to have private elements under // the root. if (rootChild.NamespaceURI == PrintSchemaNamespaces.Framework) { // For <PrintTicket> root, our Framework schema only allow these children elements: // <Feature> <AttributeSet> <Property> <ParameterInit> if ((rootChild.NodeType != XmlNodeType.Element) || ((rootChild.LocalName != PrintSchemaTags.Framework.Feature) && (rootChild.LocalName != PrintSchemaTags.Framework.ParameterInit) && (rootChild.LocalName != PrintSchemaTags.Framework.Property))) { throw NewPTFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.RootInvalidChildElement"), rootChild.Name)); } string childName = ((XmlElement)rootChild).GetAttribute(PrintSchemaTags.Framework.NameAttr, PrintSchemaNamespaces.FrameworkAttrForXmlDOM); // All the recognized root child element should have an XML attribut "name" if ((childName == null) || (childName.Length == 0)) { throw NewPTFormatException(String.Format(CultureInfo.CurrentCulture, PTUtility.GetTextFromResource("FormatException.RootChildMissingAttribute"), rootChild.Name, PrintSchemaTags.Framework.NameAttr)); } } rootChild = rootChild.NextSibling; } // We will end the verification at the root child level here. Instead of traversing the whole tree // to find violations in this construtor, we will delay detecting violations under root child level // until information of an individual feature/property subtree is requested. }
/// <summary> /// Returns a new FormatException instance for not-well-formed PrintTicket XML. /// </summary> /// <param name="detailMsg">detailed message about the violation of well-formness</param> /// <param name="innerException">the exception that causes the violation of well-formness</param> /// <returns>the new FormatException instance</returns> private static FormatException NewPTFormatException(string detailMsg, Exception innerException) { return(InternalPrintTicket.NewPTFormatException(detailMsg, innerException)); }
internal DocumentCollateSetting(InternalPrintTicket ownerPrintTicket) : base(ownerPrintTicket, PrintSchemaTags.Keywords.CollateKeys.DocumentCollate) { }
internal JobDuplexSetting(InternalPrintTicket ownerPrintTicket) : base(ownerPrintTicket, PrintSchemaTags.Keywords.DuplexKeys.JobDuplex) { }
internal JobStapleSetting(InternalPrintTicket ownerPrintTicket) : base(ownerPrintTicket, PrintSchemaTags.Keywords.StapleKeys.JobStaple) { }