internal void WriteEndTimeForFeature(FeatureUse featureUse)
 {
     lock (lockObj) {
         if (isDisposed)
         {
             return;
         }
         featureUse.endTime = GetNow();
         delayedEnd.Enqueue(featureUse);
     }
 }
        void FlushOutstandingChanges()
        {
            //Console.WriteLine("Flushing {0} starts and {1} ends", delayedStart.Count, delayedEnd.Count);
            if (delayedStart.Count == 0 && delayedEnd.Count == 0)
            {
                return;
            }
            using (SQLiteTransaction transaction = this.connection.BeginTransaction()) {
                if (delayedStart.Count > 0)
                {
                    using (SQLiteCommand cmd = this.connection.CreateCommand()) {
                        cmd.CommandText = "INSERT INTO FeatureUses (session, time, feature, activationMethod)" +
                                          "    VALUES (?, ?, ?, ?);" +
                                          "SELECT last_insert_rowid();";
                        SQLiteParameter time, feature, activationMethod;
                        cmd.Parameters.Add(new SQLiteParameter()
                        {
                            Value = sessionID
                        });
                        cmd.Parameters.Add(time             = new SQLiteParameter());
                        cmd.Parameters.Add(feature          = new SQLiteParameter());
                        cmd.Parameters.Add(activationMethod = new SQLiteParameter());
                        while (delayedStart.Count > 0)
                        {
                            FeatureUse use = delayedStart.Dequeue();
                            time.Value             = TimeToString(use.startTime);
                            feature.Value          = use.name;
                            activationMethod.Value = use.activation;

                            use.rowId = (long)cmd.ExecuteScalar();
                        }
                    }
                }
                if (delayedEnd.Count > 0)
                {
                    using (SQLiteCommand cmd = this.connection.CreateCommand()) {
                        cmd.CommandText = "UPDATE FeatureUses SET endTime = ? WHERE id = ?;";
                        SQLiteParameter endTime, id;
                        cmd.Parameters.Add(endTime = new SQLiteParameter());
                        cmd.Parameters.Add(id      = new SQLiteParameter());
                        while (delayedEnd.Count > 0)
                        {
                            FeatureUse use = delayedEnd.Dequeue();
                            endTime.Value = TimeToString(use.endTime);
                            id.Value      = use.rowId;
                            cmd.ExecuteNonQuery();
                        }
                    }
                }
                transaction.Commit();
            }
        }
        /// <summary>
        /// Adds a feature use to the session.
        /// </summary>
        /// <param name="featureName">Name of the feature.</param>
        /// <param name="activationMethod">How the feature was activated (Menu, Toolbar, Shortcut, etc.)</param>
        public FeatureUse AddFeatureUse(string featureName, string activationMethod)
        {
            if (featureName == null)
            {
                throw new ArgumentNullException("featureName");
            }

            lock (lockObj) {
                if (isDisposed)
                {
                    throw new ObjectDisposedException(GetType().Name);
                }
                FeatureUse featureUse = new FeatureUse(this, GetNow());
                featureUse.name       = featureName;
                featureUse.activation = activationMethod;
                delayedStart.Enqueue(featureUse);
                return(featureUse);
            }
        }
 internal void WriteEndTimeForFeature(FeatureUse featureUse)
 {
     lock (lockObj) {
         if (isDisposed)
             return;
         featureUse.endTime = GetNow();
         delayedEnd.Enqueue(featureUse);
     }
 }
        /// <summary>
        /// Adds a feature use to the session.
        /// </summary>
        /// <param name="featureName">Name of the feature.</param>
        /// <param name="activationMethod">How the feature was activated (Menu, Toolbar, Shortcut, etc.)</param>
        public FeatureUse AddFeatureUse(string featureName, string activationMethod)
        {
            if (featureName == null)
                throw new ArgumentNullException("featureName");

            lock (lockObj) {
                if (isDisposed)
                    throw new ObjectDisposedException(GetType().Name);
                FeatureUse featureUse = new FeatureUse(this, GetNow());
                featureUse.name = featureName;
                featureUse.activation = activationMethod;
                delayedStart.Enqueue(featureUse);
                return featureUse;
            }
        }