public WebServiceResponse AddRelease (WebServiceLogin login, DBRelease release)
		{
			WebServiceResponse response = new WebServiceResponse ();

			using (DB db = new DB ()) {
				VerifyUserInRole (db, login, Roles.BuildBot);
				release.Save (db);
			}

			return response;
		}
Example #2
0
		public WebServiceResponse AddRelease (WebServiceLogin login, DBRelease release)
		{
			WebServiceResponse response = new WebServiceResponse ();

			try {
				using (DB db = new DB ()) {
					VerifyUserInRole (db, login, Roles.BuildBot);
					release.Save (db);
				}
			} catch (Exception ex) {
				response.Exception = new WebServiceException (ex);
			}

			return response;
		}
		public ReportBuildBotStatusResponse ReportBuildBotStatus (WebServiceLogin login, BuildBotStatus status)
		{
			ReportBuildBotStatusResponse response = new ReportBuildBotStatusResponse ();

			using (DB db = new DB ()) {
				VerifyUserInRole (db, login, Roles.BuildBot, true);

				log.DebugFormat ("BuildBot '{2}' reported in. v{0}: {1}", status.AssemblyVersion, status.AssemblyDescription, status.Host);

				using (IDbCommand cmd = db.CreateCommand ()) {
					cmd.CommandText = @"
DELETE FROM BuildBotStatus WHERE host_id = (SELECT id FROM Host WHERE host = @host);
INSERT INTO BuildBotStatus (host_id, version, description) VALUES ((SELECT id FROM Host WHERE host = @host), @version, @description);
";
					DB.CreateParameter (cmd, "host", status.Host);
					DB.CreateParameter (cmd, "version", status.AssemblyVersion);
					DB.CreateParameter (cmd, "description", status.AssemblyDescription);
					cmd.ExecuteNonQuery ();
				}
				using (IDbCommand cmd = db.CreateCommand ()) {
					cmd.CommandText = "SELECT * FROM Release INNER JOIN Host ON Host.release_id = Release.id WHERE Host.host = @host;";
					DB.CreateParameter (cmd, "host", status.Host);
					using (IDataReader reader = cmd.ExecuteReader ()) {
						if (reader.Read ()) {
							DBRelease release = new DBRelease (reader);
							response.ConfiguredVersion = release.version;
							response.ConfiguredRevision = release.revision;
						}
					}
				}
			}

			return response;
		}
Example #4
0
		static void CheckLog (string log_file, BuildInfo info)
		{
			DBRelease release = null;
			string line, l;
			string cmd;
			int index;

			using (FileStream fs = new FileStream (log_file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
				using (StreamReader reader = new StreamReader (fs)) {
					List<String> files = new List<string> ();
					List<bool> hidden = new List<bool> ();

					while (null != (l = reader.ReadLine ())) {
						line = l;
						if (line.StartsWith ("@Moonbuilder:")) {
							line = line.Substring ("@Moonbuilder:".Length);
						} else if (line.StartsWith ("@MonkeyWrench:")) {
							line = line.Substring ("@MonkeyWrench:".Length);
						} else {
							continue;
						}

						line = line.TrimStart (' ');

						index = line.IndexOf (':');
						if (index == -1)
							continue;

						cmd = line.Substring (0, index);
						line = line.Substring (index + 1);
						while (line.StartsWith (" "))
							line = line.Substring (1);

						switch (cmd) {
						case "AddFile":
						case "AddHiddenFile":
							try {
								Logger.Log ("@MonkeyWrench command: '{0}' args: '{1}'", cmd, line);
								files.Add (line.Trim ());
								hidden.Add (cmd.Contains ("Hidden"));
							} catch (Exception e) {
								Logger.Log ("Error while executing @MonkeyWrench command '{0}': '{1}'", cmd, e.Message);
							}
							break;
						case "AddDirectory":
						case "AddHiddenDirectory":
							try {
								Logger.Log ("@MonkeyWrench command: '{0}' args: '{1}'", cmd, line);
								foreach (string file in Directory.GetFiles (line.Trim ())) {
									files.Add (file);
									hidden.Add (cmd.Contains ("Hidden"));
								}
							} catch (Exception e) {
								Logger.Log ("Error while executing @MonkeyWrench command '{0}': '{1}'", cmd, e.Message);
							}
							break;
						case "SetSummary":
							info.work.summary = line;
							info.work = WebService.ReportBuildStateSafe (info.work).Work;
							break;
						case "SetReleaseVersion":
							if (release == null)
								release = new DBRelease ();
							release.version = line.Trim ();
							break;
						case "SetReleaseRevision":
							if (release == null)
								release = new DBRelease ();
							release.revision = line.Trim ();
							break;
						case "SetReleaseDescription":
							if (release == null)
								release = new DBRelease ();
							release.description = line.Trim ();
							break;
						case "AddRelease":
							if (release == null) {
								Logger.Log ("Invalid @MonkeyWrench command: '{0}: No release created", cmd);
								break;
							}

							WebServiceResponse rsp;

							try {
								release.filename = Path.GetFileName (line.Trim ());
								File.Copy (line.Trim (), Path.Combine (Configuration.GetReleaseDirectory (), release.filename), true);
								rsp = WebService.AddRelease (WebService.WebServiceLogin, release);
								if (rsp.Exception != null) {
									Logger.Log ("Error while adding release: {0}", rsp.Exception);
								}
							} catch (Exception ex) {
								Logger.Log ("Could not copy release: {0}", ex.ToString ());
							}
							break;
						default:
							Logger.Log ("Invalid @MonkeyWrench command: '{0}', entire line: '{1}'", cmd, l);
							break;
						}
					}

					WebService.UploadFilesSafe (info.work, files.ToArray (), hidden.ToArray ());
				}
			}
		}