Exemplo n.º 1
0
		public void CreateLanefile (WebServiceLogin login, int lane_id, string filename)
		{
			if (string.IsNullOrEmpty (filename))
				throw new ArgumentException ("filename");

			if (lane_id <= 0)
				throw new ArgumentException ("lane_id");

			using (DB db = new DB ()) {
				VerifyUserInRole (db, login, Roles.Administrator);
				db.Audit (login, "WebServices.CreateLaneFile (lane_id: {0}, filename: {1})", lane_id, filename);

				DBLanefile file = new DBLanefile ();
				file.name = filename;
				file.contents = "#!/bin/bash -ex\n\n#Your commands here\n";
				file.mime = "text/plain";
				file.Save (db);

				DBLanefiles lanefile = new DBLanefiles ();
				lanefile.lane_id = lane_id;
				lanefile.lanefile_id = file.id;
				lanefile.Save (db);

				// TODO: Check if filename already exists.
			}
		}
Exemplo n.º 2
0
		public void EditLaneFile (WebServiceLogin login, DBLanefile lanefile)
		{
			using (DB db = new DB ()) {
				VerifyUserInRole (db, login, Roles.Administrator);

				DBLanefile original = DBLanefile_Extensions.Create (db, lanefile.id);

				if (original.original_id == null) {// This is the latest version of the file
					DBLanefile old_file = new DBLanefile ();
					old_file.contents = lanefile.contents;
					old_file.mime = lanefile.mime;
					old_file.name = lanefile.name;
					old_file.original_id = lanefile.id;
					old_file.changed_date = DBRecord.DatabaseNow;
					old_file.Save (db);

					lanefile.Save (db);
				} else {
					throw new ApplicationException ("You can only change the newest version of a lane file.");
				}
			}
		}
Exemplo n.º 3
0
		public DBLane CloneLane (int lane_id, string new_name, bool copy_files)
		{
			DBLane result = null;
			DBLane master = DBLane_Extensions.Create (this, lane_id);

			if (this.LookupLane (new_name, false) != null)
				throw new Exception (string.Format ("The lane '{0}' already exists.", new_name));

			try {
				using (IDbTransaction transaction = BeginTransaction ()) {
					result = new DBLane ();
					result.lane = new_name;
					result.max_revision = master.max_revision;
					result.min_revision = master.min_revision;
					result.repository = master.repository;
					result.source_control = master.source_control;
					result.parent_lane_id = master.parent_lane_id;
					result.enabled = master.enabled;
					result.Save (this);

					foreach (DBLanefile filemaster in master.GetFiles (this, null)) {
						int fid;

						if (copy_files) {
							DBLanefile clone = new DBLanefile ();
							clone.contents = filemaster.contents;
							clone.mime = filemaster.mime;
							clone.name = filemaster.name;
							clone.Save (this);
							fid = clone.id;
						} else {
							fid = filemaster.id;
						}

						DBLanefiles lane_files = new DBLanefiles ();
						lane_files.lane_id = result.id;
						lane_files.lanefile_id = fid;
						lane_files.Save (this);
					}

					foreach (DBCommand cmdmaster in GetCommands (master.id)) {
						DBCommand clone = new DBCommand ();
						clone.lane_id = result.id;
						clone.alwaysexecute = cmdmaster.alwaysexecute;
						clone.arguments = cmdmaster.arguments;
						clone.command = cmdmaster.command;
						clone.filename = cmdmaster.filename;
						clone.nonfatal = cmdmaster.nonfatal;
						clone.sequence = cmdmaster.sequence;
						clone.timeout = cmdmaster.timeout;
						clone.working_directory = cmdmaster.working_directory;
						clone.upload_files = cmdmaster.upload_files;
						clone.Save (this);
					}

					foreach (DBHostLaneView hostlanemaster in master.GetHosts (this)) {
						DBHostLane clone = new DBHostLane ();
						clone.enabled = false;
						clone.lane_id = result.id;
						clone.host_id = hostlanemaster.host_id;
						clone.Save (this);
					}

					foreach (DBEnvironmentVariable env in master.GetEnvironmentVariables (this)) {
						DBEnvironmentVariable clone = new DBEnvironmentVariable ();
						clone.host_id = env.host_id;
						clone.lane_id = result.id;
						clone.name = env.name;
						clone.value = env.value;
						clone.Save (this);
					}

					foreach (DBLaneNotification notification in master.GetNotifications (this)) {
						DBLaneNotification clone = new DBLaneNotification ();
						clone.lane_id = result.id;
						clone.notification_id = notification.notification_id;
						clone.Save (this);
					}

					foreach (var tag in master.GetTags (this)) {
						var clone = new DBLaneTag ();
						clone.lane_id = result.id;
						clone.tag = tag.tag;
						clone.Save (this);
					}

					transaction.Commit ();
				}
			} catch {
				result = null;
				throw;
			}

			return result;
		}