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();
        }
        /// <summary>
        /// Get user boards
        /// </summary>
        /// <returns>User boars</returns>
        public ActionResult GetBoards()
        {
            var boards = TrelloInstance.Boards.ForMe().OrderBy(b => b.Name);
            var retBoards = new List<object>();
            foreach (var board in boards)
            {
                retBoards.Add(new { board.Id, board.Name, board.Closed, board.IdOrganization, board.Desc });
            }

            return CreateResponse(retBoards);
        }
        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();
        }
        private void CardImportWork(object sender, EventArgs eventArgs, bool update)
        {
            view.ShowStatusMessage((update ? "Updating" : "Importing") + " cards...");
            view.EnableImport = false;
            view.EnableUpdate = false;
            view.EnableSelectionOfBoards = false;
            view.EnableSelectionOfLists = false;
            view.EnableSelectionOfLabels = false;

            trello.Async.Cards.ForBoard(view.SelectedBoard, BoardCardFilter.Open)
                .ContinueWith(t =>
                {
                    if (t.Exception != null)
                    {
                        HandleException(t.Exception);
                        return;
                    }

                    List<Card.Label> checkedLabels = new List<Card.Label>();

                    foreach (KeyValuePair<Color, string> kvp in view.CheckedLabels)
                    {
                        Card.Label label = new Card.Label();
                        label.Color = kvp.Key;
                        label.Name = kvp.Value;
                        checkedLabels.Add(label);
                    }

                    // We should only import cards in lists the user selected
                    var cardsToImport = GetCardsForSelectedLists(t.Result, view.FieldsToInclude, checkedLabels);

                    // Create a range based on the current selection. Rows = number of cards, Columns = 4 (to fit name, desc, list and due date)
                    var numberOfRows = cardsToImport.GetUpperBound(0) + 1;
                    var numberOfColumns = view.FieldsToInclude.Count();
                    var rangeThatFitsAllCards = ResizeToFitAllCards(Globals.ThisAddIn.Application.ActiveWindow.RangeSelection, numberOfRows, numberOfColumns);

                    // Store the address of this range for later user
                    var addressToFirstCell = rangeThatFitsAllCards.AddressLocal;

                    if (!update)
                    {
                        // Kind of copy/paste this range
                        InsertRange(rangeThatFitsAllCards);

                        // The rangeThatFitsAllCards was change after the InsertRange call, so create a new range based on addressToFirstCell
                        rangeThatFitsAllCards = ResizeToFitAllCards(Globals.ThisAddIn.Application.ActiveSheet.Range(addressToFirstCell), numberOfRows, numberOfColumns);
                    }

                    // Set the values of the cells to the cards name, desc and due date
                    UpdateRangeWithCardsToImport(rangeThatFitsAllCards, cardsToImport);

                    view.ShowStatusMessage(string.Format("{0} card(s) imported!", numberOfRows - 1));
                    view.EnableImport = true;
                    view.EnableUpdate = true;
                    view.EnableSelectionOfBoards = true;
                    view.EnableSelectionOfLists = true;
                    view.EnableSelectionOfLabels = true;
                }, taskScheduler);
        }
        private static void AddCards(List<DevCard> list, List backlog, ITrello trello, int count)
        {
            _cards = new List<Card>();
            _dic = new Dictionary<Card, DevCard>();

            foreach (var devCard in list)
            {
                Console.WriteLine(devCard.ToString());
                var cardname = GetCardName(devCard);

                var cc = new NewCard(cardname, backlog);
                var msg = devCard.ToString();
                msg += Environment.NewLine + Environment.NewLine +
                       string.Format("Feature:{0} Priority:{1}    {2}",
                           devCard.Feature + Environment.NewLine, devCard.Priority + Environment.NewLine,
                           devCard.Notes + Environment.NewLine);
                cc.Desc = msg;

                var card =
                  trello.Cards.ForList(backlog).FirstOrDefault(a => a.Name.ToLowerInvariant() == cardname.ToLowerInvariant());

                if (card == null)
                {
                    card = trello.Cards.Add(cc);
                }

                _cards.Add(card);
                _dic.Add(card, devCard);

            }
        }
        private static List<DevCard> ExtractDevCards()
        {
            var worksheet = _pck.Workbook.Worksheets.First(x => x.Name == "Backlog");

                Console.WriteLine(worksheet.Name);

                var list = new List<DevCard>();

                var start = worksheet.Dimension.Start;
                var end = worksheet.Dimension.End;
                for (var row = start.Row; row <= end.Row; row++)
                {
                    if (row <= 1) continue;
                    if (row > 50) break;
                    Rows.Add(row);
                    var dc = new DevCard();
                    for (var col = start.Column; col <= end.Column; col++)
                    {
                        // ... Cell by cell...
                        object cellValue = worksheet.Cells[row, col].Text; // This got me the actual value I needed.
                        Debug.WriteLine(cellValue);
                        if (col > 50) break;
                        switch (col)
                        {
                            case 1:
                                dc.Milestone = Convert.ToString(cellValue);
                                break;
                            case 3:
                                dc.Feature = Convert.ToString(cellValue);
                                break;
                            case 4:
                                dc.AsA = Convert.ToString(cellValue);
                                break;
                            case 5:
                                dc.IWantTo = Convert.ToString(cellValue);
                                break;
                            case 6:
                                dc.SoThat = Convert.ToString(cellValue);
                                break;
                            case 7:
                                dc.Priority = Convert.ToString(cellValue);
                                break;
                            case 8:
                                var ss = Convert.ToString(cellValue);
                                var no = string.IsNullOrEmpty(ss) ? "5" : ss;
                                dc.EstimatedHours = Convert.ToInt16(no);
                                break;
                            case 9:
                                dc.Notes = Convert.ToString(cellValue);
                                break;
                        default:
                                int icol;
                                if (_columnIndexes.TryGetValue("UAC", out icol))
                                    if (icol == col)
                                    {
                                        dc.AcceptanceCriteria = Convert.ToString(cellValue);
                                    }
                                break;
                        }
                    }
                    list.Add(dc);
                }
                return list;
        }
        /// <summary>
        /// Separate <paramref name="cards"/> by card labels
        /// </summary>
        /// <param name="cards">Unsepareted cards</param>
        /// <returns>Separeted cards</returns>
        public static IEnumerable<Card> SepareteCardByLabels(IEnumerable<Card> cards)
        {
            var separeted = new List<Card>();
            foreach (var card in cards)
            {
                // if more than one label, you should be separately
                if (card.Labels.Count > 1)
                {
                    foreach (var label in card.Labels)
                    {
                        var newCard = new Card();
                        newCard.InjectFrom(card);
                        newCard.Labels = new List<Card.Label> { label };
                        separeted.Add(newCard);
                    }
                }
                else
                {
                    separeted.Add(card);
                }
            }

            return separeted;
        }
        /// <summary>
        /// Get card Ids from all action
        /// </summary>
        /// <param name="trello">trello interface</param>
        /// <param name="boardId">board Id</param>
        /// <param name="startDate">filter start date</param>
        /// <param name="endDate">filter end date</param>
        /// <returns>List of card ids</returns>
        public static List<string> GetCardIdsFromActions(ITrello trello, string boardId, DateTime startDate, DateTime endDate)
        {
            var actions = trello.Actions.ForBoard(
                            new BoardId(boardId),
                            since: Since.Date(startDate),
                            paging: new Paging(1000, 0),
                            filter: CardActionTypes);
            var changedCardActions = actions.Where(a => a.Date > startDate && a.Date < endDate).ToList();
            var changedCardIds = new List<string>();
            foreach (var changedCardAction in changedCardActions)
            {
                // get only cards
                var cardId = GetCardIdFromAction(changedCardAction);

                // modified card
                if (!string.IsNullOrEmpty(cardId))
                {
                    // card id isnt exist
                    if (!changedCardIds.Contains(cardId))
                    {
                        changedCardIds.Add(cardId);
                    }
                }
            }

            return changedCardIds;
        }
        public List<Board> GetSelectedBoard()
        {
            List<Board> boards = new List<Board>();
            foreach (TreeNode tv in View.TreeViewBoards.Nodes)
            {
                Board b = tv.Tag as Board;

                if (tv.Checked && b != null)
                {
                    boards.Add(b);
                    b.Lists.Clear();
                    foreach (TreeNode tl in tv.Nodes)
                    {
                        List l = tl.Tag as List;
                        if (tl.Checked && l != null)
                        {
                            b.Lists.Add(l);
                        }
                    }
                }
            }
            return boards;
        }
        //public void GetTotalCompletedPointsAsOfDate(DateTime date)
        //{
        //    var points = BoardStats.CardStats.Where(c => c.DoneAction.Date < date).Sum(c => c.CardData.Points);
        //}
        private List<WeekStats> GetWeeklyStats()
        {
            var weekStatsList = new List<WeekStats>();

            for (int week = 1; week <= CompletedWeeksElapsed +1; week++)
            {

                var startDay = BoardStats.ProjectStartDate.AddDays(week * 7);

                //TODO: Why does this occasionally go past the current week. Occured on July 31st and august 1st.
                if (startDay > DateTime.Now)
                    continue;
                var endDay = startDay.AddDays(7);
                if(startDay.DayOfWeek != DayOfWeek.Monday || endDay.DayOfWeek != DayOfWeek.Monday)
                {

                }
                var completedCards = BoardStats.CardStats.Where(c => !c.IsInProgress && !c.IsInTest && c.DoneAction.DateInTimeZone(_configuration.TimeZone) >= startDay && c.DoneAction.DateInTimeZone(_configuration.TimeZone) < endDay);
                var inProgressCards = BoardStats.CardStats.Where(c => c.IsInProgress && c.EffectiveStartAction.DateInTimeZone(_configuration.TimeZone) >= startDay && c.EffectiveStartAction.DateInTimeZone(_configuration.TimeZone) < endDay);
                var inTestCards = BoardStats.CardStats.Where(c => c.IsInTest && c.EffectiveStartAction.DateInTimeZone(_configuration.TimeZone) >= startDay && c.EffectiveStartAction.DateInTimeZone(_configuration.TimeZone) < endDay);
                var timesheetEntries = BoardStats.TimesheetData.Where(t => t.Week == week && t.Category != _configuration.GoogleTimesheetsExcludeCategoryFromTotalHours).ToList();
                var excludedTimesheetEntries = BoardStats.TimesheetData.Where(t => t.Week == week && t.Category == _configuration.GoogleTimesheetsExcludeCategoryFromTotalHours).ToList();

                WeekStats weekStats = new WeekStats() { Cards = completedCards, CardsInProgress = inProgressCards, CardsInTest = inTestCards, WeekNumber = week, StartDate = startDay, EndDate = endDay, TimesheetEntries = timesheetEntries, ExcludedTimesheetEntries = excludedTimesheetEntries };
                weekStatsList.Add(weekStats);
            }
            return weekStatsList;
        }
Beispiel #11
0
        private IEnumerable<List> GetListsToScan(List<List> listsInBoard)
        {
            var doneLists = listsInBoard.Where(l => _configuration.ListNames.DoneListNames.Contains(l.Name));

            var listsToScan = new List<List>(doneLists);
            listsToScan.Add(listsInBoard.Single(l => l.Name == _configuration.ListNames.InProgressListName));
            listsToScan.Add(listsInBoard.Single(l => l.Name == _configuration.ListNames.InTestListName));
            foreach (var listName in _configuration.ListNames.ExtraListsToInclude)
            {
                listsToScan.Add(listsInBoard.Single(l => l.Name == listName));
            }
            return listsToScan.Distinct();
        }