private async Task GetOpenArtifactPermissions(
            Dictionary <int, RolePermissions> itemIdsPermissions, IEnumerable <ProjectsArtifactsItem> projectIdsArtifactIdsItemIds,
            int sessionUserId, IEnumerable <int> projectArtifactIds, int revisionId = int.MaxValue,
            bool addDrafts = true, IDbTransaction transaction = null)
        {
            var parameters = new DynamicParameters();

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

            IEnumerable <OpenArtifactPermission> openArtifactPermissions;

            if (transaction == null)
            {
                openArtifactPermissions = await _connectionWrapper.QueryAsync <OpenArtifactPermission>(
                    "GetOpenArtifactPermissions", parameters, commandType : CommandType.StoredProcedure);
            }
            else
            {
                openArtifactPermissions = await transaction.Connection.QueryAsync <OpenArtifactPermission>(
                    "GetOpenArtifactPermissions", parameters, transaction, commandType : CommandType.StoredProcedure);
            }

            foreach (var openArtifactPermission in openArtifactPermissions)
            {
                foreach (var projectIdArtifactIdItemId in projectIdsArtifactIdsItemIds)
                {
                    if (projectIdArtifactIdItemId.HolderId == openArtifactPermission.HolderId && !itemIdsPermissions.Keys.Contains(projectIdArtifactIdItemId.VersionArtifactId))
                    {
                        itemIdsPermissions.Add(projectIdArtifactIdItemId.VersionArtifactId, (RolePermissions)openArtifactPermission.Permissions);
                    }
                }
            }
        }
Beispiel #2
0
        public async Task <IEnumerable <ProjectNameIdPair> > GetProjectNameByIdsAsync(IEnumerable <int> projectIds)
        {
            var param = new DynamicParameters();

            param.Add("@projectIds", SqlConnectionWrapper.ToDataTable(projectIds, "Int32Collection", "Int32Value"));

            return(await ConnectionWrapper.QueryAsync <ProjectNameIdPair>("GetProjectNameByIds", param, commandType: CommandType.StoredProcedure));
        }
Beispiel #3
0
        public async Task <IEnumerable <SqlUser> > GetExistingUsersByIdsAsync(IEnumerable <int> userIds)
        {
            var prm = new DynamicParameters();

            prm.Add("@userIds", SqlConnectionWrapper.ToDataTable(userIds));

            return(await _connectionWrapper.QueryAsync <SqlUser>("GetExistingUsersByids", prm, commandType : CommandType.StoredProcedure));
        }
Beispiel #4
0
        public async Task <IEnumerable <AuthorHistory> > GetAuthorHistories(IEnumerable <int> artifactIds)
        {
            var param = new DynamicParameters();

            param.Add("@artifactIds", SqlConnectionWrapper.ToDataTable(artifactIds));
            param.Add("@revisionId", int.MaxValue);

            return((await ConnectionWrapper.QueryAsync <SqlAuthorHistory>("GetOpenArtifactAuthorHistories", param, commandType: CommandType.StoredProcedure)).Select(a => (AuthorHistory)a));
        }
Beispiel #5
0
        public Task <IEnumerable <int> > FindNonExistentUsersAsync(IEnumerable <int> userIds)
        {
            var parameters   = new DynamicParameters();
            var userIdsTable = SqlConnectionWrapper.ToDataTable(userIds);

            parameters.Add("@userIds", userIdsTable);

            return(_connectionWrapper.QueryAsync <int>("FindNonExistentUsers", parameters, commandType: CommandType.StoredProcedure));
        }
Beispiel #6
0
        public Task <IEnumerable <UserInfo> > GetUserInfosFromGroupsAsync(IEnumerable <int> groupIds)
        {
            var parameters    = new DynamicParameters();
            var groupIdsTable = SqlConnectionWrapper.ToDataTable(groupIds);

            parameters.Add("@groupIds", groupIdsTable);

            return(_connectionWrapper.QueryAsync <UserInfo>("GetUserInfosFromGroups", parameters, commandType: CommandType.StoredProcedure));
        }
Beispiel #7
0
        public async Task <IEnumerable <ItemRawDataCreatedDate> > GetItemsRawDataCreatedDate(int userId, IEnumerable <int> itemIds, bool addDrafts = true, int revisionId = int.MaxValue)
        {
            var parameters = new DynamicParameters();

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

            return(await _connectionWrapper.QueryAsync <ItemRawDataCreatedDate>("GetItemsRawDataCreatedDate", parameters, commandType: CommandType.StoredProcedure));
        }
Beispiel #8
0
        private void MockGetOpenArtifactPermissions(IEnumerable <OpenArtifactPermission> mockOpenArtifactPermissionsResult, SqlConnectionWrapperMock cxn, IEnumerable <int> projectArtifactIds, int revisionId = int.MaxValue, bool addDrafts = true)
        {
            var artifactIds = SqlConnectionWrapper.ToDataTable(projectArtifactIds, "Int32Collection", "Int32Value");

            cxn.SetupQueryAsync("GetOpenArtifactPermissions",
                                new Dictionary <string, object>
            {
                { "userId", 0 },
                { "artifactIds", artifactIds }
            }, mockOpenArtifactPermissionsResult);
        }
