Esempio n. 1
0
        /// <summary>
        /// OnStart(): Put startup code here
        ///  - Start threads, get inital data, etc.
        /// </summary>
        /// <param name="args"></param>
        protected override void OnStart(string[] args)
        {
            base.OnStart(args);
            _instance = this;

            // Always double-check that we have an actual thread to work with...
            InitWorld();
            LoadQueue();
        }
Esempio n. 2
0
        static void Main()
        {
            VerboseOut = s => Console.WriteLine(s);
            AutoBuild Manager = Instance;

            Manager.OnStart(new string[0]);
            ConsoleKeyInfo c = new ConsoleKeyInfo(' ', ConsoleKey.Spacebar, false, false, false);

            while (!(c.Key.Equals(ConsoleKey.Escape)))
            {
                Console.Out.Write('.');
                System.Threading.Thread.Sleep(1000);
                if (Console.KeyAvailable)
                {
                    c = Console.ReadKey(true);
                }
            }
            Manager.OnStop();


            ////uncomment this for release...
            //ServiceBase.Run(new AutoBuild());
        }
Esempio n. 3
0
        /// <summary>
        /// OnStart(): Put startup code here
        ///  - Start threads, get inital data, etc.
        /// </summary>
        /// <param name="args"></param>
        protected override void OnStart(string[] args)
        {
            base.OnStart(args);
            _instance = this;

            // Always double-check that we have an actual thread to work with...
            InitWorld();
            LoadQueue();
        }
Esempio n. 4
0
        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);
        }