/// <summary> /// Creates formatted FlowDocument /// </summary> protected virtual void GetFlowDocumentFromNavigatorAsync(XPathNavigator navigator, Story story, FlowDocumentStyleProvider styleProvider, object userState) { PrintableStoryFlowDocument flowDocument = new PrintableStoryFlowDocument(); MsdnStoryToFlowDocumentConverter.ApplyStyle(flowDocument, GetFlowDocumentStyle(styleProvider)); // Headline does not require async fetches, so the base class method can be used CreateHeadline(flowDocument, navigator, story, styleProvider); CreateBodyAsync(flowDocument, navigator, story, styleProvider, userState); }
/// <summary> /// CreateBodyAsync calls CreateBody to produce the FlowDocument, then begins async download of image sources. /// If download is pending, or if there are no image sources in the document, it raises completed event /// </summary> protected virtual void CreateBodyAsync(PrintableStoryFlowDocument flowDocument, XPathNavigator navigator, Story story, FlowDocumentStyleProvider styleProvider, object userState) { if (!IsImageDownloadPending) { CreateBody(flowDocument, navigator, story, styleProvider); // Check if image source fetches are needed if (_pendingImageRequestStates != null && _pendingImageRequestStates.Count > 0) { // Request image sources. Store the FlowDocument as our user state and exit. Completed event is raised when image fetches complete _targetDocument = flowDocument; _dispatcher.BeginInvoke(DispatcherPriority.Input, new DispatcherOperationCallback(GetImageSources), userState); return; } } // Fallback: either there are no image sources to fetch, or downloads are pending. Raise completed event ConversionCompletedEventArgs args = new ConversionCompletedEventArgs(userState, flowDocument); _dispatcher.BeginInvoke(DispatcherPriority.Input, new DispatcherOperationCallback(RaiseConversionCompleted), args); }