Esempio 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();
        }
Esempio 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();
        }
Esempio 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);
        }
Esempio 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());
        }
Esempio n. 5
0
 public static ConnectionSingleton getInstance()
 {
     if (instance == null)
     {
         instance = new ConnectionSingleton();
     }
     return(instance);
 }
Esempio 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();
        }
Esempio 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);
 }
Esempio 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();
            }
        }
Esempio n. 9
0
 public static void closeConnection()
 {
     ConnectionSingleton.getInstance().connection.Close();
 }