Click here to Skip to main content
Click here to Skip to main content
Articles » Database » Database » SQL Server » Downloads
 
Add your own
alternative version

SQLite Compare Utility

, 6 Jul 2011
Utility for comparing two SQLite database files for both structure and data
SQLiteCompare.zip
SQLiteCompare
gplex.exe
gplexx.frame
gppg.exe
license.lic
log4net.dll
Puzzle.SyntaxBox.NET3.5.dll
ShiftReduceParser.dll
SQLiteTurboDiff.suo
System.Data.SQLite.dll
AutomaticUpdates
Properties
Be.Windows.Forms.HexBox
HexBox.bmp
HexBox.snk
Thumbs.db
Design
Common
Properties
CreateTestDatabases
Properties
TestSchemaFiles
DiffControl
Properties
FastGrid
Properties
Settings.settings
Liron.Windows.Forms
multipanel.ico
Thumbs.db
Design
Properties
Setup
appicon.ico
finish_banner.bmp
installer_banner.bmp
setup.nsi
Thumbs.db
uninstallicon.ico
SQLiteParser
sqlite.lex
sqlite.y
Properties
SQLiteTurbo
sqlite.syn
SQLiteTurbo.csproj.user
Properties
Settings.settings
Resources
feedback2.png
feedback_non_selected_idea.png
feedback_non_selected_question.png
feedback_pressed.png
feedback_problem_non_selected.png
feedback_problem_selected.png
feedback_selected_idea.png
feedback_selected_question.png
normal_feedback_button.png
pressed_feedback_button.png
SVG
about.svg
accept.svg
app.svg
appicon.svg
bug.svg
check_updates.svg
close_comparison.svg
company_tagline.svg
compare.svg
copy_from_left_db.svg
copy_from_right_db.svg
edit_selected_difference.svg
feather.svg
feedback.svg
feedback_frame.svg
feedback_non_selected_idea.svg
feedback_non_selected_problem.svg
feedback_question.svg
feedback_selected_problem.svg
feedback_selected_question.svg
finish_page_banner.svg
free.svg
generate_script_left_to_right.svg
generate_script_right_to_left.svg
greenpinesoftware_logo.svg
home_screenshot.svg
installer_banner.svg
key.svg
lamp.svg
lamp_non_selected.svg
lamp_selected.svg
lock.svg
main_screen.svg
next_diff.svg
prev_diff.svg
question.svg
recycle_bin.svg
redo.svg
reject.svg
reorder_columns.svg
save_schema.svg
search.svg
smallbug.svg
sqlite_compare_logo.svg
sqlite_feather.svg
text2451.png
undo.svg
uninstall.svg
v_bullet.svg
UndoRedo
Properties
SQLiteCompareSetup.zip
SQLiteCompare_src.zip
gplex.exe
gplexx.frame
gppg.exe
license.lic
log4net.dll
Puzzle.SyntaxBox.NET3.5.dll
ShiftReduceParser.dll
SQLiteTurboDiff.suo
System.Data.SQLite.dll
HexBox.bmp
HexBox.snk
Thumbs.db
Settings.settings
multipanel.ico
Thumbs.db
appicon.ico
finish_banner.bmp
installer_banner.bmp
setup.nsi
Thumbs.db
uninstallicon.ico
sqlite.lex
sqlite.y
sqlite.syn
SQLiteTurbo.csproj.user
Settings.settings
feedback2.png
feedback_non_selected_idea.png
feedback_non_selected_question.png
feedback_pressed.png
feedback_problem_non_selected.png
feedback_problem_selected.png
feedback_selected_idea.png
feedback_selected_question.png
normal_feedback_button.png
pressed_feedback_button.png
about.svg
accept.svg
app.svg
appicon.svg
bug.svg
check_updates.svg
close_comparison.svg
company_tagline.svg
compare.svg
copy_from_left_db.svg
copy_from_right_db.svg
edit_selected_difference.svg
feather.svg
feedback.svg
feedback_frame.svg
feedback_non_selected_idea.svg
feedback_non_selected_problem.svg
feedback_question.svg
feedback_selected_problem.svg
feedback_selected_question.svg
finish_page_banner.svg
free.svg
generate_script_left_to_right.svg
generate_script_right_to_left.svg
greenpinesoftware_logo.svg
home_screenshot.svg
installer_banner.svg
key.svg
lamp.svg
lamp_non_selected.svg
lamp_selected.svg
lock.svg
main_screen.svg
next_diff.svg
prev_diff.svg
question.svg
recycle_bin.svg
redo.svg
reject.svg
reorder_columns.svg
save_schema.svg
search.svg
smallbug.svg
sqlite_compare_logo.svg
sqlite_feather.svg
text2451.png
undo.svg
uninstall.svg
v_bullet.svg
using System;
using System.IO;
using System.Collections.Generic;
using System.Text;
using System.Runtime.Serialization.Formatters.Binary;

namespace UndoRedo
{
    /// <summary>
    /// Supports undoable actions.
    /// </summary>
    public class UndoManager
    {
        #region Events
        /// <summary>
        /// Fired whenever the undo manager changes state
        /// </summary>
        public event EventHandler UndoStateChanged;
        #endregion

