예제 #1
0
        public EventMonitor(string InApiUrl, string InProject, string InCurrentUserName, string InLogFileName)
        {
            ApiUrl          = InApiUrl;
            Project         = InProject;
            CurrentUserName = InCurrentUserName;
            LatestIds       = new LatestData {
                LastBuildId = 0, LastCommentId = 0, LastEventId = 0
            };

            MetadataStream = Project.ToLowerInvariant().TrimEnd('/');
            if (MetadataStream.StartsWith("//", StringComparison.Ordinal))
            {
                int NextIdx = MetadataStream.IndexOf('/', 2);
                if (NextIdx != -1)
                {
                    NextIdx = MetadataStream.IndexOf('/', NextIdx + 1);
                    if (NextIdx != -1)
                    {
                        MetadataProject = MetadataStream.Substring(NextIdx + 1);
                        MetadataStream  = MetadataStream.Substring(0, NextIdx);
                    }
                }
            }

            LogWriter = new BoundedLogWriter(InLogFileName);
            if (ApiUrl == null)
            {
                LastStatusMessage = "Database functionality disabled due to empty ApiUrl.";
            }
            else
            {
                LogWriter.WriteLine("Using connection string: {0}", ApiUrl);
            }
        }
예제 #2
0
        bool ReadEventsFromBackend()
        {
            try
            {
                Stopwatch Timer = Stopwatch.StartNew();
                LogWriter.WriteLine();
                LogWriter.WriteLine("Polling for reviews at {0}...", DateTime.Now.ToString());
                //////////////
                /// Initial Ids
                //////////////
                if (LatestIds.LastBuildId == 0 && LatestIds.LastCommentId == 0 && LatestIds.LastEventId == 0)
                {
                    LatestData InitialIds = RESTApi.GET <LatestData>(ApiUrl, "latest", string.Format("project={0}", Project));
                    LatestIds.LastBuildId   = InitialIds.LastBuildId;
                    LatestIds.LastCommentId = InitialIds.LastCommentId;
                    LatestIds.LastEventId   = InitialIds.LastEventId;
                }

                //////////////
                /// Reviews
                //////////////
                List <EventData> Events = RESTApi.GET <List <EventData> >(ApiUrl, "event", string.Format("project={0}", Project), string.Format("lasteventid={0}", LatestIds.LastEventId));
                foreach (EventData Review in Events)
                {
                    IncomingEvents.Enqueue(Review);
                    LatestIds.LastEventId = Math.Max(LatestIds.LastEventId, Review.Id);
                }

                //////////////
                /// Comments
                //////////////
                List <CommentData> Comments = RESTApi.GET <List <CommentData> >(ApiUrl, "comment", string.Format("project={0}", Project), string.Format("lastcommentid={0}", LatestIds.LastCommentId));
                foreach (CommentData Comment in Comments)
                {
                    IncomingComments.Enqueue(Comment);
                    LatestIds.LastCommentId = Math.Max(LatestIds.LastCommentId, Comment.Id);
                }

                //////////////
                /// Bulids
                //////////////
                List <BuildData> Builds = RESTApi.GET <List <BuildData> >(ApiUrl, "build", string.Format("project={0}", Project), string.Format("lastbuildid={0}", LatestIds.LastBuildId));
                foreach (BuildData Build in Builds)
                {
                    IncomingBuilds.Enqueue(Build);
                    LatestIds.LastBuildId = Math.Max(LatestIds.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);
            }
        }
예제 #3
0
        public EventMonitor(string InApiUrl, string InProject, string InCurrentUserName, string InLogFileName)
        {
            ApiUrl          = InApiUrl;
            Project         = InProject;
            CurrentUserName = InCurrentUserName;
            LatestIds       = new LatestData {
                LastBuildId = 0, LastCommentId = 0, LastEventId = 0
            };

            LogWriter = new BoundedLogWriter(InLogFileName);
            if (ApiUrl == null)
            {
                LastStatusMessage = "Database functionality disabled due to empty ApiUrl.";
            }
            else
            {
                LogWriter.WriteLine("Using connection string: {0}", ApiUrl);
            }
        }
예제 #4
0
        bool ReadEventsFromBackend(bool bFireThrottledRequests)
        {
            try
            {
                Stopwatch Timer = Stopwatch.StartNew();
                LogWriter.WriteLine();
                LogWriter.WriteLine("Polling for reviews at {0}...", DateTime.Now.ToString());
                //////////////
                /// Initial Ids
                //////////////
                if (ApiVersion == 0)
                {
                    LatestData InitialIds = RESTApi.GET <LatestData>(ApiUrl, "latest", string.Format("project={0}", Project));
                    ApiVersion              = (InitialIds.Version == 0)? 1 : InitialIds.Version;
                    LatestIds.LastBuildId   = InitialIds.LastBuildId;
                    LatestIds.LastCommentId = InitialIds.LastCommentId;
                    LatestIds.LastEventId   = InitialIds.LastEventId;
                }

                if (ApiVersion == 2)
                {
                    int NewMinChangeCopy = NewMinChange;
                    if (NewMinChangeCopy != 0)
                    {
                        // If the range of changes has decreased, update the MinChange value before we fetch anything
                        MinChange = Math.Max(MinChange, NewMinChangeCopy);

                        // Get the first part of the query
                        string CommonArgs = String.Format("stream={0}", MetadataStream);
                        if (MetadataProject != null)
                        {
                            CommonArgs += String.Format("&project={0}", MetadataProject);
                        }

                        // Fetch any updates in the current range of changes
                        if (MinChange != 0)
                        {
                            GetMetadataListResponseV2 NewEventList = RESTApi.GET <GetMetadataListResponseV2>(ApiUrl, "metadata", String.Format("{0}&minchange={1}&sequence={2}", CommonArgs, MinChange, MetadataSequenceNumber));
                            foreach (GetMetadataResponseV2 NewEvent in NewEventList.Items)
                            {
                                IncomingMetadata.Enqueue(NewEvent);
                            }
                            MetadataSequenceNumber = Math.Max(NewEventList.SequenceNumber, MetadataSequenceNumber);
                        }

                        // Fetch any new changes
                        if (NewMinChangeCopy < MinChange)
                        {
                            GetMetadataListResponseV2 NewEvents = RESTApi.GET <GetMetadataListResponseV2>(ApiUrl, "metadata", String.Format("{0}&minchange={1}&maxchange={2}", CommonArgs, NewMinChangeCopy, MinChange));
                            foreach (GetMetadataResponseV2 NewEvent in NewEvents.Items)
                            {
                                IncomingMetadata.Enqueue(NewEvent);
                            }
                            MinChange = NewMinChangeCopy;
                        }
                    }
                }
                else
                {
                    //////////////
                    /// Bulids
                    //////////////
                    List <BadgeData> Builds = RESTApi.GET <List <BadgeData> >(ApiUrl, "build", string.Format("project={0}", Project), string.Format("lastbuildid={0}", LatestIds.LastBuildId));
                    foreach (BadgeData Build in Builds)
                    {
                        IncomingBadges.Enqueue(Build);
                        LatestIds.LastBuildId = Math.Max(LatestIds.LastBuildId, Build.Id);
                    }

                    //////////////////////////
                    /// Throttled Requests
                    //////////////////////////
                    if (bFireThrottledRequests)
                    {
                        //////////////
                        /// Reviews
                        //////////////
                        List <EventData> Events = RESTApi.GET <List <EventData> >(ApiUrl, "event", string.Format("project={0}", Project), string.Format("lasteventid={0}", LatestIds.LastEventId));
                        foreach (EventData Review in Events)
                        {
                            IncomingEvents.Enqueue(Review);
                            LatestIds.LastEventId = Math.Max(LatestIds.LastEventId, Review.Id);
                        }

                        //////////////
                        /// Comments
                        //////////////
                        List <CommentData> Comments = RESTApi.GET <List <CommentData> >(ApiUrl, "comment", string.Format("project={0}", Project), string.Format("lastcommentid={0}", LatestIds.LastCommentId));
                        foreach (CommentData Comment in Comments)
                        {
                            IncomingComments.Enqueue(Comment);
                            LatestIds.LastCommentId = Math.Max(LatestIds.LastCommentId, Comment.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);
            }
        }