Example #1
0
        private void PrepareProcessPatterns()
        {
            if (NumberOfRunningRetos < NumberOfAllowedRetros && QueueList.Count > 0)
            {
                RetrospectiveQueueStructure item = null;
                lock (s_lockObject)
                {
                    if (NumberOfRunningRetos < NumberOfAllowedRetros && QueueList.Count > 0)
                    {
                        NumberOfRunningRetos++;
                        item = GetQueueHead();
                    }
                }

                if (item == null || item.Session == null)
                {
                    return;
                }

                item.Session.ProcessPatterns(item.UPByte, item.FHRByte);
                lock (s_lockObject)
                {
                    if (NumberOfRunningRetos > 0)
                    {
                        NumberOfRunningRetos--;
                    }

                    if (QueueList.Count <= 0)
                    {
                        Logger.WriteLogEntry(TraceEventType.Information, "Patterns Add On Manager, Retrospective Queue, Prepare Process Patterns", "Stopping QueueTimer");
                        QueueTimer.Stop();
                    }
                }
            }
        }
        void QueueTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            if (QueueList.Count <= 0)
            {
                QueueTimer.Stop();
            }

            Console.Out.WriteLine("Buildig = " + Building);
            if (!Building)
            {
                Task.Factory.StartNew(() =>
                {
                    PrepareBuild();
                });
            }
        }
Example #3
0
        void QueueTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
        {
            Logger.WriteLogEntry(TraceEventType.Information, "Patterns Add On Manager, RetrospectiveQueue, Add To Queue", "QueueTimer tick");
            if (QueueList.Count <= 0)
            {
                QueueTimer.Stop();
            }

            if (NumberOfRunningRetos < NumberOfAllowedRetros)
            {
                Task.Factory.StartNew(() =>
                {
                    PrepareProcessPatterns();
                });
            }
        }
        private void PrepareBuild()
        {
            Logger.WriteLogEntry(System.Diagnostics.TraceEventType.Verbose, "BuildRunner BuildRequestsQueue, PrepareBuild", "PrepareBuild starting");
            Console.Out.WriteLine("Buildig = " + Building);
            if (!Building && QueueList.Count > 0)
            {
                BuildElement nextBuild = null;
                lock (s_lock)
                {
                    if (!Building && QueueList.Count > 0)
                    {
                        Building  = true;
                        nextBuild = GetQueueHead();
                    }
                    else
                    {
                        return;
                    }
                }

                if (nextBuild == null || nextBuild.Name.Equals(String.Empty))
                {
                    Logger.WriteLogEntry(System.Diagnostics.TraceEventType.Verbose, "BuildRunner BuildRequestsQueue, PrepareBuild", "nextBuild == null || Empty");
                    return;
                }

                //RunBatch
                var buildName = nextBuild.Name;
                var de        = (from c in BuildManager.Instance.BuildName2Path
                                 where c.Key.Equals(buildName)
                                 select c).FirstOrDefault();

                var path   = de.Value;
                var folder = GetFolder(path);
                using (Process proc = new Process())
                {
                    ProcessStartInfo psi = new ProcessStartInfo(path);
                    Logger.WriteLogEntry(System.Diagnostics.TraceEventType.Verbose, "BuildRunner BuildRequestsQueue, PrepareBuild", "ProcessStartInfo created");
                    psi.UseShellExecute        = false;
                    psi.WorkingDirectory       = folder;
                    psi.RedirectStandardOutput = true;
                    psi.RedirectStandardInput  = true;
                    psi.RedirectStandardError  = true;
                    psi.ErrorDialog            = false;
                    psi.WindowStyle            = ProcessWindowStyle.Hidden;
                    //Console.Out.WriteLine("Executing: " + path);
                    Logger.WriteLogEntry(System.Diagnostics.TraceEventType.Verbose, "BuildRunner BuildRequestsQueue, PrepareBuild", "Executing " + path);
                    proc.StartInfo = psi;
                    proc.Start();
                    System.IO.StreamReader myOutput = proc.StandardOutput;
                    //build.WaitForExit(2000);
                    CurrentBuildingLog = String.Empty;
                    using (StreamWriter wr = new StreamWriter("BuildLog.log"))
                    {
                        while (!proc.HasExited)
                        {
                            string output = myOutput.ReadToEnd();
                            CurrentBuildingLog += output;
                            //Console.Out.WriteLine(output);
                            Logger.WriteLogEntry(System.Diagnostics.TraceEventType.Verbose, "BuildRunner BuildRequestsQueue, PrepareBuild", output);
                            wr.WriteLine(output);
                        }
                    }

                    if (proc.HasExited)
                    {
                        Logger.WriteLogEntry(System.Diagnostics.TraceEventType.Verbose, "BuildRunner BuildRequestsQueue, PrepareBuild", "Process exited");
                        var logStrList = CurrentBuildingLog.Split('\n').ToList();
                        var buildNum   = (from c in logStrList
                                          where c.Contains("Build=")
                                          select c).FirstOrDefault();

                        Logger.WriteLogEntry(System.Diagnostics.TraceEventType.Verbose, "BuildRunner BuildRequestsQueue, PrepareBuild", "got buildNum = " + buildNum);
                        buildNum = buildNum.Remove(0, buildNum.IndexOf("=") + 1).Trim();
                        Logger.WriteLogEntry(System.Diagnostics.TraceEventType.Verbose, "BuildRunner BuildRequestsQueue, PrepareBuild", "extracted buildNum = " + buildNum);
                        if (!Directory.Exists(folder + "\\Log"))
                        {
                            Logger.WriteLogEntry(System.Diagnostics.TraceEventType.Verbose, "BuildRunner BuildRequestsQueue, PrepareBuild", "Create dir");
                            Directory.CreateDirectory(folder + "\\Log");
                        }

                        Logger.WriteLogEntry(System.Diagnostics.TraceEventType.Verbose, "BuildRunner BuildRequestsQueue, PrepareBuild", "dir exist");
                        String logfile = folder + "\\Log\\BuildLog" + buildNum + ".log";
                        using (StreamWriter sw = new StreamWriter(logfile))
                        {
                            sw.Write(CurrentBuildingLog);
                            Logger.WriteLogEntry(System.Diagnostics.TraceEventType.Verbose, "BuildRunner BuildRequestsQueue, PrepareBuild", "Writing log");
                        }

                        Logger.WriteLogEntry(System.Diagnostics.TraceEventType.Verbose, "BuildRunner BuildRequestsQueue, PrepareBuild", "Writing log DONE");
                        bool bSucc = false;
                        if (proc.ExitCode == 0)
                        {
                            bSucc = true;
                        }

                        Logger.WriteLogEntry(System.Diagnostics.TraceEventType.Verbose, "BuildRunner BuildRequestsQueue, PrepareBuild", "Get mail list");
                        var mailList = File.ReadAllLines(folder + "\\MailList.txt").ToList();;
                        Logger.WriteLogEntry(System.Diagnostics.TraceEventType.Verbose, "BuildRunner BuildRequestsQueue, PrepareBuild", "Get mail list DONE");
                        String mailTo = String.Empty;
                        foreach (var item in mailList)
                        {
                            if (item.Equals(String.Empty))
                            {
                                continue;
                            }

                            if (!mailTo.Equals(String.Empty))
                            {
                                mailTo += ", ";
                            }

                            mailTo += item;
                        }

                        Logger.WriteLogEntry(System.Diagnostics.TraceEventType.Verbose, "BuildRunner BuildRequestsQueue, PrepareBuild", "Send mail start");
                        if (mailTo.Equals(String.Empty))
                        {
                            mailTo = "*****@*****.**";
                        }

                        using (MailMessage mail = new MailMessage("*****@*****.**", mailTo))
                        {
                            mail.Subject = buildName + " build " + buildNum + (bSucc ? " Successful" : " Failed");
                            String body = bSucc ? "New build is available" : "Build Failed";
                            mail.Body = body;

                            mail.Attachments.Add(new Attachment(logfile));
                            SmtpClient client = new SmtpClient("notestlv2");
                            client.UseDefaultCredentials = true;

                            try
                            {
                                client.Send(mail);
                            }
                            catch (Exception ex)
                            {
                                Logger.WriteLogEntry(System.Diagnostics.TraceEventType.Critical, "BuildRunner BuildRequestsQueue, PrepareBuild", "Send mail failed");
                            }
                        }

                        Logger.WriteLogEntry(System.Diagnostics.TraceEventType.Verbose, "BuildRunner BuildRequestsQueue, PrepareBuild", "Send mail end");
                    }


                    try
                    {
                        if (!proc.HasExited)
                        {
                            proc.Kill();
                        }

                        if (File.Exists("BuildLog.log"))
                        {
                            File.Delete("BuildLog.log");
                        }

                        Logger.WriteLogEntry(System.Diagnostics.TraceEventType.Verbose, "BuildRunner BuildRequestsQueue, PrepareBuild", "Delete temp log");
                    }
                    catch (Exception ex)
                    {
                        Logger.WriteLogEntry(System.Diagnostics.TraceEventType.Critical, "BuildRunner BuildRequestsQueue, PrepareBuild", ex.ToString());
                    }
                }



                lock (s_lock)
                {
                    Building = false;
                    if (QueueList.Count <= 0)
                    {
                        QueueTimer.Stop();
                        Console.Out.WriteLine("Queue list empty, timer stopped");
                    }
                }

                Logger.WriteLogEntry(System.Diagnostics.TraceEventType.Verbose, "BuildRunner BuildRequestsQueue, PrepareBuild", "Exit");
            }
        }