//============================================================ // CALLBACK DELEGATE METHODS //============================================================ #region AsyncLoadCallback(IAsyncResult result) /// <summary> /// Called when a corresponding asynchronous load operation completes. /// </summary> /// <param name="result">The result of the asynchronous operation.</param> private static void AsyncLoadCallback(IAsyncResult result) { //------------------------------------------------------------ // Local members //------------------------------------------------------------ System.Text.Encoding encoding = System.Text.Encoding.UTF8; XPathNavigator navigator = null; WebRequest httpWebRequest = null; AtomEntryResource entry = null; Uri source = null; WebRequestOptions options = null; SyndicationResourceLoadSettings settings = null; //------------------------------------------------------------ // Determine if the async send operation completed //------------------------------------------------------------ if (result.IsCompleted) { //------------------------------------------------------------ // Extract the send operations parameters from the user state //------------------------------------------------------------ object[] parameters = (object[])result.AsyncState; httpWebRequest = parameters[0] as WebRequest; entry = parameters[1] as AtomEntryResource; source = parameters[2] as Uri; settings = parameters[3] as SyndicationResourceLoadSettings; options = parameters[4] as WebRequestOptions; object userToken = parameters[5]; //------------------------------------------------------------ // Verify expected parameters were found //------------------------------------------------------------ if (entry != null) { //------------------------------------------------------------ // Get the response to the syndication resource request //------------------------------------------------------------ WebResponse httpWebResponse = (WebResponse)httpWebRequest.EndGetResponse(result); //------------------------------------------------------------ // Load syndication resource //------------------------------------------------------------ using (Stream stream = httpWebResponse.GetResponseStream()) { if (settings != null) { encoding = settings.CharacterEncoding; } using (StreamReader streamReader = new StreamReader(stream, encoding)) { XmlReaderSettings readerSettings = new XmlReaderSettings(); readerSettings.IgnoreComments = true; readerSettings.IgnoreWhitespace = true; readerSettings.ProhibitDtd = false; using (XmlReader reader = XmlReader.Create(streamReader, readerSettings)) { if (encoding == System.Text.Encoding.UTF8) { navigator = SyndicationEncodingUtility.CreateSafeNavigator(source, options, null); } else { navigator = SyndicationEncodingUtility.CreateSafeNavigator(source, options, settings.CharacterEncoding); } //------------------------------------------------------------ // Load syndication resource using the framework adapters //------------------------------------------------------------ SyndicationResourceAdapter adapter = new SyndicationResourceAdapter(navigator, settings); adapter.Fill(entry, SyndicationContentFormat.Atom); //------------------------------------------------------------ // Extract member resource information from extensions //------------------------------------------------------------ AtomPublishingEditedSyndicationExtension editedExtension = entry.FindExtension(AtomPublishingEditedSyndicationExtension.MatchByType) as AtomPublishingEditedSyndicationExtension; if (editedExtension != null) { entry.EditedOn = editedExtension.Context.EditedOn; } AtomPublishingControlSyndicationExtension controlExtension = entry.FindExtension(AtomPublishingControlSyndicationExtension.MatchByType) as AtomPublishingControlSyndicationExtension; if (controlExtension != null) { entry.IsDraft = controlExtension.Context.IsDraft; } //------------------------------------------------------------ // Raise Loaded event to notify registered handlers of state change //------------------------------------------------------------ entry.OnEntryLoaded(new SyndicationResourceLoadedEventArgs(navigator, source, options, userToken)); } } } //------------------------------------------------------------ // Reset load operation in progress indicator //------------------------------------------------------------ entry.LoadOperationInProgress = false; } } }
/// <summary> /// Called when a corresponding asynchronous load operation completes. /// </summary> /// <param name="result">The result of the asynchronous operation.</param> private static void AsyncLoadCallback(IAsyncResult result) { System.Text.Encoding encoding = System.Text.Encoding.UTF8; XPathNavigator navigator = null; WebRequest httpWebRequest = null; AtomEntryResource entry = null; Uri source = null; WebRequestOptions options = null; SyndicationResourceLoadSettings settings = null; if (result.IsCompleted) { object[] parameters = (object[])result.AsyncState; httpWebRequest = parameters[0] as WebRequest; entry = parameters[1] as AtomEntryResource; source = parameters[2] as Uri; settings = parameters[3] as SyndicationResourceLoadSettings; options = parameters[4] as WebRequestOptions; object userToken = parameters[5]; if (entry != null) { WebResponse httpWebResponse = (WebResponse)httpWebRequest.EndGetResponse(result); using (Stream stream = httpWebResponse.GetResponseStream()) { if (settings != null) { encoding = settings.CharacterEncoding; } using (StreamReader streamReader = new StreamReader(stream, encoding)) { XmlReaderSettings readerSettings = new XmlReaderSettings(); readerSettings.IgnoreComments = true; readerSettings.IgnoreWhitespace = true; readerSettings.DtdProcessing = DtdProcessing.Ignore; using (XmlReader reader = XmlReader.Create(streamReader, readerSettings)) { if (encoding == System.Text.Encoding.UTF8) { navigator = SyndicationEncodingUtility.CreateSafeNavigator(source, options, null); } else { navigator = SyndicationEncodingUtility.CreateSafeNavigator(source, options, settings.CharacterEncoding); } SyndicationResourceAdapter adapter = new SyndicationResourceAdapter(navigator, settings); adapter.Fill(entry, SyndicationContentFormat.Atom); AtomPublishingEditedSyndicationExtension editedExtension = entry.FindExtension(AtomPublishingEditedSyndicationExtension.MatchByType) as AtomPublishingEditedSyndicationExtension; if (editedExtension != null) { entry.EditedOn = editedExtension.Context.EditedOn; } AtomPublishingControlSyndicationExtension controlExtension = entry.FindExtension(AtomPublishingControlSyndicationExtension.MatchByType) as AtomPublishingControlSyndicationExtension; if (controlExtension != null) { entry.IsDraft = controlExtension.Context.IsDraft; } entry.OnEntryLoaded(new SyndicationResourceLoadedEventArgs(navigator, source, options, userToken)); } } } entry.LoadOperationInProgress = false; } } }