コード例 #1
0
 public async Task <DateTime?> GetStatusEtaFromNowUtcAsync(InitiativeStatus initiativeStatus)
 {
     if (StatusToEtaMap.ContainsKey(initiativeStatus))
     {
         var          etaDefinition = StatusToEtaMap[initiativeStatus];
         TimeZoneInfo albertaTimeZone;
         try { albertaTimeZone = TimeZoneInfo.FindSystemTimeZoneById("America/Edmonton"); }
         catch (TimeZoneNotFoundException)
         {
             _logger.Error("Unable to find Mountain Standard Time zone");
             throw;
         }
         var      nowAlberta = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, albertaTimeZone);
         DateTime returnValue;
         if (etaDefinition.EtaType == EtaType.BusinessSeconds)
         {
             returnValue = await _businessCalendarService.AddBusinessTime(nowAlberta, TimeSpan.FromSeconds(etaDefinition.Time));
         }
         else
         {
             returnValue = await _businessCalendarService.AddBusinessDays(nowAlberta, etaDefinition.Time);
         }
         returnValue = TimeZoneInfo.ConvertTimeToUtc(returnValue, albertaTimeZone);
         return(returnValue);
     }
     else
     {
         return(null);
     }
 }
コード例 #2
0
        public async Task <string> GetStatusChangeTextAsync(InitiativeStatus status, bool isPastTense = false)
        {
            TemplateKey key = new TemplateKey()
            {
                Category = StringTemplateCategory.StatusDescription,
                Key      = string.Concat(status.ToString(), isPastTense ? "_past" : "_present")
            };
            string template = _stringTemplateCache.ContainsKey(key) ? _stringTemplateCache[key] : null;

            if (string.IsNullOrWhiteSpace(template))
            {
                template = await _ideaContext.StringTemplates
                           .Where(x => x.Category == key.Category && x.Key == key.Key)
                           .Select(x => x.Text)
                           .FirstOrDefaultAsync();

                if (string.IsNullOrWhiteSpace(template))
                {
                    throw new KeyNotFoundException($"Unable to find a StringTemplate with category {key.Category} and key {key.Key}");
                }

                _stringTemplateCache[key] = template;
            }

            return(template);
        }
コード例 #3
0
        public void UpdateStatus(InitiativeStatus newStatus,
                                 DateTime?newEta)
        {
            var oldStatus = Status;

            Status = newStatus;

            // pop any stathistories after or including this one
            foreach (var toRemove in _statusHistories.Where(x => (int)x.Status > (int)newStatus).ToList())
            {
                _statusHistories.Remove(toRemove);
            }
            var existingStatus = _statusHistories.SingleOrDefault(x => x.Status == newStatus);

            if (existingStatus == null)
            {
                _statusHistories.Add(
                    InitiativeStatusHistory.CreateInitiativeStatusChange(
                        Uid, newStatus, DateTime.UtcNow, newEta, AssigneeId));
            }
            else
            {
                if (existingStatus.PersonId != AssigneeId)
                {
                    existingStatus.SetPersonId(AssigneeId);
                }
            }

            AddDomainEvent(new InitiativeStatusChangedDomainEvent(this.Uid, oldStatus));
        }
コード例 #4
0
        private static string GetTitle(InitiativeStatus status)
        {
            switch (status)
            {
            case InitiativeStatus.Initiate:
                return("Initiated");

            case InitiativeStatus.Submit:
                return("Submitted");

            case InitiativeStatus.Review:
                return("In Review");

            case InitiativeStatus.Collaborate:
                return("In Collaboration");

            case InitiativeStatus.Deliver:
                return("In Delivery");

            case InitiativeStatus.Cancelled:
                return("Cancelled");

            default:
                return(status.ToString());
            }
        }
