Esempio n. 1
0
        public async Task <IEnumerable <Discussion> > GetDiscussions(int itemId, int projectId)
        {
            var discussionsPrm = new DynamicParameters();

            discussionsPrm.Add("@ItemId", itemId);

            var comments     = (await _connectionWrapper.QueryMultipleAsync <Discussion, ThreadReviewTrace>("GetItemDiscussions", discussionsPrm, commandType: CommandType.StoredProcedure));
            var discussions  = comments.Item1.ToList();
            var associations = comments.Item2.ToList();

            foreach (var d in discussions)
            {
                d.AssociatedReviews = associations.Where(a => a.ThreadId == d.DiscussionId).Select(a => a.ReviewId).ToList();
            }
            var discussionStates           = (await GetItemDiscussionStates(itemId)).ToDictionary(k => k.DiscussionId);
            var areEmailDiscussionsEnabled = await _mentionHelper.AreEmailDiscussionsEnabled(projectId);

            await InitializeCommentsProperties(discussions, areEmailDiscussionsEnabled, (discussion) => {
                var discussionState = (DiscussionState)null;
                if (discussionStates.TryGetValue(discussion.DiscussionId, out discussionState))
                {
                    discussion.IsClosed     = discussionState.IsClosed;
                    discussion.Status       = discussionState.Status;
                    var lastEditedOn        = DateTime.SpecifyKind(discussionState.LastEditedOn, DateTimeKind.Utc);
                    discussion.LastEditedOn = Max(discussion.LastEditedOn, lastEditedOn);
                }
            });

            return(discussions.OrderByDescending(d => d.LastEditedOn));
        }
Esempio n. 2
0
        /// <summary>
        /// Return metadata for a Full Text Search
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="searchCriteria">SearchCriteria object</param>
        /// <returns>FullTextSearchMetaDataResult</returns>
        public async Task <MetaDataSearchResultSet> FullTextMetaData(int userId, FullTextSearchCriteria searchCriteria)
        {
            string sql;
            var    param = new DynamicParameters();

            param.Add("@userId", userId);
            param.Add("@query", GetQuery(searchCriteria.Query));
            param.Add("@projectIds", SqlConnectionWrapper.ToDataTable(searchCriteria.ProjectIds));
            param.Add("@predefineds", Predefineds);
            param.Add("@primitiveItemTypePredefineds", PrimitiveItemTypePredefineds);
            param.Add("@maxItems", _searchConfigurationProvider.MaxItems);
            param.Add("@maxSearchableValueStringSize", _searchConfigurationProvider.MaxSearchableValueStringSize);
            if (searchCriteria.ItemTypeIds?.ToArray().Length > 0)
            {
                param.Add("@itemTypeIds", SqlConnectionWrapper.ToDataTable(searchCriteria.ItemTypeIds));
                sql = "SearchFullTextByItemTypesMetaData";
            }
            else
            {
                sql = "SearchFullTextMetaData";
            }

            try
            {
                var result =
                    await
                    _connectionWrapper.QueryMultipleAsync <MetaDataSearchResult, int?>(sql, param,
                                                                                       commandType : CommandType.StoredProcedure,
                                                                                       commandTimeout : _searchConfigurationProvider.SearchTimeout);

                return(new MetaDataSearchResultSet
                {
                    Items = result.Item1,
                    TotalCount = result.Item2.ElementAt(0) ?? 0,
                });
            }
            catch (SqlException sqlException)
            {
                switch (sqlException.Number)
                {
                // Sql timeout error
                case ErrorCodes.SqlTimeoutNumber:
                    throw new SqlTimeoutException("Server did not respond with a response in the allocated time. Please try again later.", ErrorCodes.Timeout);
                }
                throw;
            }
        }
        private async Task <Tuple <IEnumerable <ProjectsArtifactsItem>, IEnumerable <VersionProjectInfo> > > GetArtifactsProjects(
            IEnumerable <int> itemIds, int sessionUserId, int revisionId, bool addDrafts, IDbTransaction transaction = null)
        {
            var parameters = new DynamicParameters();

            parameters.Add("@userId", sessionUserId);
            parameters.Add("@itemIds", SqlConnectionWrapper.ToDataTable(itemIds));

            if (transaction == null)
            {
                return(await _connectionWrapper.QueryMultipleAsync <ProjectsArtifactsItem, VersionProjectInfo>("GetArtifactsProjects", parameters, commandType : CommandType.StoredProcedure));
            }

            using (var command = await transaction.Connection.QueryMultipleAsync("GetArtifactsProjects", parameters, transaction, commandType: CommandType.StoredProcedure))
            {
                var projectsAtifacts = command.Read <ProjectsArtifactsItem>().ToList();
                var versionProjects  = command.Read <VersionProjectInfo>().ToList();

                return(new Tuple <IEnumerable <ProjectsArtifactsItem>, IEnumerable <VersionProjectInfo> >(projectsAtifacts, versionProjects));
            }
        }
        public async Task <SearchArtifactsResult> GetCollectionContentSearchArtifactResults(
            int scopeId, Pagination pagination, bool includeDrafts, int userId, IDbTransaction transaction)
        {
            var searchArtifactsResult = new SearchArtifactsResult {
                ArtifactIds = new List <int>()
            };

            Tuple <IEnumerable <int>, IEnumerable <int> > result;

            if (transaction == null)
            {
                result = await _connectionWrapper.QueryMultipleAsync <int, int>(
                    QueryBuilder.GetCollectionContentSearchArtifactResults(scopeId, pagination, includeDrafts, userId),
                    commandType : CommandType.Text);
            }
            else
            {
                using (var command = await transaction.Connection.QueryMultipleAsync(QueryBuilder.GetCollectionContentSearchArtifactResults(scopeId, pagination, includeDrafts, userId),
                                                                                     param: null,
                                                                                     transaction: transaction,
                                                                                     commandType: CommandType.Text))
                {
                    var item1 = command.Read <int>().ToList();
                    var item2 = command.Read <int>().ToList();

                    result = new Tuple <IEnumerable <int>, IEnumerable <int> >(item1, item2);
                }
            }


            if (result.Item1 != null)
            {
                searchArtifactsResult.Total = result.Item1.FirstOrDefault();
            }

            searchArtifactsResult.ArtifactIds = result.Item2;

            return(searchArtifactsResult);
        }