Beispiel #1
1
        /// <summary>
        /// Initializes a new instance of the <see cref="GlimpseRequest" /> class.
        /// </summary>
        /// <param name="requestId">The request id.</param>
        /// <param name="requestMetadata">The request metadata.</param>
        /// <param name="tabData">The plugin data.</param>
        /// <param name="displayData">The display data</param>
        /// <param name="duration">The duration.</param>
        public GlimpseRequest(Guid requestId, IRequestMetadata requestMetadata, IDictionary<string, TabResult> tabData, IDictionary<string, TabResult> displayData, TimeSpan duration)
            : this()
        {
            RequestId = requestId;
            TabData = tabData;
            DisplayData = displayData;
            Duration = duration;

            RequestHttpMethod = requestMetadata.RequestHttpMethod;
            RequestIsAjax = requestMetadata.RequestIsAjax;
            RequestUri = requestMetadata.RequestUri;
            ResponseStatusCode = requestMetadata.ResponseStatusCode;
            ResponseContentType = requestMetadata.ResponseContentType;
            ClientId = requestMetadata.GetCookie(Constants.ClientIdCookieName) ?? requestMetadata.ClientId;
            UserAgent = requestMetadata.GetHttpHeader(Constants.UserAgentHeaderName);

            Guid parentRequestId;

#if NET35
            if (RequestIsAjax && Glimpse.Core.Backport.Net35Backport.TryParseGuid(requestMetadata.GetHttpHeader(Constants.HttpRequestHeader), out parentRequestId))
            {
                ParentRequestId = parentRequestId;
            }
#else
            if (RequestIsAjax && Guid.TryParse(requestMetadata.GetHttpHeader(Constants.HttpRequestHeader), out parentRequestId))
            {
                ParentRequestId = parentRequestId;
            }
#endif
        }
 public void GetVenue_ShouldThrowException_WhenVenueIdIsEmpty(
     [Frozen] IRequestMetadata metadata
     , [Frozen] CommandHandler handler)
 {
     // ACT
     Assert.ThrowsAsync <ArgumentNullException>(() => handler.GetVenueAsync(Guid.Empty, metadata, true));
 }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="GlimpseRequest" /> class.
        /// </summary>
        /// <param name="requestId">The request id.</param>
        /// <param name="requestMetadata">The request metadata.</param>
        /// <param name="tabData">The plugin data.</param>
        /// <param name="duration">The duration.</param>
        public GlimpseRequest(Guid requestId, IRequestMetadata requestMetadata, IDictionary <string, TabResult> tabData, IDictionary <string, TabResult> displayData, TimeSpan duration)
        {
            RequestId   = requestId;
            TabData     = tabData;
            DisplayData = displayData;
            Duration    = duration;

            DateTime            = DateTime.Now;
            RequestHttpMethod   = requestMetadata.RequestHttpMethod;
            RequestIsAjax       = requestMetadata.RequestIsAjax;
            RequestUri          = requestMetadata.RequestUri;
            ResponseStatusCode  = requestMetadata.ResponseStatusCode;
            ResponseContentType = requestMetadata.ResponseContentType;
            ClientId            = requestMetadata.GetCookie(Constants.ClientIdCookieName) ?? requestMetadata.ClientId;
            UserAgent           = requestMetadata.GetHttpHeader(Constants.UserAgentHeaderName);

            Guid parentRequestId;

#if NET35
            if (RequestIsAjax && Glimpse.Core.Backport.Net35Backport.TryParseGuid(requestMetadata.GetHttpHeader(Constants.HttpRequestHeader), out parentRequestId))
            {
                ParentRequestId = parentRequestId;
            }
#else
            if (RequestIsAjax && Guid.TryParse(requestMetadata.GetHttpHeader(Constants.HttpRequestHeader), out parentRequestId))
            {
                ParentRequestId = parentRequestId;
            }
#endif
        }
Beispiel #4
0
        public void AppendTraceMetadata(IRequestMetadata metadata)
        {
            metadata.EnsureNotNull(nameof(metadata));

            TenantId      = metadata.TenantId;
            CorrelationId = metadata.CorrelationId;
        }
        public async Task <IActionResult> ExecuteAsync(
            IRequestMetadata <UserResource> requestMetadata = null,
            CancellationToken cancellationToken             = default(CancellationToken))
        {
            var users = await Database.Users.GetAllAsync(user => true, cancellationToken : cancellationToken);

            return(await OkAsync(users, requestMetadata, cancellationToken));
        }
 public void CreateVenue_ShouldThrowException_WhenVenueNameIsNull(
     [Frozen] IRequestMetadata metadata
     , Address address
     , [Frozen] CommandHandler handler)
 {
     // ACT
     Assert.Throws <ArgumentNullException>(() => handler.CreateVenue(null, address, metadata));
 }