コード例 #5
0
 internal static InitiativeStatusHistory CreateInitiativeStatusChange(Guid initiativeId,
                                                                      InitiativeStatus newStatus,
                                                                      DateTime statusEntryDateUtc,
                                                                      DateTime?expectedExitDateUtc,
                                                                      int?personId)
 {
     return(new InitiativeStatusHistory()
     {
         Status = newStatus,
         StatusEntryDateUtc = statusEntryDateUtc,
         ExpectedExitDateUtc = expectedExitDateUtc,
         PersonId = personId
     });
 }
 /// <summary>
 /// Sets the status on the initiative according to the Remedy Work Order status
 /// </summary>
 /// <param name="initiative"></param>
 /// <param name="workOrderStatus"></param>
 /// <param name="workOrderLastModifiedUtc"></param>
 /// <returns>True if the initiative status is updated, otherwise false</returns>
 protected bool UpdateIdeaWithNewWorkOrderStatus(Initiative initiative, InitiativeStatus newIdeaStatus, DateTime workOrderLastModifiedUtc, DateTime?etaUtc)
 {
     if (initiative.Status != newIdeaStatus)
     {
         _logger.Information("Updating status of initiative {InitiativeId} from {FromInitiativeStatus} to {ToIdeaStatus} because Remedy was updated on {LastModifiedDateUtc}",
                             initiative.Id, initiative.Status, newIdeaStatus, workOrderLastModifiedUtc);
         initiative.UpdateStatus(newIdeaStatus, etaUtc);
         return(true);
     }
     else
     {
         _logger.Information("Not updating status because it has not changed from: {Status}", initiative.Status);
         return(false);
     }
 }
 internal InitiativeStatusChangedDomainEvent(Guid initiativeId, InitiativeStatus previousInitiativeStatus)
 {
     InitiativeId   = initiativeId;
     PreviousStatus = previousInitiativeStatus;
 }
コード例 #8
0
        internal static async Task <IEnumerable <InitiativeStepDetail> > FromInitiativeStatusHistoriesAsync(IEnumerable <InitiativeStatusHistory> steps,
                                                                                                            IPersonRepository personRepository,
                                                                                                            IStringTemplateService stringTemplateService)
        {
            if (steps == null || !steps.Any())
            {
                return(null);
            }

            EnsureArg.IsNotNull(stringTemplateService);
            var lastStep = steps.OrderByDescending(x => x.StatusEntryDateUtc).First();

            var stack = new Stack <InitiativeStepDetail>();

            foreach (var step in steps)
            {
                var stepDto = new InitiativeStepDetail()
                {
                    StepId      = (int)step.Status,
                    Title       = GetTitle(step.Status),
                    Description = step.StatusDescriptionOverride,
                    StartDate   = step.StatusEntryDateUtc.ToLocalTime()
                };
                if (stack.Count > 0)
                {
                    stack.Peek().CompletionDate = stepDto.StartDate;
                }

                // now fill in the text here
                if (string.IsNullOrWhiteSpace(stepDto.Description))
                {
                    var textTemplate = await stringTemplateService.GetStatusChangeTextAsync(step.Status, step != lastStep);

                    if (!string.IsNullOrWhiteSpace(textTemplate))
                    {
                        string expectedCompletionDateString = null;
                        if (step.ExpectedExitDateUtc.HasValue)
                        {
                            TimeZoneInfo albertaTimeZone         = TimeZoneInfo.FindSystemTimeZoneById("America/Edmonton");
                            var          expectedExitDateAlberta = TimeZoneInfo.ConvertTimeFromUtc(step.ExpectedExitDateUtc.Value, albertaTimeZone);
                            var          nowDateAlberta          = TimeZoneInfo.ConvertTimeFromUtc(DateTime.UtcNow, albertaTimeZone);
                            expectedCompletionDateString = expectedExitDateAlberta.ToStringRelativeToNow(nowDateAlberta);
                            //expectedCompletionDateString = expectedExitDateAlberta.ToString();
                        }
                        Person assignee = null;
                        if (step.PersonId.HasValue)
                        {
                            assignee = await personRepository.GetPersonAsync(step.PersonId.Value);
                        }

                        string assigneeName = assignee?.Name;
                        if (string.IsNullOrWhiteSpace(assigneeName))
                        {
                            assigneeName = "An OCT representative";
                        }
                        stepDto.Description = string.Format(textTemplate, assigneeName, expectedCompletionDateString);
                    }
                }

                stack.Push(stepDto);
            }

            // now add missing statuses
            var allStatuses = new InitiativeStatus[]
            {
                InitiativeStatus.Submit,
                InitiativeStatus.Review,
                InitiativeStatus.Collaborate,
                InitiativeStatus.Deliver
            };

            var remaining = allStatuses.Where(x => !stack.Any(y => y.StepId == (int)x)).OrderBy(x => (int)x)
                            .Select(x => new InitiativeStepDetail()
            {
                StepId = (int)x,
                Title  = GetTitle(x)
            });

            return(stack
                   .Concat(remaining)
                   .OrderBy(x => x.StepId));
        }