Esempio n. 1
0
        public bool AddCardHistory(CardHistory cardHistory, [NotNull] ref string errorRepresent)
        {
            if (errorRepresent == null)
            {
                throw new ArgumentNullException(nameof(errorRepresent));
            }
            var newCardHistory = new itws.CardHistory
            {
                CreatorUserName  = cardHistory.CreatorUserName,
                CreatorId        = cardHistory.CreatorId,
                CreatorEMail     = "",
                Labels           = cardHistory.LabelsNames.ToArray(),
                CardId           = cardHistory.CardId,
                BoardId          = cardHistory.BoardId,
                CreationDateTime = cardHistory.CreationDateTime,
                Name             = cardHistory.Name,
                Text             = cardHistory.Text,
                CardUrl          = cardHistory.Url
            };

            var cardRecordList = new List <CardRecord>();

            cardHistory.InWorkActionRecordList.ForEach(t => cardRecordList.Add(new CardRecord
            {
                BeginerId        = t.BeginerId,
                BeginerUserName  = t.BeginerUserName,
                BeginerEMail     = "",
                FinisherId       = t.FinisherId,
                FinisherUserName = t.FinisherUserName,
                FinisherEMail    = "",
                StartDateTime    = t.StartDateTime,
                FinishDateTime   = t.FinishDateTime,
                ListId           = t.ListId
            }));
            newCardHistory.InWorkActionRecordList = cardRecordList.ToArray();

            var commentsList = new List <Comment>();

            cardHistory.Comments.ForEach(t => commentsList.Add(new Comment
            {
                UserEMail       = "",
                UserName        = t.AuthorUserName,
                CommentDateTime = t.CommentDateTime,
                Text            = t.Text
            }));
            newCardHistory.Comments = commentsList.ToArray();

            errorRepresent = string.Empty;
            return(_service.AddCardHistory(newCardHistory, ref errorRepresent));
        }
Esempio n. 2
0
        public bool ExecuteProcess()
        {
            var settings = GetSettings(typeof(TrelloCheckerSettings)) as TrelloCheckerSettings;

            EnterpriseWsWrapper = new EnterpriseWsWrapper(settings);
            var contractorsArray  = EnterpriseWsWrapper.GetConractorsArray();
            var nomenclatureArray = EnterpriseWsWrapper.GetNomenclatureArray().OrderBy(t => t.Name).Take(MaxLabelCount);

            TrelloAuthorization.Default.AppKey    = settings.TrelloAppKey;
            TrelloAuthorization.Default.UserToken = settings.TrelloUserToken;

            var organization        = new Organization(settings.OrganizationID);
            var organizationMembers = organization.Members.Select(t => t.UserName).ToArray();

            TrelloRequestCounter.TrelloPostCount += 2;

            SyncContractors(contractorsArray, organization, settings);

            foreach (var contractor in contractorsArray)
            {
                CreateLogRecord(contractor.BoardId);
                var board = new Board(contractor.BoardId);
                var label = board.CheckLabel(LabelName, LabelColor);
                board.SyncLabels(nomenclatureArray.Select(t => t.Represent).ToArray(), LabelColor.Purple);

                TrelloRequestCounter.TrelloPostCount += 3;
                var listStruct = new ListsStruct(settings, board);
                if (!listStruct.BoardHaveAllList)
                {
                    CreateLogRecord($"There are not enoght lists in board \"{board.Name}\" ({board.Url})", System.Diagnostics.EventLogEntryType.Error);
                    continue;
                }

                //if (!board.Members.Any(t => t == Member.Me)) board.Memberships.Add(Member.Me, BoardMembershipType.Normal);

                foreach (var card in listStruct.TrelloDoneList.Cards.Where(c => !c.IsArchived.GetValueOrDefault()))
                {
                    TrelloRequestCounter.TrelloPostCount += 1;
                    if (card.Labels.Count(l => l.Name == LabelName) > 0)
                    {
                        continue;
                    }
                    CardHistory cardHistory;
                    try
                    {
                        cardHistory = new CardHistory(listStruct, card, organizationMembers);
                    }
                    catch (Exception e)
                    {
                        CreateLogRecord($"Card history retrieve error. \"{board.Name}\" ({card.Url})", System.Diagnostics.EventLogEntryType.Error);
                        continue;
                    }
                    var errorRepresent = string.Empty;
                    if (EnterpriseWsWrapper.AddCardHistory(cardHistory, ref errorRepresent))
                    {
                        TrelloRequestCounter.TrelloPostCount += 1;
                        card.Labels.Add(label);
                    }
                    else
                    {
                        CreateLogRecord(errorRepresent, System.Diagnostics.EventLogEntryType.Error);
                    }
                }
            }
            return(true);
        }
