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); }
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)); }
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)); }
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)); }
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()); }
private void Setup <T>(Expression <Func <ISqlConnectionWrapper, Task <T> > > expression, T result, Dictionary <string, object> outParameters = null) { var setup = Setup(expression).ReturnsAsync(result); if (outParameters != null) { setup.Callback((string s, object p, IDbTransaction t, int?o, CommandType c) => { foreach (var kv in outParameters) { SqlConnectionWrapper.Set(p, kv.Key, kv.Value); } }); } setup.Verifiable(); }
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)); }
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); }
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)); }
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 <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); }
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); }
public void SetupQueryMultipleAsync <T1, T2, T3, T4>(string sql, Dictionary <string, object> param, Tuple <IEnumerable <T1>, IEnumerable <T2>, IEnumerable <T3>, IEnumerable <T4> > result, Dictionary <string, object> outParameters = null) { Expression <Func <object, bool> > match = p => param == null || param.All(kv => Matches(kv.Value, SqlConnectionWrapper.Get <object>(p, kv.Key))); Setup(c => c.QueryMultipleAsync <T1, T2, T3, T4>(sql, It.Is(match), It.IsAny <IDbTransaction>(), It.IsAny <int?>(), CommandType.StoredProcedure), result, outParameters); }
public void SetupExecuteScalarAsync <T>(Expression <Func <string, bool> > sqlMatcher, Dictionary <string, object> param, T result, Dictionary <string, object> outParameters = null) { Expression <Func <object, bool> > match = p => param == null || param.All(kv => Matches(kv.Value, SqlConnectionWrapper.Get <object>(p, kv.Key))); Setup(c => c.ExecuteScalarAsync <T>(It.Is(sqlMatcher), It.Is(match), It.IsAny <IDbTransaction>(), It.IsAny <int?>(), It.IsAny <CommandType?>()), result, outParameters); }
public void SetupExecuteAsync(string sql, Dictionary <string, object> param, int result, Dictionary <string, object> outParameters = null) { Expression <Func <object, bool> > match = p => param == null || param.All(kv => Matches(kv.Value, SqlConnectionWrapper.Get <object>(p, kv.Key))); Setup(c => c.ExecuteAsync(sql, It.Is(match), It.IsAny <IDbTransaction>(), It.IsAny <int?>(), CommandType.StoredProcedure), result, outParameters); }