Beispiel #9
0
        public async Task <IEnumerable <SqlGroup> > GetExistingGroupsByIds(IEnumerable <int> groupIds, bool instanceOnly, IDbTransaction transaction = null)
        {
            var prm = new DynamicParameters();

            prm.Add("@groupIds", SqlConnectionWrapper.ToDataTable(groupIds));
            prm.Add("@instanceOnly", instanceOnly);

            if (transaction != null)
            {
                return(await transaction.Connection.QueryAsync <SqlGroup>("GetExistingGroupsByIds", prm, transaction, commandType : CommandType.StoredProcedure));
            }
            return(await _connectionWrapper.QueryAsync <SqlGroup>("GetExistingGroupsByIds", prm, commandType : CommandType.StoredProcedure));
        }
Beispiel #10
0
        public async Task <IEnumerable <UserInfo> > GetUserInfos(IEnumerable <int> userIds, IDbTransaction transaction = null)
        {
            var userInfosPrm = new DynamicParameters();
            var userIdsTable = SqlConnectionWrapper.ToDataTable(userIds, "Int32Collection", "Int32Value");

            userInfosPrm.Add("@userIds", userIdsTable);

            if (transaction != null)
            {
                return(await transaction.Connection.QueryAsync <UserInfo>("GetUserInfos", userInfosPrm, transaction, commandType : CommandType.StoredProcedure));
            }
            return(await _connectionWrapper.QueryAsync <UserInfo>("GetUserInfos", userInfosPrm, commandType : CommandType.StoredProcedure));
        }
Beispiel #11
0
        public async Task <IReadOnlyList <ArtifactPropertyInfo> > GetArtifactsWithPropertyValuesAsync(
            int userId, IEnumerable <int> artifactIds, IEnumerable <int> propertyTypePredefineds, IEnumerable <int> propertyTypeIds)
        {
            var parameters = new DynamicParameters();

            parameters.Add("@UserId", userId, DbType.Int32);
            parameters.Add("@AddDrafts", true, DbType.Boolean);
            parameters.Add("@ArtifactIds", SqlConnectionWrapper.ToDataTable(artifactIds));
            parameters.Add("@PropertyTypePredefineds", SqlConnectionWrapper.ToDataTable(propertyTypePredefineds));
            parameters.Add("@PropertyTypeIds", SqlConnectionWrapper.ToDataTable(propertyTypeIds));

            var result = await ConnectionWrapper.QueryAsync <ArtifactPropertyInfo>(
                "GetPropertyValuesForArtifacts", parameters, commandType : CommandType.StoredProcedure);

            return(result.ToList());
        }
Beispiel #12
0
        public async Task <IEnumerable <ProcessInfoDto> > GetProcessInformationAsync(IEnumerable <int> artifactIds, int userId)
        {
            if (artifactIds == null)
            {
                throw new ArgumentOutOfRangeException(nameof(artifactIds));
            }

            var artifactsPermissions = await ArtifactPermissionsRepository.GetArtifactPermissions(artifactIds, userId);

            artifactIds = artifactsPermissions.Where(p => p.Value.HasFlag(RolePermissions.Read)).Select(p => p.Key);

            var param = new DynamicParameters();

            param.Add("@artifactIds", SqlConnectionWrapper.ToDataTable(artifactIds));
            var artifacts = await ConnectionWrapper.QueryAsync <ProcessInfo>("GetProcessInformation", param, commandType : CommandType.StoredProcedure);

            return(ProcessInfoMapper.Map(artifacts));
        }
Beispiel #13
0
        private void MockQueryMultipleAsync(
            IEnumerable <int> itemIds,
            SqlConnectionWrapperMock cxn,
            IEnumerable <ProjectsArtifactsItem> mockProjectsArtifactsItemsResult,
            IEnumerable <VersionProjectInfo> mockVersionProjectInfoResult,
            int revisionId = int.MaxValue,
            bool addDrafts = true)
        {
            var tvp = SqlConnectionWrapper.ToDataTable(itemIds, "Int32Collection", "Int32Value");

            var result = Tuple.Create(mockProjectsArtifactsItemsResult, mockVersionProjectInfoResult);

            cxn.SetupQueryMultipleAsync("GetArtifactsProjects",
                                        new Dictionary <string, object>
            {
                { "userId", 0 },
                { "itemIds", tvp }
            }, result);
        }
        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));
            }
        }
Beispiel #15
0
        public async Task <IEnumerable <ItemDetails> > GetItemsDetails(int userId, IEnumerable <int> itemIds, bool addDrafts = true, int revisionId = int.MaxValue, IDbTransaction transaction = null)
        {
            if (itemIds.IsEmpty())
            {
                return(Enumerable.Empty <ItemDetails>());
            }

            var parameters = new DynamicParameters();

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

            if (transaction == null)
            {
                return(await _connectionWrapper.QueryAsync <ItemDetails>("GetItemsDetails", parameters, commandType : CommandType.StoredProcedure));
            }

            return(await transaction.Connection.QueryAsync <ItemDetails>("GetItemsDetails", parameters, transaction, commandType : CommandType.StoredProcedure));
        }
