本文整理汇总了C#中DB.GetCommands方法的典型用法代码示例。如果您正苦于以下问题:C# DB.GetCommands方法的具体用法?C# DB.GetCommands怎么用?C# DB.GetCommands使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DB
的用法示例。
在下文中一共展示了DB.GetCommands方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddWork
private static void AddWork (DB db, List<DBHost> hosts, List<DBLane> lanes, List<DBHostLane> hostlanes)
{
DateTime start = DateTime.Now;
List<DBCommand> commands = null;
List<DBLaneDependency> dependencies = null;
List<DBCommand> commands_in_lane;
List<DBRevisionWork> revisionwork_without_work = new List<DBRevisionWork> ();
DBHostLane hostlane;
StringBuilder sql = new StringBuilder ();
bool fetched_dependencies = false;
int lines = 0;
try {
/* Find the revision works which don't have work yet */
using (IDbCommand cmd = db.CreateCommand ()) {
cmd.CommandText = "SELECT * FROM RevisionWork WHERE state = 10;";
using (IDataReader reader = cmd.ExecuteReader ()) {
while (reader.Read ()) {
revisionwork_without_work.Add (new DBRevisionWork (reader));
}
}
}
log.InfoFormat ("AddWork: Got {0} hosts and {1} revisionwork without work", hosts.Count, revisionwork_without_work.Count);
foreach (DBLane lane in lanes) {
commands_in_lane = null;
foreach (DBHost host in hosts) {
hostlane = null;
for (int i = 0; i < hostlanes.Count; i++) {
if (hostlanes [i].lane_id == lane.id && hostlanes [i].host_id == host.id) {
hostlane = hostlanes [i];
break;
}
}
if (hostlane == null) {
log.DebugFormat ("AddWork: Lane '{0}' is not configured for host '{1}', not adding any work.", lane.lane, host.host);
continue;
} else if (!hostlane.enabled) {
log.DebugFormat ("AddWork: Lane '{0}' is disabled for host '{1}', not adding any work.", lane.lane, host.host);
continue;
}
log.InfoFormat ("AddWork: Lane '{0}' is enabled for host '{1}', adding work!", lane.lane, host.host);
foreach (DBRevisionWork revisionwork in revisionwork_without_work) {
bool has_dependencies;
/* revisionwork_without_work contains rw for all hosts/lanes, filter out the ones we want */
if (revisionwork.host_id != host.id || revisionwork.lane_id != lane.id)
continue;
/* Get commands and dependencies for all lanes only if we know we'll need them */
if (commands == null)
commands = db.GetCommands (0);
if (commands_in_lane == null) {
commands_in_lane = new List<DBCommand> ();
CollectWork (commands_in_lane, lanes, lane, commands);
}
if (!fetched_dependencies) {
fetched_dependencies = true;
dependencies = DBLaneDependency_Extensions.GetDependencies (db, null);
}
has_dependencies = dependencies != null && dependencies.Any (dep => dep.lane_id == lane.id);
log.DebugFormat ("AddWork: Lane '{0}', revisionwork_id '{1}' has dependencies: {2}", lane.lane, revisionwork.id, has_dependencies);
foreach (DBCommand command in commands_in_lane) {
int work_state = (int) (has_dependencies ? DBState.DependencyNotFulfilled : DBState.NotDone);
sql.AppendFormat ("INSERT INTO Work (command_id, revisionwork_id, state) VALUES ({0}, {1}, {2});\n", command.id, revisionwork.id, work_state);
lines++;
log.DebugFormat ("Lane '{0}', revisionwork_id '{1}' Added work for command '{2}'", lane.lane, revisionwork.id, command.command);
if ((lines % 100) == 0) {
db.ExecuteNonQuery (sql.ToString ());
sql.Clear ();
log.DebugFormat ("AddWork: flushed work queue, added {0} items now.", lines);
}
}
sql.AppendFormat ("UPDATE RevisionWork SET state = {0} WHERE id = {1} AND state = 10;", (int) (has_dependencies ? DBState.DependencyNotFulfilled : DBState.NotDone), revisionwork.id);
}
}
}
if (sql.Length > 0)
db.ExecuteNonQuery (sql.ToString ());
} catch (Exception ex) {
log.ErrorFormat ("AddWork: {0}", ex);
}
log.InfoFormat ("AddWork: [Done in {0} seconds]", (DateTime.Now - start).TotalSeconds);
}
示例2: GetCommands
public GetCommandsResponse GetCommands (WebServiceLogin login, int lane_id)
{
GetCommandsResponse response = new GetCommandsResponse ();
using (DB db = new DB ()) {
Authenticate (db, login, response, true);
response.Commands = db.GetCommands (lane_id);
}
return response;
}
示例3: UpdateBuildLogDB
private static void UpdateBuildLogDB (DB db, DBLane lane, List<DBHost> hosts, List<DBHostLane> hostlanes)
{
List<DBRevision> revisions;
List<DBCommand> commands = null;
List<DBLaneDependency> dependencies = null;
DBHostLane hostlane;
DBWork work;
bool got_dependencies = false;
bool got_commands = false;
try {
Logger.Log ("Updating build db log... Got {0} hosts", hosts.Count);
foreach (DBHost host in hosts) {
hostlane = null;
for (int i = 0; i < hostlanes.Count; i++) {
if (hostlanes [i].lane_id == lane.id && hostlanes [i].host_id == host.id) {
hostlane = hostlanes [i];
break;
}
}
if (hostlane == null) {
Logger.Log ("Lane '{0}' is not configured for host '{1}', not adding any work.", lane.lane, host.host);
continue;
} else if (!hostlane.enabled) {
Logger.Log ("Lane '{0}' is disabled for host '{1}', not adding any work.", lane.lane, host.host);
continue;
}
AddRevisionWork (db, lane, host);
revisions = db.GetDBRevisionsWithoutWork (lane.id, host.id);
Logger.Log ("Updating build db log... Got {0} revisions for host {1}", revisions.Count, host.host);
foreach (DBRevision revision in revisions) {
bool dependencies_satisfied = true;
if (!got_commands) {
commands = db.GetCommands (lane.id);
got_commands = true;
}
if (!got_dependencies) {
dependencies = DBLaneDependency_Extensions.GetDependencies (db, lane);
got_dependencies = true;
}
if (dependencies != null) {
Logger.Log ("Lane '{0}', revision '{1}' checking dependencies...", lane.lane, revision.revision);
foreach (DBLaneDependency dependency in dependencies)
dependencies_satisfied &= dependency.IsSuccess (db, revision.revision);
Logger.Log ("Lane '{0}', revision '{1}' dependency checking resulted in: {2}.", lane.lane, revision.revision, dependencies_satisfied);
}
int revisionwork_id;
bool pending_dependencies;
using (IDbCommand cmd = db.CreateCommand ()) {
cmd.CommandText = "SELECT add_revisionwork (@lane_id, @host_id, @revision_id);";
DB.CreateParameter (cmd, "lane_id", lane.id);
DB.CreateParameter (cmd, "host_id", host.id);
DB.CreateParameter (cmd, "revision_id", revision.id);
revisionwork_id = (int) cmd.ExecuteScalar ();
}
using (IDbCommand cmd = db.CreateCommand ()) {
cmd.CommandText = "SELECT state FROM RevisionWork WHERE id = @id;";
DB.CreateParameter (cmd, "id", revisionwork_id);
pending_dependencies = (int) DBState.DependencyNotFulfilled == (int) cmd.ExecuteScalar ();
}
if (pending_dependencies && !dependencies_satisfied)
continue;
Logger.Log ("Pending dependencies: {0}", pending_dependencies);
foreach (DBCommand command in commands) {
work = null;
if (pending_dependencies) {
using (IDbCommand cmd = db.CreateCommand ()) {
cmd.CommandText = "SELECT * FROM Work WHERE revisionwork_id = @revisionwork_id AND command_id = @command_id;";
DB.CreateParameter (cmd, "revisionwork_id", revisionwork_id);
DB.CreateParameter (cmd, "command_id", command.id);
using (IDataReader reader = cmd.ExecuteReader ()) {
if (reader.Read ())
work = new DBWork (reader);
}
}
}
if (work == null) {
work = new DBWork ();
work.command_id = command.id;
work.revisionwork_id = revisionwork_id;
}
work.State = dependencies_satisfied ? DBState.NotDone : DBState.DependencyNotFulfilled;
work.Save (db);
Logger.Log ("Saved revision {0}, host {2}, command {1}", revision.revision, command.command, host.host);
//.........这里部分代码省略.........