Exemplo n.º 1
0
        public static void loadFrom(string filename)
        {
            SQLiteConnection connection  = ConnectionSingleton.getInstance().connection;
            SQLiteConnection connection2 = new SQLiteConnection("Data Source=" + filename + "; Version=3;");

            connection2.Open();
            ConnectionSingleton.getInstance().resetDatabase();
            new SQLiteCommand("BEGIN", connection).ExecuteNonQuery();
            SQLiteCommand    command2 = new SQLiteCommand("SELECT timeOffset, sender, packet FROM events", connection2);
            SQLiteDataReader reader2  = command2.ExecuteReader();

            while (reader2.Read())
            {
                SQLiteCommand command = new SQLiteCommand("INSERT INTO events (timeOffset, sender, packet) VALUES (@TIMEOFFSET, @SENDER, @PACKET)", connection);
                command.Parameters.AddWithValue("@TIMEOFFSET", reader2["timeOffset"]);
                command.Parameters.AddWithValue("@SENDER", reader2["sender"]);
                command.Parameters.AddWithValue("@PACKET", reader2["packet"]);
                command.ExecuteNonQuery();
            }
            command2 = new SQLiteCommand("SELECT name, value FROM properties", connection2);
            reader2  = command2.ExecuteReader();
            while (reader2.Read())
            {
                SQLiteCommand command = new SQLiteCommand("INSERT INTO properties(name, value) VALUES(@NAME, @VALUE)", connection);
                command.Parameters.AddWithValue("@NAME", reader2["name"]);
                command.Parameters.AddWithValue("@VALUE", reader2["value"]);
                command.ExecuteNonQuery();
            }
            new SQLiteCommand("COMMIT", connection).ExecuteNonQuery();
            connection2.Close();
        }
Exemplo n.º 2
0
        public void startReplaying()
        {
            SQLiteConnection connection = ConnectionSingleton.getInstance().connection;
            SQLiteCommand    command    = new SQLiteCommand("SELECT timeOffset, sender, packet FROM events", connection);

            reader = command.ExecuteReader();
        }
Exemplo n.º 3
0
        public Int64 getRecordingLength()
        {
            SQLiteConnection connection = ConnectionSingleton.getInstance().connection;
            SQLiteCommand    command    = new SQLiteCommand("SELECT MAX(timeOffset) FROM events", connection);
            Int64            length     = (Int64)command.ExecuteScalar();

            return(length);
        }
Exemplo n.º 4
0
        public string getProperty(string name)
        {
            SQLiteConnection connection = ConnectionSingleton.getInstance().connection;
            SQLiteCommand    command    = new SQLiteCommand("SELECT value FROM properties WHERE name=@NAME", connection);

            command.Parameters.AddWithValue("@NAME", name);
            return((string)command.ExecuteScalar());
        }
Exemplo n.º 5
0
 public static ConnectionSingleton getInstance()
 {
     if (instance == null)
     {
         instance = new ConnectionSingleton();
     }
     return(instance);
 }
Exemplo n.º 6
0
        public virtual void setProperty(string name, string value)
        {
            SQLiteConnection connection = ConnectionSingleton.getInstance().connection;
            SQLiteCommand    command    = new SQLiteCommand("INSERT OR REPLACE INTO properties(name, value) VALUES(@NAME, @VALUE)", connection);

            command.Parameters.AddWithValue("@NAME", name);
            command.Parameters.AddWithValue("@VALUE", value);
            command.ExecuteNonQuery();
        }
Exemplo n.º 7
0
 public virtual void startRecording()
 {
     ConnectionSingleton.getInstance().resetDatabase();
     stopwatch = new Stopwatch();
     stopwatch.Start();
     commitCounter = 0;
     transaction   = ConnectionSingleton.getInstance().connection.BeginTransaction();
     record(null, REGISTER);
 }
Exemplo n.º 8
0
        public virtual void record(IPAddress sender, string eventText)
        {
            long             timeOffset = stopwatch.ElapsedMilliseconds;
            SQLiteConnection connection = ConnectionSingleton.getInstance().connection;
            SQLiteCommand    command    = new SQLiteCommand("INSERT INTO events (timeOffset, sender, packet) VALUES (@TIMEOFFSET, @SENDER, @PACKET)", connection);

            command.Parameters.AddWithValue("@TIMEOFFSET", timeOffset);
            command.Parameters.AddWithValue("@SENDER", sender);
            command.Parameters.AddWithValue("@PACKET", eventText);
            int returnValue = command.ExecuteNonQuery();

            if (returnValue != 1)
            {
                throw new Exception("Warning: event not inserted + " + command.ToString());
            }
            commitCounter++;
            if (commitCounter > COMMIT_PERIOD)
            {
                commitCounter = 0;
                transaction.Commit();
                transaction = connection.BeginTransaction();
            }
        }
Exemplo n.º 9
0
 public static void closeConnection()
 {
     ConnectionSingleton.getInstance().connection.Close();
 }