Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        /// <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);
            }
        }
Esempio n. 3
0
        /// <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);
            }
        }