/// <summary> /// When the timer elapses /// </summary> public void Elapsed(object sender, System.Timers.ElapsedEventArgs e) { #if DEBUG Trace.TraceInformation("Cleaning stale queries from database..."); #endif IDbConnection connection = m_configuration.CreateConnection(); try { connection.Open(); // Clean the query database IDbCommand cmd = connection.CreateCommand(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = "qry_cln"; IDataParameter ageParm = cmd.CreateParameter(); ageParm.DbType = DbType.String; ageParm.Direction = ParameterDirection.Input; ageParm.ParameterName = "max_age_in"; ageParm.Value = String.Format("{0} minutes", m_configuration.MaxQueryAge); cmd.Parameters.Add(ageParm); cmd.ExecuteNonQuery(); } catch (Exception ex) { Trace.TraceError(ex.ToString()); } finally { connection.Close(); connection.Dispose(); } }
/// <summary> /// Register a query set /// </summary> public bool RegisterQuerySet <TIdentifier>(string queryId, int count, Identifier <TIdentifier>[] results, object tag) { IDbConnection dbc = m_configuration.CreateConnection(); IDbTransaction tx = null; try { dbc.Open(); tx = dbc.BeginTransaction(); if (IsRegistered(queryId)) { throw new Exception(String.Format("Query '{0}' has already been registered with the QueryManager", queryId)); } // Register the query RegisterQuery(dbc, tx, queryId, count, tag); // Push each result into if (results.Length > 0) { try { int ofs = 0; while (ofs < results.Length) { PushResults(dbc, tx, queryId, results.Skip(ofs).Take(100).ToArray()); ofs += 100; } } catch (Exception e) { Trace.TraceError("Error pushing bulk: {0}", e); foreach (var id in results) { this.PushResult(dbc, tx, queryId, id); } } } tx.Commit(); // Return true return(true); } catch (Exception e) { tx.Rollback(); throw new QueryPersistenceException(e.Message, e); } finally { dbc.Close(); dbc.Dispose(); } }