Beispiel #16
0
        public async Task <IEnumerable <PropertyType> > GetStandardProperties(ISet <int> standardArtifactTypeIds)
        {
            if (standardArtifactTypeIds == null)
            {
                throw new ArgumentOutOfRangeException(nameof(standardArtifactTypeIds));
            }

            var prm = new DynamicParameters();

            // When the count of standardArtifactTypeIds is zero, you will receive all standard properties in system.
            prm.Add("@standardArtifactTypeIds", SqlConnectionWrapper.ToDataTable(standardArtifactTypeIds, "Int32Collection", "Int32Value"));

            var propertyTypeVersions = await ConnectionWrapper.QueryAsync <SqlProjectMetaRepository.PropertyTypeVersion>("GetStandardProperties", prm, commandType : CommandType.StoredProcedure);

            var propertyTypes = new List <PropertyType>();

            foreach (var pv in propertyTypeVersions)
            {
                propertyTypes.Add(pv.ConvertToPropertyType());
            }

            return(propertyTypes);
        }
Beispiel #17
0
        public async Task <IDictionary <int, IEnumerable <Artifact> > > GetArtifactsNavigationPathsAsync(
            int userId,
            IEnumerable <int> artifactIds,
            bool includeArtifactItself = true,
            int?revisionId             = null,
            bool addDraft = true)
        {
            if (artifactIds == null)
            {
                throw new ArgumentOutOfRangeException(nameof(artifactIds));
            }

            var param = new DynamicParameters();

            param.Add("@userId", userId);
            param.Add("@artifactIds", SqlConnectionWrapper.ToDataTable(artifactIds));
            param.Add("@revisionId", revisionId ?? int.MaxValue);
            param.Add("@addDrafts", addDraft);

            var itemPaths = (await ConnectionWrapper.QueryAsync <ArtifactsNavigationPath>("GetArtifactsNavigationPaths", param, commandType: CommandType.StoredProcedure)).ToList();

            var artifactNavigationPaths = new Dictionary <int, IDictionary <int, Artifact> >();

            foreach (var artifactsNavigationPath in itemPaths)
            {
                IDictionary <int, Artifact> pathArray;
                if (!artifactNavigationPaths.TryGetValue(artifactsNavigationPath.ArtifactId, out pathArray))
                {
                    var addedRecord = AddNavigationPathRecord(
                        artifactsNavigationPath.ArtifactId,
                        artifactNavigationPaths);

                    if (artifactsNavigationPath.ParentId.HasValue)
                    {
                        AddArtifactShortInfo(
                            artifactsNavigationPath.ParentId.Value,
                            null,
                            null,
                            artifactsNavigationPath.Level + 1,
                            addedRecord);
                    }

                    if (includeArtifactItself || artifactsNavigationPath.Level > 0)
                    {
                        AddArtifactShortInfo(
                            artifactsNavigationPath.ArtifactId,
                            artifactsNavigationPath.Name,
                            artifactsNavigationPath.PrimitiveItemTypePredefined,
                            artifactsNavigationPath.Level,
                            addedRecord);
                    }
                }
                else
                {
                    Artifact artifactShortInfoForCurrentLevel;
                    if (pathArray.TryGetValue(artifactsNavigationPath.Level, out artifactShortInfoForCurrentLevel))
                    {
                        artifactShortInfoForCurrentLevel.Name           = artifactsNavigationPath.Name;
                        artifactShortInfoForCurrentLevel.PredefinedType = artifactsNavigationPath.PrimitiveItemTypePredefined;
                    }
                    else
                    {
                        if (includeArtifactItself || artifactsNavigationPath.Level > 0)
                        {
                            int id = -1;
                            if (artifactsNavigationPath.Level == 0)
                            {
                                id = artifactsNavigationPath.ArtifactId;
                            }
                            AddArtifactShortInfo(id, artifactsNavigationPath.Name, artifactsNavigationPath.PrimitiveItemTypePredefined,
                                                 artifactsNavigationPath.Level, pathArray);
                        }
                    }

                    if (artifactsNavigationPath.ParentId.HasValue)
                    {
                        Artifact artifactShortInfoForNextLevel;
                        if (pathArray.TryGetValue(artifactsNavigationPath.Level + 1, out artifactShortInfoForNextLevel))
                        {
                            artifactShortInfoForNextLevel.Id = artifactsNavigationPath.ParentId.Value;
                        }
                        else
                        {
                            AddArtifactShortInfo(
                                artifactsNavigationPath.ParentId.Value,
                                null,
                                null,
                                artifactsNavigationPath.Level + 1,
                                pathArray);
                        }
                    }
                }
            }

            var result = new Dictionary <int, IEnumerable <Artifact> >(artifactNavigationPaths.Count);

            foreach (var entry in artifactNavigationPaths)
            {
                result.Add(entry.Key, entry.Value.OrderByDescending(i => i.Key).Select(j => j.Value));
            }

            return(result);
        }