Skip to content

fixing DrtXpsApi failures #1301

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -325,26 +325,28 @@ public ReadOnlyCollection<XpsDigitalSignature> Signatures

foreach( PackagePart part in xmlPartList )
{
Stream stream = part.GetStream(FileMode.Open, FileAccess.Read );
//
// An empty stream contains not version extensibility thus is valid
// We do create empty parts for print tickets
//
if( stream.Length == 0 )
continue;
try
using (Stream stream = part.GetStream(FileMode.Open, FileAccess.Read))
{
if( StreamContainsVersionExtensiblity(stream) )
//
// An empty stream contains not version extensibility thus is valid
// We do create empty parts for print tickets
//
if (stream.Length == 0)
continue;
try
{
if (StreamContainsVersionExtensiblity(stream))
{
isSignable = false;
break;
}
}
catch (XmlException)
{
isSignable = false;
break;
}
}
catch( XmlException )
{
isSignable = false;
break;
}
}
return isSignable;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -950,23 +950,25 @@ IList<String> linkTargetStream
void
ParsePages()
{
Stream stream = _metroPart.GetStream(FileMode.Open);
//
// If the stream is empty there are no pages to parse
//
if( stream.Length > 0 )
using (Stream stream = _metroPart.GetStream(FileMode.Open))
{
XmlTextReader reader = new XmlTextReader(stream);

while( reader.Read() )
//
// If the stream is empty there are no pages to parse
//
if (stream.Length > 0)
{
if( reader.NodeType == XmlNodeType.Element && reader.Name == XpsS0Markup.PageContent)
XmlTextReader reader = new XmlTextReader(stream);

while (reader.Read())
{
string attribute = reader.GetAttribute(XmlTags.Source);
if( attribute != null )
if (reader.NodeType == XmlNodeType.Element && reader.Name == XpsS0Markup.PageContent)
{
Uri relativeUri = new Uri(attribute, UriKind.Relative);
AddPageToCache(PackUriHelper.ResolvePartUri( Uri, relativeUri));
string attribute = reader.GetAttribute(XmlTags.Source);
if (attribute != null)
{
Uri relativeUri = new Uri(attribute, UriKind.Relative);
AddPageToCache(PackUriHelper.ResolvePartUri(Uri, relativeUri));
}
}
}
}
Expand Down Expand Up @@ -1074,14 +1076,16 @@ IList<String> linkTargetStream
Collection<XpsSignatureDefinition> sigDefCollection
)
{
XmlTextReader reader = new XmlTextReader( sigDefPart.GetStream(FileMode.Open) );
while( reader.Read() )
using (XmlTextReader reader = new XmlTextReader(sigDefPart.GetStream(FileMode.Open)))
{
if( reader.NodeType == XmlNodeType.Element &&
reader.Name == XpsS0Markup.SignatureDefinitions
)
while (reader.Read())
{
ParseSignatureDefinitions( reader, sigDefCollection );
if (reader.NodeType == XmlNodeType.Element &&
reader.Name == XpsS0Markup.SignatureDefinitions
)
{
ParseSignatureDefinitions(reader, sigDefCollection);
}
}
}
}
Expand Down Expand Up @@ -1124,21 +1128,20 @@ Collection<XpsSignatureDefinition> sigDefCollection
{
sigDefPart = CurrentXpsManager.AddSignatureDefinitionPart( _metroPart );
}
Stream stream = sigDefPart.GetStream(FileMode.Create);
XmlTextWriter writer = new XmlTextWriter(
stream,
System.Text.Encoding.UTF8
);
writer.WriteStartDocument();
writer.WriteStartElement( XpsS0Markup.SignatureDefinitions,
XpsS0Markup.SignatureDefinitionNamespace);
foreach( XpsSignatureDefinition sigDef in _signatureDefinitions )

using (Stream stream = sigDefPart.GetStream(FileMode.Create))
using (XmlTextWriter writer = new XmlTextWriter(stream, System.Text.Encoding.UTF8))
{
sigDef.WriteXML( writer );
writer.WriteStartDocument();
writer.WriteStartElement(XpsS0Markup.SignatureDefinitions,
XpsS0Markup.SignatureDefinitionNamespace);
foreach (XpsSignatureDefinition sigDef in _signatureDefinitions)
{
sigDef.WriteXML(writer);
}
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.Close();
stream.Close();

_sigCollectionDirty = false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -546,28 +546,31 @@ Uri partUri
void
ParseDocuments()
{
Stream stream = _metroPart.GetStream(FileMode.Open);
//
// If the stream is empty there are no documents to parse
//
if( stream.Length > 0 )
{
XmlTextReader reader = new XmlTextReader(stream);

while( reader.Read() )
{
if( reader.NodeType == XmlNodeType.Element && reader.Name == XpsS0Markup.DocumentReference)
{
string attribute = reader.GetAttribute(XmlTags.Source);
if( attribute != null )
{
Uri relativeUri = new Uri(attribute, UriKind.Relative);
//This routine properly adds DocumentReaderWriter to the _documentCache
AddDocumentToCache(PackUriHelper.ResolvePartUri( Uri, relativeUri));
}
}
}
}
using (Stream stream = _metroPart.GetStream(FileMode.Open))
{
//
// If the stream is empty there are no documents to parse
//
if (stream.Length > 0)
{
XmlTextReader reader = new XmlTextReader(stream);

while (reader.Read())
{
if (reader.NodeType == XmlNodeType.Element && reader.Name == XpsS0Markup.DocumentReference)
{
string attribute = reader.GetAttribute(XmlTags.Source);
if (attribute != null)
{
Uri relativeUri = new Uri(attribute, UriKind.Relative);
//This routine properly adds DocumentReaderWriter to the _documentCache
AddDocumentToCache(PackUriHelper.ResolvePartUri(Uri, relativeUri));
}
}
}
}
}

}

/// <summary>
Expand Down
Loading