public static GetPersonQuery Create(EntityObjectType objectType, Guid agentId) { return(new GetPersonQuery() { ObjectType = objectType, AgentId = agentId }); }
public async Task <PagedStatementsResult> Handle(PagedStatementsQuery request, CancellationToken cancellationToken) { if (!string.IsNullOrWhiteSpace(request.Cursor)) { string token = request.Cursor; string jsonString = await _distributedCache.GetStringAsync(token, cancellationToken); request = PagedStatementsQuery.FromJson(jsonString); request.Cursor = null; } var query = _context.Statements.AsNoTracking(); if (request.VerbId != null) { string verbHash = request.VerbId.ComputeHash(); query = query.Where(x => x.Verb.Hash == verbHash); } if (request.Agent != null) { var currentAgent = await _mediator.Send(GetAgentQuery.Create(request.Agent)); if (currentAgent != null) { Guid agentId = currentAgent.AgentId; EntityObjectType agentType = currentAgent.ObjectType; if (request.RelatedAgents.GetValueOrDefault()) { query = ( from sta in query join sub in _context.SubStatements on new { ObjectType = sta.ObjectType, ObjectId = sta.ObjectId } equals new { ObjectType = sub.ObjectType, ObjectId = sub.SubStatementId } let ctx = sta.Context where sta.Actor.AgentId == agentId || (sta.ObjectType == agentType && sta.ObjectId == agentId) || (sta.Context.InstructorId == agentId || sta.Context.TeamId == agentId) // SubStatement || sub.Actor.AgentId == agentId || (sub.ObjectType == agentType && sub.ObjectId == agentId) || // Object (sub.Context.InstructorId == agentId || sub.Context.TeamId == agentId) select sta ); } else { query = query.Where(x => x.ActorId == currentAgent.AgentId); } } else { return(new PagedStatementsResult()); } } if (request.ActivityId != null) { var activity = await _mediator.Send(GetActivityQuery.Create(request.ActivityId), cancellationToken); if (activity == null) { return(new PagedStatementsResult()); } if (request.RelatedActivities.GetValueOrDefault()) { query = ( from statement in query join subStatement in _context.SubStatements on new { ObjectId = statement.ObjectId, ObjectType = statement.ObjectType } equals new { ObjectId = subStatement.ObjectId, ObjectType = EntityObjectType.SubStatement } where ( statement.ObjectType == EntityObjectType.Activity && statement.ObjectId == activity.ActivityId ) || ( subStatement.ObjectType == EntityObjectType.Activity && subStatement.ObjectId == activity.ActivityId ) || ( statement.Context != null && statement.Context.ContextActivities != null && ( statement.Context.ContextActivities.Any(x => x.ActivityId == activity.ActivityId) ) ) select statement ); } else { query = query.Where(x => x.ObjectType == EntityObjectType.Activity && x.ObjectId == activity.ActivityId); } } if (request.Registration.HasValue) { Guid registration = request.Registration.Value; query = ( from statement in query where statement.Context != null && statement.Context.Registration == registration select statement ); } if (request.Ascending.GetValueOrDefault()) { query = query.OrderBy(x => x.Stored); } else { query = query.OrderByDescending(x => x.Stored); } if (request.Since.HasValue) { query = query.Where(x => x.Stored > request.Since.Value); } if (request.Until.HasValue) { query = query.Where(x => x.Stored < request.Until.Value); } int pageSize = request.Limit ?? 1000; int skipRows = request.PageIndex * pageSize; IQueryable <StatementEntity> pagedQuery = null; // Include voiding statements query = query.Select(p => p.VoidingStatementId != null ? p.VoidingStatement : p); if (!request.Attachments.GetValueOrDefault()) { pagedQuery = query.Select(p => new StatementEntity { StatementId = p.StatementId, FullStatement = p.FullStatement }); } else { pagedQuery = query.Select(p => new StatementEntity { StatementId = p.StatementId, FullStatement = p.FullStatement, Attachments = p.Attachments, }); } var result = await pagedQuery.Skip(skipRows).Take(pageSize + 1) .ToListAsync(cancellationToken); if (result == null) { return(new PagedStatementsResult()); } List <StatementEntity> statements = result.Take(pageSize).ToList(); if (result.Count > pageSize) { request.Cursor = Guid.NewGuid().ToString(); request.PageIndex += 1; if (!request.Until.HasValue) { request.Until = DateTimeOffset.UtcNow; } var options = new DistributedCacheEntryOptions() .SetSlidingExpiration(TimeSpan.FromSeconds(60 * 10)); await _distributedCache.SetStringAsync(request.Cursor, request.ToJson(), options, cancellationToken); return(new PagedStatementsResult(statements, request.Cursor)); } return(new PagedStatementsResult(statements)); }
//private Tuple<string, string> GetDBNameSchemaName(string objectIdentity) //{ // return new Tuple<string, string>(objectIdentity.Split('>')[0], objectIdentity.Split('>')[1]); //} private ObjectDTO ToObjectDTO(DatabaseObjectCategory objectCategory, int objectIdentity, string title, string name, int tableDrivedEntityID, EntityObjectType entityType = EntityObjectType.None) { ObjectDTO result = new ObjectDTO(); result.ObjectCategory = objectCategory; result.ObjectIdentity = objectIdentity; result.Title = title; result.TableDrivedEntityID = tableDrivedEntityID; result.EntityType = entityType; result.Name = name; //result.SecurityObjectID = securityObjectID; result.NeedsExplicitPermission = (objectCategory == DatabaseObjectCategory.Entity); return(result); }
private FrameworkElement GetNodeHeader(string title, DatabaseObjectCategory type, EntityObjectType entityType = EntityObjectType.None) { StackPanel pnlHeader = new StackPanel(); System.Windows.Controls.TextBlock label = new System.Windows.Controls.TextBlock(); label.Text = title; Image img = new Image(); img.Width = 15; Uri uriSource = null; if (type == DatabaseObjectCategory.Folder) { uriSource = new Uri("../Images/folder.png", UriKind.Relative); } else if (type == DatabaseObjectCategory.Database) { uriSource = new Uri("../Images/database.png", UriKind.Relative); } else if (type == DatabaseObjectCategory.Schema) { uriSource = new Uri("../Images/folder.png", UriKind.Relative); } else if (type == DatabaseObjectCategory.Entity) { if (entityType == EntityObjectType.View) { uriSource = new Uri("../Images/view.png", UriKind.Relative); } else { uriSource = new Uri("../Images/form.png", UriKind.Relative); } } else if (type == DatabaseObjectCategory.Report) { uriSource = new Uri("../Images/report.png", UriKind.Relative); } else if (type == DatabaseObjectCategory.Archive) { uriSource = new Uri("../Images/archive.png", UriKind.Relative); } else if (type == DatabaseObjectCategory.Letter) { uriSource = new Uri("../Images/mail.png", UriKind.Relative); } else { uriSource = new Uri("../Images/report.png", UriKind.Relative); } if (uriSource != null) { img.Source = new BitmapImage(uriSource); } pnlHeader.Orientation = Orientation.Horizontal; pnlHeader.Children.Add(img); pnlHeader.Children.Add(label); return(pnlHeader); }