示例#1
0
        public bool GetCommentByCurrentUser(int ChangeNumber, out string CommentText)
        {
            EventSummary Summary = GetSummaryForChange(ChangeNumber);

            if (Summary == null)
            {
                CommentText = null;
                return(false);
            }

            CommentData Comment = Summary.Comments.Find(x => String.Compare(x.UserName, CurrentUserName, true) == 0);

            if (Comment == null || String.IsNullOrWhiteSpace(Comment.Text))
            {
                CommentText = null;
                return(false);
            }

            CommentText = Comment.Text;
            return(true);
        }
示例#2
0
        void PollForUpdates()
        {
            EventData   Event   = null;
            CommentData Comment = null;

            while (!bDisposing)
            {
                // If there's no connection string, just empty out the queue
                if (ApiUrl != null)
                {
                    // Post all the reviews to the database. We don't send them out of order, so keep the review outside the queue until the next update if it fails
                    while (Event != null || OutgoingEvents.TryDequeue(out Event))
                    {
                        SendEventToBackend(Event);
                        Event = null;
                    }

                    // Post all the comments to the database.
                    while (Comment != null || OutgoingComments.TryDequeue(out Comment))
                    {
                        SendCommentToBackend(Comment);
                        Comment = null;
                    }

                    // Read all the new reviews
                    ReadEventsFromBackend();

                    // Send a notification that we're ready to update
                    if ((IncomingEvents.Count > 0 || IncomingBuilds.Count > 0 || IncomingComments.Count > 0) && OnUpdatesReady != null)
                    {
                        OnUpdatesReady();
                    }
                }

                // Wait for something else to do
                RefreshEvent.WaitOne(30 * 1000);
            }
        }
示例#3
0
 bool SendCommentToBackend(CommentData Comment)
 {
     try
     {
         Stopwatch Timer = Stopwatch.StartNew();
         LogWriter.WriteLine("Posting comment... ({0}, {1}, {2}, {3})", Comment.ChangeNumber, Comment.UserName, Comment.Text, Comment.Project);
         if (ApiVersion == 2)
         {
             SendMetadataUpdateUpdateV2(Comment.ChangeNumber, Comment.Project, Comment.UserName, null, Comment.Text);
         }
         else
         {
             RESTApi.POST(ApiUrl, "comment", new JavaScriptSerializer().Serialize(Comment));
         }
         LogWriter.WriteLine("Done in {0}ms.", Timer.ElapsedMilliseconds);
         return(true);
     }
     catch (Exception Ex)
     {
         LogWriter.WriteException(Ex, "Failed with exception.");
         return(false);
     }
 }
示例#4
0
        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);
            }
        }
示例#5
0
        void ConvertMetadataToEvents(GetMetadataResponseV2 Metadata)
        {
            EventSummary Summary;

            if (ChangeNumberToSummary.TryGetValue(Metadata.Change, out Summary))
            {
                foreach (string CurrentUser in Summary.CurrentUsers)
                {
                    UserNameToLastSyncEvent.Remove(CurrentUser);
                }
                ChangeNumberToSummary.Remove(Metadata.Change);
            }

            if (Metadata.Badges != null)
            {
                foreach (GetBadgeDataResponseV2 BadgeData in Metadata.Badges)
                {
                    BadgeData Badge = new BadgeData();
                    Badge.ChangeNumber = Metadata.Change;
                    Badge.BuildType    = BadgeData.Name;
                    Badge.Result       = BadgeData.State;
                    Badge.Url          = BadgeData.Url;
                    Badge.Project      = Metadata.Project;
                    IncomingBadges.Enqueue(Badge);
                }
            }

            if (Metadata.Users != null)
            {
                foreach (GetUserDataResponseV2 UserData in Metadata.Users)
                {
                    if (UserData.SyncTime != null)
                    {
                        EventData Event = new EventData {
                            Id = UserData.SyncTime.Value, Change = Metadata.Change, Project = Metadata.Project, UserName = UserData.User, Type = EventType.Syncing
                        };
                        IncomingEvents.Enqueue(Event);
                    }

                    EventType?Type = GetEventTypeFromVote(UserData.Vote);
                    if (Type != null)
                    {
                        EventData Event = new EventData {
                            Id = ++IncomingMetadataId, Change = Metadata.Change, Project = Metadata.Project, UserName = UserData.User, Type = Type.Value
                        };
                        IncomingEvents.Enqueue(Event);
                    }

                    if (UserData.Investigating)
                    {
                        EventData Event = new EventData {
                            Id = ++IncomingMetadataId, Change = Metadata.Change, Project = Metadata.Project, UserName = UserData.User, Type = EventType.Starred
                        };
                        IncomingEvents.Enqueue(Event);
                    }

                    if (UserData.Starred)
                    {
                        EventData Event = new EventData {
                            Id = ++IncomingMetadataId, Change = Metadata.Change, Project = Metadata.Project, UserName = UserData.User, Type = EventType.Starred
                        };
                        IncomingEvents.Enqueue(Event);
                    }

                    if (UserData.Comment != null)
                    {
                        CommentData Comment = new CommentData {
                            Id = ++IncomingMetadataId, ChangeNumber = Metadata.Change, Project = Metadata.Project, UserName = UserData.User, Text = UserData.Comment
                        };
                        IncomingComments.Enqueue(Comment);
                    }
                }
            }
        }