        #region Public Properties
        /// <summary>
        /// Get TRUE if there are actions to be undone
        /// </summary>
        public bool CanUndo
        {
            get
            {
                return _undoList.Count > 0;
            }
        }

        /// <summary>
        /// Get TRUE if there are actions to be redone
        /// </summary>
        public bool CanRedo
        {
            get
            {
                return _redoList.Count > 0;
            }
        }

        /// <summary>
        /// Get the undo action description
        /// </summary>
        public string UndoActionDescription
        {
            get
            {
                if (_undoList.Count > 0)
                    return _undoList[_undoList.Count - 1].Name;
                else
                    return string.Empty;
            }
        }

        /// <summary>
        /// Get the redo action description
        /// </summary>
        public string RedoActionDescription
        {
            get
            {
                if (_redoList.Count > 0)
                    return _redoList[_redoList.Count - 1].Name;
                else
                    return string.Empty;
            }
        }

        /// <summary>
        /// Get the list of actions that were performed in the manager
        /// </summary>
        public List<ActionRecord> ActionsHistory
        {
            get { return _actionsHistory; }
        }
        #endregion

        #region Public Methods

        /// <summary>
        /// Clear all undoable actions
        /// </summary>
        public void Clear()
        {
            _undoList.Clear();
            _redoList.Clear();
            _actionsHistory.Clear();

            if (UndoStateChanged != null)
                UndoStateChanged(this, EventArgs.Empty);
        }

        /// <summary>
        /// Do the specified action while updating the internal undo/redo lists.
        /// </summary>
        /// <param name="action">The action to perform</param>
        public void Do(UndoableAction action)
        {
            // Do the action
            action.Do(false);

            // Clear the redo list
            _redoList.Clear();

            // Add the action to the undo list.
            _undoList.Add(action);

            // Add action record to the history log
            ActionRecord ar = new ActionRecord(DateTime.Now, action.Name, 
                action.Description, ActionType.Do);
            _actionsHistory.Add(ar);

            // Notify that the state of the undo manager has changed
            if (UndoStateChanged != null)
                UndoStateChanged(this, EventArgs.Empty);
        }

        /// <summary>
        /// Undo the most recent action
        /// </summary>
        public void Undo()
        {
            if (_undoList.Count == 0)
                return;

            // Get the most recent action
            UndoableAction action = _undoList[_undoList.Count - 1];

            // Undo that action
            action.Undo();

            // Remove the action from the undo list and add it to the redo list.
            _undoList.Remove(action);
            _redoList.Add(action);

            // Add action record to the history log
            ActionRecord ar = new ActionRecord(DateTime.Now, action.Name, 
                action.Description, ActionType.Undo);
            _actionsHistory.Add(ar);

            // Notify that the state of the undo manager has changed
            if (UndoStateChanged != null)
                UndoStateChanged(this, EventArgs.Empty);
        }

        /// <summary>
        /// Redo the last action.
        /// </summary>
        public void Redo()
        {
            if (_redoList.Count == 0)
                return;

            // Get the latest action to redo
            UndoableAction action = _redoList[_redoList.Count - 1];

            // Redo that action
            action.Do(true);

            // Remove the action from the redo list and add it to the undo list
            _redoList.Remove(action);
            _undoList.Add(action);

            // Add action record to the history log
            ActionRecord ar = new ActionRecord(DateTime.Now, action.Name, 
                action.Description, ActionType.Redo);
            _actionsHistory.Add(ar);

            // Notify that the state of the undo manager has changed
            if (UndoStateChanged != null)
                UndoStateChanged(this, EventArgs.Empty);
        }

        /// <summary>
        /// Returns a list of actions that were saved into a history file.
        /// </summary>
        /// <param name="fpath">The path to the file that contains the actions.</param>
        /// <returns>The list of action records that were recorded in the file.</returns>
        public List<ActionRecord> LoadActionsHistory(string fpath)
        {
            BinaryFormatter s = new BinaryFormatter();
            using (FileStream fs = File.OpenRead(fpath))
            {
                object obj = s.Deserialize(fs);
                return obj as List<ActionRecord>;
            } // using
        }

        /// <summary>
        /// Saves the specified list of action records into the specified file.
        /// </summary>
        /// <param name="fpath">The path to the history file.</param>
        /// <param name="history">The list of actions history to save</param>
        public void SaveActionsHistory(string fpath, List<ActionRecord> history)
        {
            BinaryFormatter s = new BinaryFormatter();
            using (FileStream fs = File.Open(fpath, FileMode.Create))
            {
                s.Serialize(fs, history);
            } // using
        }
        #endregion

        #region Private Variables
        private List<UndoableAction> _undoList = new List<UndoableAction>();
        private List<UndoableAction> _redoList = new List<UndoableAction>();
        private List<ActionRecord> _actionsHistory = new List<ActionRecord>();
        #endregion
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)

Share

About the Author

liron.levi
Software Developer Arineta Cardio Imaging
Israel Israel
My name is Liron Levi and I'm developing software for fun & profit for 15 years already. I'm now working for Arineta Cardio Imaging as a software developer (the company develops a CT machine).
 
I can be contacted directly at liron.levi@outlook.com or via linkedin at http://www.linkedin.com/pub/liron-levy/1/578/ab5

| Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 6 Jul 2011
Article Copyright 2011 by liron.levi
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid