void ApplyBuildUpdate(BuildData Build)
        {
            EventSummary Summary = FindOrAddSummary(Build.ChangeNumber);

            BuildData ExistingBuild = Summary.Builds.Find(x => x.ChangeNumber == Build.ChangeNumber && x.BuildType == Build.BuildType);

            if (ExistingBuild != null)
            {
                if (ExistingBuild.Id <= Build.Id)
                {
                    Summary.Builds.Remove(ExistingBuild);
                }
                else
                {
                    return;
                }
            }

            Summary.Builds.Add(Build);
            Summary.Verdict = GetVerdict(Summary.Reviews, Summary.Builds);
        }
        bool ReadEventsFromBackend()
        {
            try
            {
                Stopwatch Timer = Stopwatch.StartNew();
                LogWriter.WriteLine();
                LogWriter.WriteLine("Polling for reviews at {0}...", DateTime.Now.ToString());

                if (LastEventId == 0)
                {
                    using (SqlConnection Connection = new SqlConnection(SqlConnectionString))
                    {
                        Connection.Open();
                        using (SqlCommand Command = new SqlCommand("SELECT MAX(ID) FROM dbo.UserVotes", Connection))
                        {
                            using (SqlDataReader Reader = Command.ExecuteReader())
                            {
                                while (Reader.Read())
                                {
                                    LastEventId = Reader.GetInt64(0);
                                    LastEventId = Math.Max(LastEventId - 5000, 0);
                                    break;
                                }
                            }
                        }
                    }
                }

                using (SqlConnection Connection = new SqlConnection(SqlConnectionString))
                {
                    Connection.Open();
                    using (SqlCommand Command = new SqlCommand("SELECT Id, Changelist, UserName, Verdict, Project FROM dbo.UserVotes WHERE Id > @param1 ORDER BY Id", Connection))
                    {
                        Command.Parameters.AddWithValue("@param1", LastEventId);
                        using (SqlDataReader Reader = Command.ExecuteReader())
                        {
                            while (Reader.Read())
                            {
                                EventData Review = new EventData();
                                Review.Id       = Reader.GetInt64(0);
                                Review.Change   = Reader.GetInt32(1);
                                Review.UserName = Reader.GetString(2);
                                Review.Project  = Reader.IsDBNull(4)? null : Reader.GetString(4);
                                if (Enum.TryParse(Reader.GetString(3), out Review.Type))
                                {
                                    if (Review.Project == null || String.Compare(Review.Project, Project, true) == 0)
                                    {
                                        IncomingEvents.Enqueue(Review);
                                    }
                                    LastEventId = Math.Max(LastEventId, Review.Id);
                                }
                            }
                        }
                    }
                    using (SqlCommand Command = new SqlCommand("SELECT Id, ChangeNumber, UserName, Text, Project FROM dbo.Comments WHERE Id > @param1 ORDER BY Id", Connection))
                    {
                        Command.Parameters.AddWithValue("@param1", LastCommentId);
                        using (SqlDataReader Reader = Command.ExecuteReader())
                        {
                            while (Reader.Read())
                            {
                                CommentData Comment = new CommentData();
                                Comment.Id           = Reader.GetInt32(0);
                                Comment.ChangeNumber = Reader.GetInt32(1);
                                Comment.UserName     = Reader.GetString(2);
                                Comment.Text         = Reader.GetString(3);
                                Comment.Project      = Reader.GetString(4);
                                if (Comment.Project == null || String.Compare(Comment.Project, Project, true) == 0)
                                {
                                    IncomingComments.Enqueue(Comment);
                                }
                                LastCommentId = Math.Max(LastCommentId, Comment.Id);
                            }
                        }
                    }
                    using (SqlCommand Command = new SqlCommand("SELECT Id, ChangeNumber, BuildType, Result, Url, Project FROM dbo.CIS WHERE Id > @param1 ORDER BY Id", Connection))
                    {
                        Command.Parameters.AddWithValue("@param1", LastBuildId);
                        using (SqlDataReader Reader = Command.ExecuteReader())
                        {
                            while (Reader.Read())
                            {
                                BuildData Build = new BuildData();
                                Build.Id           = Reader.GetInt32(0);
                                Build.ChangeNumber = Reader.GetInt32(1);
                                Build.BuildType    = Reader.GetString(2).TrimEnd();
                                if (Enum.TryParse(Reader.GetString(3).TrimEnd(), true, out Build.Result))
                                {
                                    Build.Url     = Reader.GetString(4);
                                    Build.Project = Reader.IsDBNull(5)? null : Reader.GetString(5);
                                    if (Build.Project == null || String.Compare(Build.Project, Project, true) == 0 || MatchesWildcard(Build.Project, Project))
                                    {
                                        IncomingBuilds.Enqueue(Build);
                                    }
                                }
                                LastBuildId = Math.Max(LastBuildId, Build.Id);
                            }
                        }
                    }
                }
                LastStatusMessage = String.Format("Last update took {0}ms", Timer.ElapsedMilliseconds);
                LogWriter.WriteLine("Done in {0}ms.", Timer.ElapsedMilliseconds);
                return(true);
            }
            catch (Exception Ex)
            {
                LogWriter.WriteException(Ex, "Failed with exception.");
                LastStatusMessage = String.Format("Last update failed: ({0})", Ex.ToString());
                return(false);
            }
        }
Exemple #3
0
 public bool TryGetLatestBuild(string BuildType, out BuildData BuildData)
 {
     return(BadgeNameToLatestBuild.TryGetValue(BuildType, out BuildData));
 }