Beispiel #7
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="telemetry">
 /// A TelemetryService object instance.
 /// </param>
 /// <param name="requestMetadata">
 /// A RequestMetadata object instance.
 /// </param>
 public EventResourceFilterAttribute(
     ITelemetryService telemetry,
     IRequestMetadata requestMetadata
     )
 {
     _requestMetadata = requestMetadata;
     _telemetry       = telemetry;
 }
            public IRequestMetadata GetMetadata()
            {
                if (_metadata != null)
                {
                    return(_metadata);
                }

                return(_metadata = CreateMetadata());
            }
        public async Task <IHttpActionResult> ExecuteAsync(
            int userId,
            IRequestMetadata <PostResource> requestMetadata = null,
            CancellationToken cancellationToken             = default(CancellationToken))
        {
            var posts = await Database.Posts.GetByOwnerUserIdAsync(userId, cancellationToken);

            return(await OkAsync(posts, requestMetadata, cancellationToken));
        }
 public IntegrationEventException(string message, Exception innerException, IRequestMetadata metadata)
     : base(message, innerException)
 {
     if (metadata != null)
     {
         TenantId      = metadata.TenantId;
         CorrelationId = metadata.CorrelationId;
     }
 }
        public IHttpActionResult Execute(int id, IRequestMetadata<PostResource> metadata = null)
        {
            var post = _database.Posts.GetById(new[] { id }).FirstOrDefault().AsResource();

            if (post == null)
            {
                return NotFound();
            }

            return Ok(post.Populate(_database));
        }
        public async Task <IActionResult> ExecuteAsync(
            string q = null,
            int skip = 0,
            int take = 100,
            IRequestMetadata <PostResource> requestMetadata = null,
            CancellationToken cancellationToken             = default(CancellationToken))
        {
            var posts = await Database.Posts.GetAllAsync(Predicate(q), skip, take, cancellationToken);

            return(await OkAsync(posts, requestMetadata, cancellationToken));
        }
Beispiel #13
0
        public IHttpActionResult Execute(int id, IRequestMetadata <PostResource> metadata = null)
        {
            var post = _database.Posts.GetById(new[] { id }).FirstOrDefault().AsResource();

            if (post == null)
            {
                return(NotFound());
            }

            return(Ok(post.Populate(_database)));
        }
        public IHttpActionResult Execute(string q = null, int skip = 0, int take = 100, IRequestMetadata<PostResource> metadata = null)
        {
            var posts = _database.Posts.GetAll(Predicate(q), skip, take).AsResource();

            foreach (var post in posts)
            {
                post.Populate(_database);
            }

            return Ok(posts);
        }
        public Venue CreateVenue(string venueName, Address address, IRequestMetadata metadata)
        {
            venueName.EnsureNotNullDefaultOrWhitespace(nameof(venueName));
            address.EnsureNotNull(nameof(address));
            metadata.EnsureNotNull(nameof(metadata));

            var venue = new Venue(venueName, address);

            venue.AppendTraceMetadata(metadata);

            return(venue);
        }
        public void GetVenue_ShouldThrowException_WhenThrowExceptionIfVenueNotExisted(
            [Frozen] Mock <IRepository <Guid, Venue> > repository
            , [Frozen] IRequestMetadata metadata
            , Guid venueId
            , [Frozen] CommandHandler handler)
        {
            // ARRANGE
            repository.Setup(r => r.FindByIdAsync(It.IsAny <Guid>(), It.IsAny <bool>()))
            .ThrowsAsync(new NullReferenceException());

            // ACT
            Assert.ThrowsAsync <NullReferenceException>(() => handler.GetVenueAsync(venueId, metadata, true));
        }
Beispiel #17
0
        public async Task <IHttpActionResult> ExecuteAsync(
            int id,
            IRequestMetadata <UserResource> requestMetadata = null,
            CancellationToken cancellationToken             = default(CancellationToken))
        {
            var user = await Database.Users.GetByIdAsync(id, cancellationToken);

            if (user == null)
            {
                return(NotFound());
            }

            return(await OkAsync(user, requestMetadata, cancellationToken));
        }
