/// <summary> /// Filters an entry /// </summary> /// <param name="entry">Entry</param> /// <param name="roles">Roles</param> /// <returns>true if the role is valid, false to filter it</returns> private bool FilterEntry(TimelineEntry entry, IList <string> roles) { if (!_entryRoleFilter.ContainsKey(entry.Event)) { return(true); } return(_entryRoleFilter[entry.Event].All(s => roles.Contains(s))); }
/// <summary> /// Adds a timeline event /// </summary> /// <param name="timelineEvent">Timeline Event</param> /// <param name="additionalValues">Additional Values</param> /// <returns>Task</returns> public async Task AddTimelineEntry(TimelineEvent timelineEvent, params string[] additionalValues) { Task <GoNorthUser> currentUserTask = _userManager.GetUserAsync(_httpContext.HttpContext.User); Task <GoNorthProject> projectTask = _projectDbAccess.GetDefaultProject(); Task.WaitAll(currentUserTask, projectTask); GoNorthUser currentUser = currentUserTask.Result; GoNorthProject project = projectTask.Result; TimelineEntry entry = new TimelineEntry(); entry.ProjectId = project != null ? project.Id : string.Empty; entry.Event = timelineEvent; entry.Timestamp = DateTimeOffset.UtcNow; entry.AdditionalValues = additionalValues; entry.Username = currentUser.UserName; entry.UserDisplayName = currentUser.DisplayName; await _timelineDbAccess.CreateTimelineEntry(entry); }
/// <summary> /// Formats a timeline entry /// </summary> /// <param name="entry">Entry</param> /// <returns>Formatted timeline entry</returns> public FormattedTimelineEntry FormatTimelineEntry(TimelineEntry entry) { string[] escapedValues = entry.AdditionalValues.Select(s => HtmlEncoder.Default.Encode(s)).ToArray(); FormattedTimelineEntry formattedEntry = new FormattedTimelineEntry(); formattedEntry.Timestamp = entry.Timestamp.ToLocalTime(); formattedEntry.UserDisplayName = entry.UserDisplayName; try { formattedEntry.Content = _localizer[entry.Event.ToString(), escapedValues]; } catch(FormatException) { // Handle case that template was updated and has new placeholder for old values List<string> extendedArguments = new List<string>(escapedValues); extendedArguments.AddRange(new List<string> { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty }); formattedEntry.Content = _localizer[entry.Event.ToString(), extendedArguments.ToArray()]; } return formattedEntry; }
/// <summary> /// Adds a timeline event /// </summary> /// <param name="timelineEvent">Timeline Event</param> /// <param name="additionalValues">Additional Values</param> /// <returns>Task</returns> public async Task AddTimelineEntry(TimelineEvent timelineEvent, params string[] additionalValues) { Task <GoNorthUser> currentUserTask = _userManager.GetUserAsync(_httpContext.HttpContext.User); Task <GoNorthProject> projectTask = _projectDbAccess.GetDefaultProject(); Task.WaitAll(currentUserTask, projectTask); GoNorthUser currentUser = currentUserTask.Result; GoNorthProject project = projectTask.Result; string updateId = null; if (_eventMergeTimeSpan > 0) { DateTimeOffset dateLimit = DateTimeOffset.UtcNow.AddMinutes(-_eventMergeTimeSpan); List <TimelineEntry> timelineEntries = await _timelineDbAccess.GetTimelineEntriesByUserInTimeSpan(project.Id, currentUser.UserName, timelineEvent, dateLimit); foreach (TimelineEntry curEntry in timelineEntries) { if (curEntry.AdditionalValues == null && additionalValues == null) { updateId = curEntry.Id; break; } else if (curEntry.AdditionalValues == null || additionalValues == null) { continue; } if (curEntry.AdditionalValues.Length != additionalValues.Length) { continue; } bool isNotValid = false; for (int curAdditionalValue = 0; curAdditionalValue < additionalValues.Length; ++curAdditionalValue) { if (curEntry.AdditionalValues[curAdditionalValue] != additionalValues[curAdditionalValue]) { isNotValid = true; break; } } if (isNotValid) { continue; } updateId = curEntry.Id; break; } } TimelineEntry entry = new TimelineEntry(); entry.ProjectId = project != null ? project.Id : string.Empty; entry.Event = timelineEvent; entry.Timestamp = DateTimeOffset.UtcNow; entry.AdditionalValues = additionalValues; entry.Username = currentUser.UserName; entry.UserDisplayName = currentUser.DisplayName; if (string.IsNullOrEmpty(updateId)) { await _timelineDbAccess.CreateTimelineEntry(entry); } else { entry.Id = updateId; await _timelineDbAccess.UpdateTimelineEntry(entry); } }
/// <summary> /// Adds a timeline entry with a user /// </summary> /// <param name="projectId">Id of the project to associate, if null the project will be loaded</param> /// <param name="userDisplayName">User Displayname</param> /// <param name="userLoginName">Userl oginname</param> /// <param name="timelineEvent">Timeline Event</param> /// <param name="additionalValues">Additional Values</param> /// <returns>Task</returns> private async Task AddTimlineEntry(string projectId, string userDisplayName, string userLoginName, TimelineEvent timelineEvent, params string[] additionalValues) { if (string.IsNullOrEmpty(projectId)) { GoNorthProject project = await _userProjectAccess.GetUserProject(); projectId = project != null ? project.Id : string.Empty; } string updateId = null; if (_eventMergeTimeSpan > 0) { DateTimeOffset dateLimit = DateTimeOffset.UtcNow.AddMinutes(-_eventMergeTimeSpan); List <TimelineEntry> timelineEntries = await _timelineDbAccess.GetTimelineEntriesByUserInTimeSpan(projectId, userLoginName, timelineEvent, dateLimit); foreach (TimelineEntry curEntry in timelineEntries) { if (curEntry.AdditionalValues == null && additionalValues == null) { updateId = curEntry.Id; break; } else if (curEntry.AdditionalValues == null || additionalValues == null) { continue; } if (curEntry.AdditionalValues.Length != additionalValues.Length) { continue; } bool isNotValid = false; for (int curAdditionalValue = 0; curAdditionalValue < additionalValues.Length; ++curAdditionalValue) { if (curEntry.AdditionalValues[curAdditionalValue] != additionalValues[curAdditionalValue]) { isNotValid = true; break; } } if (isNotValid) { continue; } updateId = curEntry.Id; break; } } TimelineEntry entry = new TimelineEntry(); entry.ProjectId = projectId; entry.Event = timelineEvent; entry.Timestamp = DateTimeOffset.UtcNow; entry.AdditionalValues = additionalValues; entry.Username = userLoginName; entry.UserDisplayName = userDisplayName; if (string.IsNullOrEmpty(updateId)) { await _timelineDbAccess.CreateTimelineEntry(entry); } else { entry.Id = updateId; await _timelineDbAccess.UpdateTimelineEntry(entry); } }