コード例 #1
0
        private CommitDTO Parse(IEnumerable <string> commitLines)
        {
            try
            {
                // TODO: this code should be refactored and replaced with womething like
                // a visitor pattern for the parser. Additionally, it should not fail
                // when an unknown token occurs.
                if (commitLines?.Count() > 3)
                {
                    var commit = new CommitDTO()
                    {
                        Id = this.commitIdParser.Parse(commitLines.ElementAt(0))
                    };

                    var authorInfo = this.commitAuthorParser.Parse(commitLines.ElementAt(1));

                    commit.AuthorName  = authorInfo.name;
                    commit.AuthorEmail = authorInfo.email;
                    commit.Date        = commitDateParser.Parse(commitLines.ElementAt(2));
                    commit.Message     = commitMessageParser.Parse(commitLines.Skip(3));

                    return(commit);
                }
                else
                {
                    logger.Error("Insufficient information for a commit: \n" + string.Join("\n", commitLines));
                    return(null);
                }
            }
            catch (Exception exp)
            {
                logger.Error("Commit parsing exception while parsing: \n" + string.Join("\n", commitLines), exp);
                return(null);
            }
        }
コード例 #2
0
        private void do_commit()
        {
            if (consumer_offset.Count == 0)
            {
                return;
            }
            try
            {
                CommitDTO commit_dto = new CommitDTO();

                foreach (string key in consumer_offset.Keys)
                {
                    var message = consumer_offset[key];
                    if (message != null)
                    {
                        commit_dto.commits.Add(new Commit
                        {
                            topic     = message.topic,
                            partition = message.partition,
                            offset    = message.offset
                        });
                    }
                }
                client.commit_offsets(commit_dto);
            }
            catch
            {
                //_logger.log
            }
        }
コード例 #3
0
        public void commit_offsets(CommitDTO commit_dto)
        {
            if (!isConnected || commit_dto == null || commit_dto.commits.Count == 0)
            {
                return;
            }

            _logger.Info("committing offset...");

            foreach (var commit in commit_dto.commits)
            {
                _logger.Trace(string.Format("committing topic: {0}, partition: {1}, offset: {2}  ", commit.topic, commit.partition, commit.offset));
            }

            TransferPkg pkg = build_TransferPkg((int)CmdId.CommitReq, ProtoBufEncoder.SerializeToBytes(commit_dto));

            TransferPkg commit_res = send_and_recv(pkg, false, false);

            if (commit_res == null)
            {
                _logger.Error("Commit failed, received unexpected response, needed CommitRsp, received nothing.");
                reconnect();
                return;
            }
            if (commit_res.cmdId != -3)
            {
                _logger.Error("Error occured commiting offset, reconnecting...");
            }
        }
コード例 #4
0
 public void GenerateData(List<ChangeList> allChangeLists)
 {
     foreach (var changeList in allChangeLists)
     {
         AuthorDTO authorDto;
         var author = changeList.Author;
         if (!data.TryGetValue(author, out authorDto))
         {
             authorDto = new AuthorDTO {Author = author, Commits = new Dictionary<int, CommitDTO>()};
             data.Add(author, authorDto);
         }
         var commits = authorDto.Commits;
         CommitDTO values;
         var year = changeList.Date.Year;
         if (!commits.TryGetValue(year, out values))
         {
             values = new CommitDTO() {All = 0, Hourly = new int[24]};
             commits.Add(year, values);
         }
         var hour = changeList.Date.Hour;
         values.Hourly[hour]++;
         values.All++;
     }
 }