Beispiel #18
0
        /// <summary>
        /// Publish an IntegrationEvent to external Event Bus
        /// </summary>
        /// <param name="metadata">The tracker</param>
        /// <param name="integrationEvent">The IntegrationEvent needs to be send</param>
        /// <returns></returns>
        protected async Task PublishAsync(IntegrationEvent integrationEvent, IRequestMetadata metadata = null)
        {
            if (integrationEvent == null)
            {
                throw new ArgumentNullException(nameof(integrationEvent));
            }

            if (metadata != null)
            {
                integrationEvent.AppendTraceMetadata(metadata);
            }

            await _publisher.PublishAsync(integrationEvent).ConfigureAwait(false);
        }
        public async Task <IActionResult> ExecuteAsync(
            int id,
            IRequestMetadata <PostResource> requestMetadata = null,
            CancellationToken cancellationToken             = default(CancellationToken))
        {
            var post = await Database.Posts.GetByIdAsync(id, cancellationToken);

            if (post == null)
            {
                return(NotFound());
            }

            return(await OkAsync(post, requestMetadata, cancellationToken));
        }
        public async Task <Venue> GetVenueAsync(Guid venueId, IRequestMetadata metadata, bool throwExceptionIfNotExisted = true)
        {
            venueId.EnsureNotNullOrDefault(nameof(venueId));
            metadata.EnsureNotNull(nameof(metadata));

            var venue = await _repository.FindByIdAsync(venueId, throwExceptionIfNotExisted);

            if (venue == null)
            {
                return(null);
            }

            venue.AppendTraceMetadata(metadata);
            return(venue);
        }
        public async void GetVenue_ShouldReturnNull_WhenThrowExceptionIfVenueNotExisted(
            [Frozen] Mock <IRepository <Guid, Venue> > repository
            , [Frozen] IRequestMetadata metadata
            , Guid venueId
            , [Frozen] CommandHandler handler)
        {
            // ARRANGE
            repository.Setup(r => r.FindByIdAsync(It.IsAny <Guid>(), It.IsAny <bool>()))
            .ReturnsAsync((Venue)null);

            // ACT
            var venue = await handler.GetVenueAsync(venueId, metadata, false);

            // ASSERT
            Assert.Null(venue);
        }
        public async Task <IActionResult> ExecuteAsync(
            int postId,
            IRequestMetadata <CommentResource> requestMetadata = null,
            CancellationToken cancellationToken = default(CancellationToken))
        {
            var post = await Database.Posts.GetByIdAsync(postId, cancellationToken);

            if (post == null)
            {
                return(NotFound());
            }

            var comments = await Database.Comments.GetByPostIdAsync(new[] { post.Id }, cancellationToken);

            return(await OkAsync(comments, requestMetadata, cancellationToken));
        }
Beispiel #23
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RuntimePolicyContext" /> class.
        /// </summary>
        /// <param name="requestMetadata">The request metadata.</param>
        /// <param name="logger">The logger.</param>
        /// <param name="requestContext">The request context.</param>
        /// <exception cref="System.ArgumentNullException">Throws an exception if any parameters are <c>null</c>.</exception>
        public RuntimePolicyContext(IRequestMetadata requestMetadata, ILogger logger, object requestContext)
        {
            if (requestMetadata == null)
            {
                throw new ArgumentNullException("requestMetadata");
            }

            if (logger == null)
            {
                throw new ArgumentNullException("logger");
            }

            if (requestContext == null)
            {
                throw new ArgumentNullException("requestContext");
            }

            RequestMetadata = requestMetadata;
            Logger          = logger;
            RequestContext  = requestContext;
        }
Beispiel #24
0
        public IHttpActionResult Execute(string q = null, int skip = 0, int take = 100, IRequestMetadata <PostResource> metadata = null)
        {
            var posts = _database.Posts.GetAll(Predicate(q), skip, take).AsResource();

            foreach (var post in posts)
            {
                post.Populate(_database);
            }

            return(Ok(posts));
        }
 public EntityException(string message, IRequestMetadata metadata)
     : this(message, null, metadata)
 {
 }
Beispiel #26
0
        /// <summary>
        /// Dispatch a new Command
        /// </summary>
        /// <typeparam name="TResponse">The result type of the execution of the Command</typeparam>
        /// <param name="command">The Command is going to be sent</param>
        /// <param name="metadata">The tracker</param>
        /// <returns></returns>
        protected async Task <TResponse> DispatchAsync <TResponse>(Command <TResponse> command, IRequestMetadata metadata = null)
        {
            if (command == null)
            {
                throw new ArgumentNullException(nameof(command));
            }

            if (metadata != null)
            {
                command.AppendTraceMetadata(metadata);
            }

            return(await _mediator.Send(command).ConfigureAwait(false));
        }
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="requestMetadata">
 /// Claim Reader
 /// </param>
 public LogonIdentityService(
     IRequestMetadata requestMetadata
     )
 {
     _requestMetadata = requestMetadata;
 }
 public void AppendTraceMetadata(IRequestMetadata metadata)
 {
     TenantId      = metadata.TenantId;
     CorrelationId = metadata.CorrelationId;
 }
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="requestMetadata"></param>
 /// <param name="errorHandlerService"></param>
 public CustomAuthorizationFilter(IRequestMetadata requestMetadata, IErrorHandlerService errorHandlerService)
 {
     _requestMetadata     = requestMetadata;
     _errorHandlerService = errorHandlerService;
 }
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="config"></param>
 /// <param name="requestMetadata"></param>
 /// <param name="telemetryService"></param>
 public ErrorHandlerService(IConfiguration config, IRequestMetadata requestMetadata, ITelemetryService telemetryService)
 {
     _config           = config;
     _requestMetadata  = requestMetadata;
     _telemetryService = telemetryService;
 }
 public IntegrationEventException(string message, IRequestMetadata metadata)
     : this(message, null, metadata)
 {
 }