Ejemplo n.º 1
0
        public override Task ExecuteAsync(string generator, WebHookHandlerContext context)
        {
            // For more information about Slack WebHook payloads, please see 
            // 'https://api.slack.com/outgoing-webhooks'
            NameValueCollection entry = context.GetDataOrDefault<NameValueCollection>();

            // We can trace to see what is going on.
            Trace.WriteLine(entry.ToString());

            // Switch over the IDs we used when configuring this WebHook 
            switch (context.Id)
            {
                case "trigger":
                    MatchCollection matches = Regex.Matches(entry["text"], pattern);
                    var spreadsheetService = new GoogleDocService();
                    foreach (Match match in matches)
                    {
                        var insertItem = new Bill
                        {
                            Money = match.Groups["money"].Value,
                            ShopName = match.Groups["shopname"].Value,
                            Date = DateTime.ParseExact(DateTime.Today.Year + "/" + match.Groups["date"].Value, "yyyy/MM/dd", CultureInfo.InvariantCulture),
                            UserName = match.Groups["username"].Value
                        };
                        spreadsheetService.Insert(insertItem);
                    }

                    // Information can be returned using a SlackResponse
                    var triggerReply = new SlackResponse(
                        "Update Google SpreadSheet(RTBS 체크카드 사용 내역서)" + 
                        Environment.NewLine + 
                        "누적 " + spreadsheetService.GetTotalMoney() + "원");
                    context.Response = context.Request.CreateResponse(triggerReply);
                    break;

                case "slash":
                    // Information can be returned in a plain text response
                    context.Response = context.Request.CreateResponse();
                    context.Response.Content = new StringContent("Hello slash command!");
                    break;
            }

            return Task.FromResult(true);
        }
Ejemplo n.º 2
0
        public bool Insert(Bill bill)
        {
            var ret = false;
            SpreadsheetQuery query = new SpreadsheetQuery();

            // Make a request to the API and get all spreadsheets.
            SpreadsheetFeed feed = _spreadsheetService.Query(query);

            var _spreadsheet = feed.Entries.FirstOrDefault(s => s.Title.Text == "RTBS 체크카드 사용 내역서");
            var spreadsheet = _spreadsheet as SpreadsheetEntry;
            if (spreadsheet != null)
            {
                var worksheet = spreadsheet.Worksheets.Entries.FirstOrDefault();
                if (worksheet != null)
                {
                    AtomLink listFeedLink = worksheet.Links.FindService(GDataSpreadsheetsNameTable.ListRel, null);
                    // Fetch the list feed of the worksheet.
                    ListQuery listQuery = new ListQuery(listFeedLink.HRef.ToString());
                    ListFeed listFeed = _spreadsheetService.Query(listQuery);
                    var currentNo = string.Empty;
                    foreach (var entry in listFeed.Entries)
                    {
                        var curRow = entry as ListEntry;
                        if (curRow != null)
                        {
                            foreach (ListEntry.Custom curElement in curRow.Elements)
                            {
                                if (curElement.LocalName == "rtbs체크카드사용내역서")
                                {
                                    currentNo = curElement.Value;
                                }
                            }
                        }
                    }
                    if (string.IsNullOrWhiteSpace(currentNo) || currentNo == "No")
                    {
                        currentNo = "1";
                    }
                    else
                    {
                        int temp;
                        if (int.TryParse(currentNo, out temp) && temp > 0)
                        {
                            temp++;
                            currentNo = temp.ToString();
                        }
                        else
                        {
                            currentNo = "1";
                        }
                    }
                    //// Create a local representation of the new row.
                    ListEntry row = new ListEntry();
                    row.Elements.Add(new ListEntry.Custom() { LocalName = "rtbs체크카드사용내역서", Value = currentNo });
                    row.Elements.Add(new ListEntry.Custom() { LocalName = "_cokwr", Value = bill.Date.ToString("yyyy. MM. dd") });
                    row.Elements.Add(new ListEntry.Custom() { LocalName = "_cpzh4", Value = bill.ShopName });
                    row.Elements.Add(new ListEntry.Custom() { LocalName = "_cre1l", Value = bill.Money.Replace("원","").Replace(",","") });
                    row.Elements.Add(new ListEntry.Custom() { LocalName = "_chk2m", Value = bill.Purpose });
                    row.Elements.Add(new ListEntry.Custom() { LocalName = "_ciyn3", Value = bill.UserName });

                    //// Send the new row to the API for insertion.
                    var result = _spreadsheetService.Insert(listFeed, row);
                    ret = true;
                }
            }

            return ret;
        }