public CardHistory(ListsStruct listsStruct, Card card, IEnumerable <string> organizationMembers) { Card = card; Labels = card.Labels; var createActionArray = listsStruct.TrelloFirstList.Actions.Filter(ActionType.CreateCard).ToArray(); var hasCreateAction = createActionArray.Any(a => a.Data.Card.Id == card.Id); var createAction = hasCreateAction ? createActionArray.First(a => a.Data.Card.Id == card.Id) : null; Creator = hasCreateAction ? createAction.Creator : null; CreationDateTime = hasCreateAction ? createAction.Date.GetValueOrDefault() : DateTime.Now; TrelloRequestCounter.TrelloPostCount += 3; InWorkActionRecordList = FillActionRecordList(Creator, card.Actions.Filter(ActionType.UpdateCard).ToArray(), listsStruct.TrelloInWorkList, organizationMembers); Comments = new List <Comment>(); foreach ( var comment in card.Comments.Where( c => organizationMembers.Contains(c.Creator.UserName) && (c.Data.Text.StartsWith("+") || c.Data.Text.StartsWith("-")))) { TrelloRequestCounter.TrelloPostCount += 1; Comments.Add(new Comment(comment)); } }
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); }
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); }