internal byte[] GetSaveHistoryBytes(bool persistEntireJournal, out int journalEntryId, out string uriString, out string titleString)
 {
     ApplicationProxyInternal.SaveHistoryReturnInfo saveHistoryReturnInfo = null;
     if (Application.Current != null)
     {
         saveHistoryReturnInfo = (ApplicationProxyInternal.SaveHistoryReturnInfo)Application.Current.Dispatcher.Invoke(DispatcherPriority.Send, new DispatcherOperationCallback(this._GetSaveHistoryBytesDelegate), persistEntireJournal);
     }
     if (saveHistoryReturnInfo != null)
     {
         journalEntryId = saveHistoryReturnInfo.entryId;
         uriString      = saveHistoryReturnInfo.uri;
         titleString    = saveHistoryReturnInfo.title;
         return(saveHistoryReturnInfo.saveByteArray);
     }
     journalEntryId = 0;
     uriString      = null;
     titleString    = null;
     return(null);
 }
        private object _GetSaveHistoryBytesDelegate(object arg)
        {
            bool flag = (bool)arg;

            ApplicationProxyInternal.SaveHistoryReturnInfo saveHistoryReturnInfo = new ApplicationProxyInternal.SaveHistoryReturnInfo();
            if (this._serviceProvider == null)
            {
                return(null);
            }
            if (Application.IsApplicationObjectShuttingDown)
            {
                return(null);
            }
            Invariant.Assert(this._rbw.Value != null, "BrowserJournalingError: _rbw should not be null");
            Journal journal = this._rbw.Value.Journal;

            Invariant.Assert(journal != null, "BrowserJournalingError: Could not get internal journal for the window");
            JournalEntry journalEntry;

            if (flag)
            {
                NavigationService navigationService = this._rbw.Value.NavigationService;
                try
                {
                    navigationService.RequestCustomContentStateOnAppShutdown();
                }
                catch (Exception ex)
                {
                    if (CriticalExceptions.IsCriticalException(ex))
                    {
                        throw;
                    }
                }
                journal.PruneKeepAliveEntries();
                journalEntry = navigationService.MakeJournalEntry(JournalReason.NewContentNavigation);
                if (journalEntry != null && !journalEntry.IsAlive())
                {
                    if (journalEntry.JEGroupState.JournalDataStreams != null)
                    {
                        journalEntry.JEGroupState.JournalDataStreams.PrepareForSerialization();
                    }
                    journal.UpdateCurrentEntry(journalEntry);
                }
                else
                {
                    journalEntry = journal.GetGoBackEntry();
                }
            }
            else
            {
                journalEntry = journal.CurrentEntry;
            }
            if (journalEntry != null)
            {
                saveHistoryReturnInfo.title   = journalEntry.Name;
                saveHistoryReturnInfo.entryId = journalEntry.Id;
            }
            else
            {
                saveHistoryReturnInfo.title = this._rbw.Value.Title;
            }
            saveHistoryReturnInfo.uri = BindUriHelper.UriToString(this.Uri);
            MemoryStream memoryStream = new MemoryStream();

            memoryStream.Seek(0L, SeekOrigin.Begin);
            if (flag)
            {
                ApplicationProxyInternal.BrowserJournal browserJournal = new ApplicationProxyInternal.BrowserJournal(journal, BindUriHelper.BaseUri);
                new SecurityPermission(SecurityPermissionFlag.SerializationFormatter).Assert();
                try
                {
                    memoryStream.WriteByte(2);
                    BinaryFormatter binaryFormatter = new BinaryFormatter();
                    binaryFormatter.Serialize(memoryStream, browserJournal);
                    goto IL_1A6;
                }
                catch (Exception ex2)
                {
                    if (CriticalExceptions.IsCriticalException(ex2))
                    {
                        throw;
                    }
                    Invariant.Assert(false, "Failed to serialize the navigation journal: " + ex2);
                    goto IL_1A6;
                }
                finally
                {
                    CodeAccessPermission.RevertAll();
                }
            }
            memoryStream.WriteByte(1);
            ApplicationProxyInternal.WriteInt32(memoryStream, saveHistoryReturnInfo.entryId);
IL_1A6:
            saveHistoryReturnInfo.saveByteArray = memoryStream.ToArray();
            ((IDisposable)memoryStream).Dispose();
            return(saveHistoryReturnInfo);
        }