/// <summary> /// TODO: This method needs to be moved from here as it makes calls to schema specific methods. /// </summary> /// <param name="callingUrl"></param> /// <param name="domainId"></param> /// <param name="conditions"></param> /// <param name="pageNumber"></param> /// <param name="pageSize"></param> /// <returns></returns> public SearchMapResult SearchMap(IGlymaSession glymaSession, Guid domainId, Guid rootMapUid, SearchConditions conditions, int pageNumber = 1, int pageSize = 5) { SearchMapResult result = new SearchMapResult(); using (IDbConnectionAbstraction mapDbConnection = glymaSession.ConnectionFactory.CreateMapDbConnection()) { mapDbConnection.Open(); SqlCommand findMetadata = conditions.BuildSearchQuery(mapDbConnection.Connection, rootMapUid, pageNumber, pageSize); SqlDataReader matchingMetadata = findMetadata.ExecuteReader(); matchingMetadata.Read(); int totalMetadataCount = (int)matchingMetadata[0]; matchingMetadata.NextResult(); int currentMetadataPagePosition = pageNumber * pageSize; DataTable nodesList; result.Count = totalMetadataCount; if (currentMetadataPagePosition > totalMetadataCount && pageNumber > 1) { int itemsToRemove = currentMetadataPagePosition - totalMetadataCount; if (itemsToRemove >= pageSize) { result = new SearchMapResult(); return result; } else { nodesList = new DataTable("NodesList"); nodesList.Load(matchingMetadata); for (int i = 0; i < itemsToRemove; i++) { nodesList.Rows.RemoveAt(0); } nodesList.Columns.Remove("Modified"); } } else { nodesList = new DataTable("NodesList"); nodesList.Load(matchingMetadata); nodesList.Columns.Remove("Modified"); } QueryNodes queryNodes = new QueryNodes(mapDbConnection); Dictionary<Guid, SearchedNode> nodes = queryNodes.GetNodes(nodesList); result.SearchedNodes = nodes; mapDbConnection.Close(); try { mapDbConnection.Open(); AuditLogItem logItem = new AuditLogItem(mapDbConnection.Connection); logItem.OperationName = "SearchMap"; //logItem.CallingUrl = callingUrl; logItem.DomainUid = domainId; logItem.NodeUid = null; logItem.RootMapUid = rootMapUid; logItem.MaxDepth = null; logItem.ObjectIndex = null; logItem.EdgeConditions = null; logItem.FilterConditions = null; logItem.SearchConditions = null; logItem.PageNumber = pageNumber; logItem.PageSize = pageSize; logItem.Commit(); mapDbConnection.Close(); } catch { /// Don't do anything. This is here because audit logging is a very low importance task and we don't want it potentially killing the more important tasks at hand. } return result; } }
/// <summary> /// TODO: This method needs to be moved from here as it makes calls to schema specific methods. /// </summary> /// <param name="callingUrl"></param> /// <param name="domainId"></param> /// <param name="conditions"></param> /// <param name="pageNumber"></param> /// <param name="pageSize"></param> /// <returns></returns> public SearchMapResult SearchMap(IGlymaSession glymaSession, Guid domainId, Guid rootMapUid, SearchConditions conditions, int pageNumber = 1, int pageSize = 5) { SearchMapResult result = new SearchMapResult(); using (IDbConnectionAbstraction mapDbConnection = glymaSession.ConnectionFactory.CreateMapDbConnection()) { mapDbConnection.Open(); SqlCommand findMetadata = conditions.BuildSearchQuery(mapDbConnection.Connection, rootMapUid, pageNumber, pageSize); SqlDataReader matchingMetadata = findMetadata.ExecuteReader(); matchingMetadata.Read(); int totalMetadataCount = (int)matchingMetadata[0]; matchingMetadata.NextResult(); int currentMetadataPagePosition = pageNumber * pageSize; DataTable nodesList; result.Count = totalMetadataCount; if (currentMetadataPagePosition > totalMetadataCount && pageNumber > 1) { int itemsToRemove = currentMetadataPagePosition - totalMetadataCount; if (itemsToRemove >= pageSize) { result = new SearchMapResult(); return(result); } else { nodesList = new DataTable("NodesList"); nodesList.Load(matchingMetadata); for (int i = 0; i < itemsToRemove; i++) { nodesList.Rows.RemoveAt(0); } nodesList.Columns.Remove("Modified"); } } else { nodesList = new DataTable("NodesList"); nodesList.Load(matchingMetadata); nodesList.Columns.Remove("Modified"); } QueryNodes queryNodes = new QueryNodes(mapDbConnection); Dictionary <Guid, SearchedNode> nodes = queryNodes.GetNodes(nodesList); result.SearchedNodes = nodes; mapDbConnection.Close(); try { mapDbConnection.Open(); AuditLogItem logItem = new AuditLogItem(mapDbConnection.Connection); logItem.OperationName = "SearchMap"; //logItem.CallingUrl = callingUrl; logItem.DomainUid = domainId; logItem.NodeUid = null; logItem.RootMapUid = rootMapUid; logItem.MaxDepth = null; logItem.ObjectIndex = null; logItem.EdgeConditions = null; logItem.FilterConditions = null; logItem.SearchConditions = null; logItem.PageNumber = pageNumber; logItem.PageSize = pageSize; logItem.Commit(); mapDbConnection.Close(); } catch { /// Don't do anything. This is here because audit logging is a very low importance task and we don't want it potentially killing the more important tasks at hand. } return(result); } }