internal void LoadHistoryStream(MemoryStream loadStream, bool firstLoadFromHistory)
 {
     if (Application.Current == null)
     {
         return;
     }
     ApplicationProxyInternal.LoadHistoryStreamInfo loadHistoryStreamInfo = new ApplicationProxyInternal.LoadHistoryStreamInfo();
     loadHistoryStreamInfo.loadStream           = loadStream;
     loadHistoryStreamInfo.firstLoadFromHistory = firstLoadFromHistory;
     Application.Current.Dispatcher.Invoke(DispatcherPriority.Send, new DispatcherOperationCallback(this._LoadHistoryStreamDelegate), loadHistoryStreamInfo);
 }
        private object _LoadHistoryStreamDelegate(object arg)
        {
            ApplicationProxyInternal.LoadHistoryStreamInfo loadHistoryStreamInfo = (ApplicationProxyInternal.LoadHistoryStreamInfo)arg;
            if (this.IsShutdown())
            {
                return(null);
            }
            loadHistoryStreamInfo.loadStream.Seek(0L, SeekOrigin.Begin);
            object obj = this.DeserializeJournaledObject(loadHistoryStreamInfo.loadStream);

            if (loadHistoryStreamInfo.firstLoadFromHistory)
            {
                if (!(obj is ApplicationProxyInternal.BrowserJournal))
                {
                    return(null);
                }
                ApplicationProxyInternal.BrowserJournal browserJournal = (ApplicationProxyInternal.BrowserJournal)obj;
                Journal      journal      = browserJournal.Journal;
                JournalEntry journalEntry = journal.CurrentEntry;
                if (journalEntry == null)
                {
                    journalEntry = journal.GetGoBackEntry();
                }
                NavigationService navigationService = this._rbw.Value.NavigationService;
                this._rbw.Value.SetJournalForBrowserInterop(journal);
                if (BindUriHelper.BaseUri == null)
                {
                    BindUriHelper.BaseUri = browserJournal.BaseUri;
                }
                if (journalEntry != null)
                {
                    Application.Current.Startup += this.OnStartup;
                    this._rbw.Value.JournalNavigationScope.NavigateToEntry(journalEntry);
                }
            }
            else
            {
                if (!(obj is int))
                {
                    return(null);
                }
                Journal journal = this._rbw.Value.Journal;
                int     index   = journal.FindIndexForEntryWithId((int)obj);
                if (!this._rbw.Value.JournalNavigationScope.NavigateToEntry(index))
                {
                    throw new OperationCanceledException();
                }
            }
            return(null);
        }