Esempio n. 1
0
        public void Post([FromBody] JiraEvent jiraEvent, [FromQuery(Name = "user_id")] string userId)
        {
            try
            {
                //string test = jiraEvent.Content.ReadAsStringAsync().Result;
                _logger.LogDebug("JiraWebhookEvent key: " + jiraEvent.Issue.Key);

                if (!userId.ToLower().Equals(ApiUser))
                {
                    string origin = GetOrigin(jiraEvent);

                    if (isCreated(jiraEvent))
                    {
                        _publisher.OnInstanceCreatedAsync(jiraEvent.Issue.Key, userId);
                    }
                    else if (isUpdated(jiraEvent))
                    {
                        _publisher.OnInstanceUpdatedAsync(jiraEvent.Issue.Key, userId);
                    }
                    else if (isDeleted(jiraEvent))
                    {
                        _publisher.OnInstanceDeletedAsync(jiraEvent.Issue.Key, userId);
                    }
                }
            } catch (ProjectNotPresentException e)
            {
                _logger.LogDebug(e.Message);
                _logger.LogError(e.StackTrace);
            }
            catch (Exception e)
            {
                _logger.LogError("Unknown error occured", e.StackTrace);
            }
        }
        public async Task ConnectAsync()
        {
            Debug.WriteLine("Connecting to SignalR");
            Connection         = new HubConnection(_config.SignalServiceUri, await GetConnectionString());
            Connection.Closed += Connection_Closed;

            HubProxy = Connection.CreateHubProxy("topicsHub");

            //Handle incoming event from server: use Invoke to write to console from SignalR's thread
            HubProxy.On <Topic>("NewTopic", (topic) =>
            {
                //Ignore if topic was created by IssueConnector
                if (!EasyAccessMessageFilter.IsOriginalTopic(topic))
                {
                    return;
                }

                //Else publish the topic created at EasyAccess
                Debug.WriteLine("Original Easy Access topic created with id: " + topic.Id);
                _publisher.OnInstanceCreatedAsync(topic.Id, topic.AuthorId, topic.ProjectId);
            }
                                );

            HubProxy.On <Topic>("UpdatedTopic", (topic) => {
                //TODO, need a "loop-stopping-mechanism" to implement this properly.
                Debug.WriteLine("Updated topic: " + topic.Title);
            }
                                );

            HubProxy.On <Topic, string>("DeletedTopic", (topic, username) =>
            {
                //TODO
            }
                                        );

            HubProxy.On <Comment>("NewComment", (comment) =>
            {
                Debug.WriteLine("New comment posted. Content: " + comment.Content +
                                ". Status: " + comment.Status + ". Priority: " + comment.Priority);

                try
                {
                    //Ignore if comment was created by issue connector
                    if (comment.AuthorName.Equals("IssueConnector"))
                    {
                        return;
                    }

                    //If comment is created at another system than easy access, ignore
                    if (!EasyAccessMessageFilter.IsOriginalComment(comment))
                    {
                        return;
                    }

                    //If status or priority is updated, send a message with the updated topic
                    if (comment.Status != null || comment.Priority != null)
                    {
                        _publisher.OnInstanceUpdatedAsync(comment.TopicGuid, null, comment.ProjectId);
                    }

                    //Ignore comment if content is empty
                    if (comment.Content.Length > 0)
                    {
                        _publisher.OnCommentCreatedAsync(comment.TopicGuid, comment.Id, comment.AuthorId, comment.ProjectId);
                    }
                }
                catch (Exception e)
                {
                    Debug.WriteLine("Error publishing comment.");
                    Debug.WriteLine(e.StackTrace);
                }
            }

                                  );

            HubProxy.On <Comment>("DeletedComment", (comment) =>
            {
                //TODO, this is probably not critical to implement at the moment
            }
                                  );

            HubProxy.On <ViewPoint>("NewViewPoint", (viewpoint) => {
                Debug.WriteLine("New viewpoint created: " + viewpoint.Id);
                _publisher.OnViewpointCreatedAsync(viewpoint.TopicGuid, viewpoint.Id, viewpoint.ProjectId, viewpoint.CommentGuid);
            }
                                    );

            HubProxy.On <ViewPoint>("DeletedViewPoint", (viewpoint) => { }
                                    );

            try
            {
                await Connection.Start();
            }
            catch (HttpRequestException)
            {
                Debug.WriteLine("Unable to connect to server: Start server before connecting clients.");
                //No connection
                return;
            }
        }