private static string[] CreateStringArrayFromCard(Card card, IEnumerable<List> lists, IEnumerable<string> fieldsToInclude) { var list = new List<string>(); if(fieldsToInclude.Contains("Name")) list.Add(card.Name); if (fieldsToInclude.Contains("Description")) list.Add(card.Desc); if (fieldsToInclude.Contains("Due Date")) list.Add(card.Due.ToString()); if (fieldsToInclude.Contains("List")) list.Add(lists.FirstOrDefault() != null ? lists.FirstOrDefault().Name : null); return list.ToArray(); }
private static string[] CreateStringArrayFromCard(Card card, IEnumerable<List> lists, IEnumerable<string> fieldsToInclude) { var list = new List<string>(); Match match = Regex.Match(card.Name, @"(.*)?\[(([0-9]+)/)?([0-9]+)\](.*)?"); if (fieldsToInclude.Contains("Name")) { if (match.Success) { list.Add(match.Groups[1].Value.Trim() + match.Groups[5].Value); } else { list.Add(card.Name); } } if (fieldsToInclude.Contains("Description")) list.Add(card.Desc); if (fieldsToInclude.Contains("Due Date")) list.Add(card.Due.ToString()); if (fieldsToInclude.Contains("List")) list.Add(lists.FirstOrDefault() != null ? lists.FirstOrDefault().Name : null); int est = -1, log = -1, taskEst = -1, taskLog = -1; if (match.Success) { est = int.Parse(match.Groups[4].Value); } if (match.Success) { if (match.Groups[3].Value.Trim() != "") log = int.Parse(match.Groups[3].Value); } string relTasks = "", allTasks = ""; int i = 0; foreach (TrelloNet.Card.Checklist cl in card.Checklists) { Match clMatch = Regex.Match(cl.Name, @"\{(.*?)\}"); bool relevant = false; if (!clMatch.Success || clMatch.Groups[1].Value == (lists.FirstOrDefault() != null ? lists.FirstOrDefault().Name : null)) relevant = true; foreach (TrelloNet.Card.CheckItem ci in cl.CheckItems) { Match ciMatch = Regex.Match(ci.Name, @"(.*)?\[(([0-9]+)/)?([0-9]+)\](.*)?"); if (ciMatch.Success) { if (taskEst < 0) taskEst = 0; if (taskLog < 0) taskLog = 0; taskEst += int.Parse(ciMatch.Groups[4].Value); if (ci.Checked) taskLog += int.Parse(ciMatch.Groups[4].Value); else if (ciMatch.Groups[3].Value.Trim() != "") taskLog += int.Parse(ciMatch.Groups[3].Value); } string ciName = ciMatch.Groups[0].Value.Trim() + ciMatch.Groups[5].Value; if (relevant) relTasks += (i++ > 0 ? ",\r\n" : "") + ciName; allTasks += (i++ > 0 ? ",\r\n" : "") + ciName; } } if (fieldsToInclude.Contains("Estimates")) { if (taskEst >= 0) list.Add(taskEst.ToString()); else if (est >= 0) list.Add(est.ToString()); else list.Add(""); } if (fieldsToInclude.Contains("Time Log")) { if (taskLog >= 0) list.Add(taskLog.ToString()); else if (log >= 0) list.Add(log.ToString()); else list.Add(""); } if (fieldsToInclude.Contains("Labels")) { var labelStrings = from l in card.Labels select l.Name + "(" + l.Color.ToString() + ")"; string labelString = ""; foreach (string l in labelStrings) { labelString += (labelString.Length > 0?",\r\n":"") + l; } list.Add(labelString); } if (fieldsToInclude.Contains("Tasks (Relevant)")) { list.Add(relTasks); } if (fieldsToInclude.Contains("Tasks (All)")) { list.Add(allTasks); } return list.ToArray(); }