//A copy constructor, because I'm always annoyed when I can't find one. public ProjectData(ProjectData source) { Enabled = source.Enabled; KeepCleanRepo = source.KeepCleanRepo; RepoURL = source.RepoURL; WatchRefs = new ObservableCollection<string>(source.WatchRefs); BuildCheckouts = new XDictionary<string, CheckoutInfo>(source.BuildCheckouts); Commands = new XDictionary<string, CommandScript>(source.Commands); BuildTriggers = new ObservableCollection<BuildTrigger>(source.BuildTriggers); Build = new ObservableCollection<string>(source.Build); PreBuild = new ObservableCollection<string>(source.PreBuild); PostBuild = new ObservableCollection<string>(source.PostBuild); WatchRefs.CollectionChanged += CollectionChanged; BuildCheckouts.Changed += CheckoutsChanged; Commands.Changed += CommandsChanged; BuildTriggers.CollectionChanged += CollectionChanged; Build.CollectionChanged += CollectionChanged; PreBuild.CollectionChanged += CollectionChanged; PostBuild.CollectionChanged += CollectionChanged; LoadHistory(String.Empty); }
/// <summary> /// Loads a project configuration from disk. /// </summary> /// <param name="projectName">The name of the project to load.</param> /// <param name="overwrite">If true, will reload the project config data even if the project already has a configuration loaded. (False by default)</param> /// <returns>True if the project was loaded successfully. False otherwise.</returns> public bool LoadProject(string projectName, bool overwrite = false) { if (Projects.ContainsKey(projectName) && !overwrite) return false; try { if (projectName == null) throw new ArgumentException("ProjectName cannot be null."); Projects[projectName] = new ProjectData(); if (!Projects.ContainsKey(projectName)) throw new ArgumentException("Project not found: " + projectName); string file = Path.Combine(MasterConfig.ProjectRoot, projectName, "config.conf"); UrlEncodedMessage UEM = new UrlEncodedMessage(File.ReadAllText(file), AutoBuild.SerialSeperator, true); UEM.DeserializeTo(Projects[projectName]); Projects[projectName].SetName(projectName); string logPath = Path.Combine(MasterConfig.ProjectRoot, projectName, "Log.log"); if (!File.Exists(logPath)) logPath = String.Empty; Projects[projectName].LoadHistory(logPath); Projects[projectName].Changed2 += ProjectChanged; return true; } catch (Exception e) { WriteEvent("Unable to load project config (" + projectName + "):\n" + e.Message, EventLogEntryType.Error, 0, 0); return false; } }
public void AddProject(string projectName, ProjectData project) { if (Projects.ContainsKey(projectName)) throw new ArgumentException("A project with this name already exists: " + projectName); Projects[projectName] = project; Projects[projectName].LoadHistory(new BuildHistory()); SaveProject(projectName); // save this so we don't run into other problems later Projects[projectName].Changed2 += ProjectChanged; InitProject(projectName); }
public override Task Post(HttpListenerResponse response, string relativePath, UrlEncodedMessage message) { var payload = (string)message["payload"]; if (payload == null) { response.StatusCode = 500; response.Close(); return("".AsResultTask()); } var result = Task.Factory.StartNew(() => { try { dynamic json = JObject.Parse(payload); WriteLog("MSG Process begin " + json.commits.Count); string repository = (json.repository.name) ?? String.Empty; string reference = json["ref"].ToString(); int count = json.commits.Count; bool validTrigger = false; for (int i = 0; i < count; i++) { string username = (json.commits[i].author.username ?? json.commits[i].author.name ?? new { Value = String.Empty }).Value; if (!username.Equals((string)(AutoBuild.MasterConfig.VersionControlList["git"].Properties["username"]), StringComparison.CurrentCultureIgnoreCase)) { validTrigger = true; } } if (validTrigger) { AutoBuild.WriteVerbose("POST received: " + repository + " -- " + reference); if (AutoBuild.Projects.ContainsKey(repository)) { ProjectData project = AutoBuild.Projects[repository]; if (project.WatchRefs.IsNullOrEmpty() || project.WatchRefs.Contains(reference)) { AutoBuild.StandBy(repository); } } else { bool makeNew; if (!Boolean.TryParse(AutoBuild.MasterConfig.VersionControlList["git"].Properties["NewFromHook"], out makeNew)) { return; } if (makeNew) { /////Build new ProjectInfo info from commit message. ProjectData project = new ProjectData(); project.SetName(repository); project.Enabled = true; project.KeepCleanRepo = AutoBuild.MasterConfig.DefaultCleanRepo; // This section constructs the repo url to use... string init_url = json.repository.url; string proto = init_url.Substring(0, init_url.IndexOf("://") + 3); init_url = init_url.Substring(proto.Length); string host = init_url.Substring(0, init_url.IndexOf("/")); string repo = init_url.Substring(init_url.IndexOf("/") + 1); switch (((string)(AutoBuild.MasterConfig.VersionControlList["git"].Properties["url_style"])).ToLower()) { case "git": project.RepoURL = "git://" + host + "/" + repo; break; case "http": project.RepoURL = json.url; break; case "ssh": project.RepoURL = "git@" + host + ":" + repo; break; default: project.RepoURL = null; break; } // End repo url section project.WatchRefs.AddRange(AutoBuild.MasterConfig.DefaultRefs); if (!(AutoBuild.MasterConfig.DefaultCommands.IsNullOrEmpty())) { if (project.WatchRefs.Count > 0) { foreach (string watchRef in project.WatchRefs) { string branch = watchRef.Substring(11); //length of @"refs/heads/" project.BuildCheckouts[branch] = new ProjectData.CheckoutInfo(); List <string> strings; //prebuild strings = AutoBuild.MasterConfig.DefaultCommands["prebuild"] ?? new List <string>(); foreach (string s in strings) { project.BuildCheckouts[branch].PreCmd.Add(s); } //build project.BuildCheckouts[branch].BuildCmd.Add("Checkout"); // magic name strings = AutoBuild.MasterConfig.DefaultCommands["build"] ?? new List <string>(); foreach (string s in strings) { project.BuildCheckouts[branch].BuildCmd.Add(s); } //postbuild strings = AutoBuild.MasterConfig.DefaultCommands["postbuild"] ?? new List <string>(); foreach (string s in strings) { project.BuildCheckouts[branch].ArchiveCmd.Add(s); } } } else { List <string> strings; //prebuild strings = AutoBuild.MasterConfig.DefaultCommands["prebuild"] ?? new List <string>(); foreach (string s in strings) { project.PreBuild.Add(s); } //build strings = AutoBuild.MasterConfig.DefaultCommands["build"] ?? new List <string>(); foreach (string s in strings) { project.Build.Add(s); } //postbuild strings = AutoBuild.MasterConfig.DefaultCommands["postbuild"] ?? new List <string>(); foreach (string s in strings) { project.PostBuild.Add(s); } } } //We're obviously adding a git repo for this project, so assign that for the project's version control project.VersionControl = "git"; //Add the new project with the new ProjectInfo AutoBuild.Instance.AddProject(repository, project); //Start the wait period. AutoBuild.StandBy(repository); } } } } catch (Exception e) { WriteLog("Error processing payload: {0} -- {1}\r\n{2}".format(e.GetType(), e.Message, e.StackTrace), EventLogEntryType.Error); Listener.HandleException(e); response.StatusCode = 500; response.Close(); } }, TaskCreationOptions.AttachedToParent); result.ContinueWith(antecedent => { if (result.IsFaulted) { var e = antecedent.Exception.InnerException; WriteLog("Error handling commit message: {0} -- {1}\r\n{2}".format(e.GetType(), e.Message, e.StackTrace), EventLogEntryType.Error); Listener.HandleException(e); response.StatusCode = 500; response.Close(); } }, TaskContinuationOptions.OnlyOnFaulted); return(result); }
public override Task Post(HttpListenerResponse response, string relativePath, UrlEncodedMessage message) { var payload = (string)message["payload"]; if (payload == null) { response.StatusCode = 500; response.Close(); return "".AsResultTask(); } var result = Task.Factory.StartNew(() => { try { dynamic json = JObject.Parse(payload); WriteLog("MSG Process begin " + json.commits.Count); string repository = (json.repository.name) ?? String.Empty; string reference = json["ref"].ToString(); int count = json.commits.Count; bool validTrigger = false; for (int i = 0; i < count; i++) { string username = (json.commits[i].author.username ?? json.commits[i].author.name ?? new {Value = String.Empty}).Value; if (!username.Equals((string)(AutoBuild.MasterConfig.VersionControlList["git"].Properties["username"]), StringComparison.CurrentCultureIgnoreCase)) { validTrigger = true; } } if (validTrigger) { AutoBuild.WriteVerbose("POST received: " + repository + " -- " + reference); if (AutoBuild.Projects.ContainsKey(repository)) { ProjectData project = AutoBuild.Projects[repository]; if (project.WatchRefs.IsNullOrEmpty() || project.WatchRefs.Contains(reference)) AutoBuild.StandBy(repository); } else { bool makeNew; if (!Boolean.TryParse(AutoBuild.MasterConfig.VersionControlList["git"].Properties["NewFromHook"], out makeNew)) return; if (makeNew) { /////Build new ProjectInfo info from commit message. ProjectData project = new ProjectData(); project.SetName(repository); project.Enabled = true; project.KeepCleanRepo = AutoBuild.MasterConfig.DefaultCleanRepo; // This section constructs the repo url to use... string init_url = json.repository.url; string proto = init_url.Substring(0, init_url.IndexOf("://") + 3); init_url = init_url.Substring(proto.Length); string host = init_url.Substring(0, init_url.IndexOf("/")); string repo = init_url.Substring(init_url.IndexOf("/") + 1); switch (((string)(AutoBuild.MasterConfig.VersionControlList["git"].Properties["url_style"])).ToLower()) { case "git": project.RepoURL = "git://" + host + "/" + repo; break; case "http": project.RepoURL = json.url; break; case "ssh": project.RepoURL = "git@" + host + ":" + repo; break; default: project.RepoURL = null; break; } // End repo url section project.WatchRefs.AddRange(AutoBuild.MasterConfig.DefaultRefs); if (!(AutoBuild.MasterConfig.DefaultCommands.IsNullOrEmpty())) { if (project.WatchRefs.Count > 0) { foreach (string watchRef in project.WatchRefs) { string branch = watchRef.Substring(11); //length of @"refs/heads/" project.BuildCheckouts[branch] = new ProjectData.CheckoutInfo(); List<string> strings; //prebuild strings = AutoBuild.MasterConfig.DefaultCommands["prebuild"] ?? new List<string>(); foreach (string s in strings) { project.BuildCheckouts[branch].PreCmd.Add(s); } //build project.BuildCheckouts[branch].BuildCmd.Add("Checkout"); // magic name strings = AutoBuild.MasterConfig.DefaultCommands["build"] ?? new List<string>(); foreach (string s in strings) { project.BuildCheckouts[branch].BuildCmd.Add(s); } //postbuild strings = AutoBuild.MasterConfig.DefaultCommands["postbuild"] ?? new List<string>(); foreach (string s in strings) { project.BuildCheckouts[branch].ArchiveCmd.Add(s); } } } else { List<string> strings; //prebuild strings = AutoBuild.MasterConfig.DefaultCommands["prebuild"] ?? new List<string>(); foreach (string s in strings) { project.PreBuild.Add(s); } //build strings = AutoBuild.MasterConfig.DefaultCommands["build"] ?? new List<string>(); foreach (string s in strings) { project.Build.Add(s); } //postbuild strings = AutoBuild.MasterConfig.DefaultCommands["postbuild"] ?? new List<string>(); foreach (string s in strings) { project.PostBuild.Add(s); } } } //We're obviously adding a git repo for this project, so assign that for the project's version control project.VersionControl = "git"; //Add the new project with the new ProjectInfo AutoBuild.Instance.AddProject(repository, project); //Start the wait period. AutoBuild.StandBy(repository); } } } } catch (Exception e) { WriteLog("Error processing payload: {0} -- {1}\r\n{2}".format(e.GetType(), e.Message, e.StackTrace), EventLogEntryType.Error); Listener.HandleException(e); response.StatusCode = 500; response.Close(); } }, TaskCreationOptions.AttachedToParent); result.ContinueWith(antecedent => { if (result.IsFaulted) { var e = antecedent.Exception.InnerException; WriteLog("Error handling commit message: {0} -- {1}\r\n{2}".format(e.GetType(), e.Message, e.StackTrace), EventLogEntryType.Error); Listener.HandleException(e); response.StatusCode = 500; response.Close(); } }, TaskContinuationOptions.OnlyOnFaulted); return result; }