Example #1
0
        /// <summary>
        /// When the method completes, the queue message is deleted. If the method fails before completing, the queue message
        /// is not deleted; after a 10-minute lease expires, the message is released to be picked up again and processed. This
        /// sequence won't be repeated indefinitely if a message always causes an exception. After 5 unsuccessful attempts to
        /// process a message, the message is moved to a queue named {queuename}-poison. The maximum number of attempts is
        /// configurable.
        ///
        /// https://azure.microsoft.com/en-us/documentation/articles/websites-dotnet-webjobs-sdk-get-started/#configure-storage
        /// </summary>
        /// <param name="auditInfo"></param>
        /// <param name="logger"></param>
        public static void AddRetrievalAuditLogRecord([QueueTrigger("%queueName%")] AuditDataModel auditInfo, TextWriter logger)
        {
            using (var io = new Wutnu.Data.WutNuContext())
            {
                try
                {
                    var ipInfo = IpLookup.Get(auditInfo.HostIp);
                    io.usp_AddHistory(
                        auditInfo.ShortUrl,
                        auditInfo.CallDate,
                        auditInfo.UserId,
                        auditInfo.HostIp,
                        ipInfo.Latitude,
                        ipInfo.Longitude,
                        ipInfo.City,
                        ipInfo.Region,
                        ipInfo.Country,
                        ipInfo.Continent,
                        ipInfo.Isp);
                    io.SaveChanges();
                }
                catch (Exception ex)
                {
                    Logging.WriteDebugInfoToErrorLog("Error dequeing", ex, io);
                    var x = ex.GetBaseException();
                    //logger.WriteLine("Error dequeuing: {0}, {1}", x.Message, x.StackTrace);

                    throw ex;
                }
            }
        }
        /// <summary>
        /// Asynchronously handles the command request.
        /// </summary>
        /// <param name="request">The command request.</param>
        /// <param name="cancellationToken">The cancellation token.</param>
        /// <returns>A task that represents the asynchronous operation.
        /// The task result contains the result of the command request.</returns>
        public async Task <TResponse> Handle(TRequest request, CancellationToken cancellationToken)
        {
            try
            {
                cancellationToken.ThrowIfCancellationRequested();

                var response = await ProtectedHandleAsync(request, cancellationToken);

                if (SubEventType != SubEventType.None)
                {
                    var principal = PrincipalProvider.GetPrincipal();
                    var auditData = new AuditDataModel()
                    {
                        Entity  = response,
                        Command = request
                    };
                    await Audit.AddDefaultEventAsync(principal, auditData, SubEventType);
                }

                return(response);
            }
            catch (Exception)
            {
                Context.RollBackTransaction();

                throw;
            }
        }
Example #3
0
        private ActionResult LogAndRedir(WutLinkPoco res, int?userId = null)
        {
            var cli   = WutQueue.GetQueueClient();
            var queue = WutQueue.GetQueue(cli, Settings.AuditQueueName);
            var msg   = new AuditDataModel
            {
                UserId   = userId,
                CallDate = DateTime.UtcNow,
                HostIp   = Request.UserHostAddress,
                ShortUrl = res.ShortUrl
            };

            var message = JsonConvert.SerializeObject(msg);

            WutQueue.AddMessage(queue, message);

            return(Redirect(res.RealUrl));
        }
        public ServiceRequest
            (AuditDataModel dataModel
            , Guid requestId
            , Guid messageId
            , string messageSource
            , string messageType
            , string message
            , DateTime receivedAt)
        {
            if (dataModel == null)
            {
                throw new ArgumentNullException(nameof(dataModel));
            }
            if (requestId == Guid.Empty)
            {
                throw new ArgumentException(nameof(requestId));
            }
            if (messageId == Guid.Empty)
            {
                throw new ArgumentException(nameof(messageId));
            }
            if (string.IsNullOrWhiteSpace(messageType))
            {
                throw new ArgumentException(nameof(messageType));
            }
            if (string.IsNullOrWhiteSpace(message))
            {
                throw new ArgumentException(nameof(message));
            }

            this.DataModel     = dataModel;
            this.RequestId     = requestId;
            this.MessageId     = messageId;
            this.MessageSource = messageSource;
            this.MessageType   = messageType;
            this.Message       = message;
            this.ReceivedAt    = receivedAt;
        }