Esempio n. 3
0
        public bool ExecuteProcess()
        {
            var settings = GetSettings(typeof(TrelloCardReminderSettings)) as TrelloCardReminderSettings;

            var serializer = new ManateeSerializer();

            TrelloConfiguration.Serializer         = serializer;
            TrelloConfiguration.Deserializer       = serializer;
            TrelloConfiguration.JsonFactory        = new ManateeFactory();
            TrelloConfiguration.RestClientProvider = new WebApiClientProvider();
            TrelloAuthorization.Default.AppKey     = settings.TrelloAppKey;
            TrelloAuthorization.Default.UserToken  = settings.TrelloUserToken;

            var organization        = new Organization(settings.OrganizationID);
            var organizationMembers = organization.Members.Select(t => t.UserName).ToArray();

            TrelloRequestCounter.TrelloPostCount += 2;

            foreach (var board in organization.Boards)
            {
                if (!board.Members.Any(t => t == Member.Me))
                {
                    board.Memberships.Add(Member.Me, BoardMembershipType.Normal);
                }

                var listStruct = new ListsStruct(settings, board);
                if (!listStruct.BoardHaveAllList)
                {
                    continue;
                }

                var powerUpSettings = board.GetPowerUpSettings(settings.PowerUpId);

                foreach (var card in listStruct.TrelloInWorkList.Cards.Where(c => !c.IsArchived.GetValueOrDefault()))
                {
                    var estimateHours = Double.MaxValue;
                    if (powerUpSettings != null)
                    {
                        var estimeteValue = powerUpSettings.Where(t => t.Id == $"{settings.EstimateValuePrefix}{card.Id}{settings.EstimateValuePostfix}").FirstOrDefault();
                        if (estimeteValue != null && estimeteValue.Value.Trim() != string.Empty)
                        {
                            estimateHours = Convert.ToDouble(estimeteValue.Value);
                        }
                    }

                    CardHistory cardHistory;
                    try
                    {
                        cardHistory = new CardHistory(listStruct, card, organizationMembers);
                    }
                    catch (Exception e)
                    {
                        CreateLogRecord($"Error while getting card data. Card: {card.Url}", EventLogEntryType.Error);
                        throw;
                    }

                    var allWorkTime        = cardHistory.InWorkActionRecordList.Sum(t => t.Duration) + cardHistory.Comments.Sum(t => t.Value);
                    var lastAction         = cardHistory.InWorkActionRecordList.FirstOrDefault();
                    var lastPeriodWorkTime = lastAction.Duration;

                    if (allWorkTime > estimateHours)
                    {
                        if (settings.MoveCardIfEstimateExceeded)
                        {
                            card.List = listStruct.TrelloFirstList; card.Position = 1;
                        }
                        if (settings.LeaveComment)
                        {
                            card.Comments.Add($"@{lastAction.BeginerUserName}\n{settings.MoveCommentContent}");
                        }
                    }
                    else if (lastAction.Duration > settings.MaxTimeToStayInWork)
                    {
                        if (settings.MoveCardIfMaxTimeExceeded)
                        {
                            card.List = listStruct.TrelloFirstList; card.Position = 1;
                        }
                        if (settings.LeaveComment)
                        {
                            card.Comments.Add($"@{lastAction.BeginerUserName}\n{settings.MoveCommentContent}");
                        }
                    }
                    else if (allWorkTime > (estimateHours - settings.WarnningCommentLeaveTime))
                    {
                        if (settings.LeaveComment)
                        {
                            card.Comments.Add($"@{lastAction.BeginerUserName}\n{settings.WarningCommentContent}");
                        }
                    }
                    else if (lastAction.Duration > (settings.MaxTimeToStayInWork - settings.WarnningCommentLeaveTime))
                    {
                        if (settings.LeaveComment)
                        {
                            card.Comments.Add($"@{lastAction.BeginerUserName}\n{settings.WarningCommentContent}");
                        }
                    }
                }
            }
            return(true);
        }