예제 #1
0
        public IActionResult Push([FromQuery] string accesstoken)
        {
            using (StreamReader reader = new StreamReader(Request.Body))
            {
                string content = reader.ReadToEndAsync().Result;

                string str = content.Replace("<", "");
                str = str.Replace(">", "");
                str = str.Replace("
", "");

                EventXmlModel json = new EventXmlModel
                {
                    CreatedBy      = str.Split("/CreatedBy")[0].Split("CreatedBy")[1].Trim(),
                    PullRequestUri = str.Split("/PullRequestUri")[0].Split("PullRequestUri")[1].Trim()
                };

                _hubContext.Clients.All.SendAsync("Push", JsonConvert.SerializeObject(json));

                var prePullRequestUri = _cache.Get <string>(_cachekey);
                if (prePullRequestUri == json.PullRequestUri)
                {
                    _hubContext.Clients.All.SendAsync("Debug", "duplicate");
                }
                else
                {
                    _cache.Set(_cachekey, json.PullRequestUri);
                    APIPost(accesstoken, "notify", json.CreatedBy + " 有一個PR,請有空的人看一下 : " + json.PullRequestUri);
                }
            }
            return(Ok());
        }
예제 #2
0
        public IActionResult Push([FromQuery] string id, [FromQuery] string channelaccesstoken)
        {
            using (StreamReader reader = new StreamReader(Request.Body))
            {
                string content = reader.ReadToEndAsync().Result;

                string str = content.Replace("&lt;", "");
                str = str.Replace("&gt;", "");
                str = str.Replace("&#xD;", "");

                EventXmlModel json = new EventXmlModel();
                json.CreatedBy      = str.Split("/CreatedBy")[0].Split("CreatedBy")[1].Trim();
                json.PullRequestUri = str.Split("/PullRequestUri")[0].Split("PullRequestUri")[1].Trim();

                _hubContext.Clients.All.SendAsync("Push", JsonConvert.SerializeObject(json));
                LinePush p = new LinePush();
                p.to       = id;
                p.messages = new List <LineMessage>();
                LineMessage message = new LineMessage();
                message.type = "text";
                message.text = json.CreatedBy + " : " + json.PullRequestUri;
                p.messages.Add(message);
                APIPost(channelaccesstoken, "message/push", p);
            }
            return(Ok(id));
        }