示例#1
0
        private Dictionary<string, string> GetData(RegisterIssueRequestEntity request)
        {
            var values = GetData(request.IssueType).ToArray();

            var result = new Dictionary<string, string>();
            foreach (var value in values)
            {
                var keyCount = values.Count(x => x.Key == value.Key);
                if (keyCount == 1)
                {
                    result.Add(value.Key, value.Value);
                }
                else
                {
                    var index = 0;
                    while (result.ContainsKey(value.Key + "." + index))
                    {
                        index++;
                    }
                    result.Add(value.Key + "." + index, value.Value);
                }
            }

            return result;
        }
示例#2
0
        public RegisterIssueResponseEntity RegisterIssue(RegisterIssueRequestEntity request)
        {
            if (request == null) throw new ArgumentNullException(nameof(request), "No request object provided.");
            if (string.IsNullOrEmpty(request.SessionKey)) throw new ArgumentException("No valid session provided.");
            if (request.IssueType == null) throw new ArgumentException("No IssueType object in request was provided. Need object '{ \"IssueType\":{...} }' in root.");
            if (string.IsNullOrEmpty(request.IssueType.Message)) throw new ArgumentException("No message in issue type provided.");

            var issueKey = request.IssueKey;
            if (issueKey == Guid.Empty)
            {
                issueKey = Guid.NewGuid();
            }

            var value = request.IssueType.Type;
            if (string.IsNullOrEmpty(value))
            {
                value = "Message";
            }

            var serverTime = DateTime.UtcNow;
            var clientTime = request.ClientTime;
            if (request.ClientTime == DateTime.MinValue)
            {
                clientTime = serverTime;
            }

            var session = _repository.GetSession(request.SessionKey);
            if (session == null)
            {
                throw new ArgumentException("There is no session with provided sessionKey.");
            }
            if (session.ServerEndTime != null)
            {
                throw new InvalidOperationException("The session has already been marked as ended. Create a new session to register issues.");
            }

            int ticket;
            lock (_syncRoot)
            {
                _repository.SetSessionUsed(session.SessionKey, serverTime);
                ticket = GetTicket(session.ProjectKey, 10);
            }

            // Add/Update IssueType
            var issueTypeKey = _repository.GetIssueTypeKey(session.VersionKey, value, request.IssueLevel, request.IssueType.Message, request.IssueType.StackTrace);
            if (issueTypeKey == null)
            {
                issueTypeKey = Guid.NewGuid();
                _repository.CreateIssueType(issueTypeKey.Value, session.VersionKey, ticket, value, request.IssueLevel, request.IssueType.Message, request.IssueType.StackTrace, serverTime, request.IssueType.Inner);
            }

            //TODO: Check if the issue key already exists. _repository.GetIssue(issueKey);
            _repository.CreateIssue(issueKey, issueTypeKey.Value, request.IssueThreadKey, session.SessionKey, clientTime, GetData(request), serverTime);

            _writeBusiness.RunRecalculate();

            return new RegisterIssueResponseEntity(issueKey, ticket, serverTime, session.ProjectKey, issueTypeKey.Value);
        }