public void Should_include_partitions_in_reports()
        {
            var upl    = new TestUploader();
            var config = new CoderrConfiguration();
            var ex     = new Exception("hello");
            var ctx    = new ErrorReporterContext(this, ex);

            config.Uploaders.Register(upl);
            config.AddPartition(x =>
            {
                x.AddPartition("Id", "42");
            });

            var processor = new ExceptionProcessor(config);

            processor.Process(ctx);

            upl.Report.GetCollectionProperty("CoderrData", "ErrPartition.Id").Should().Be("42");
        }
        public void Should_ignore_reports_that_have_already_been_reported_since_same_frameworks_have_multiple_injection_points_which_would_Report_the_same_exception()
        {
            var upl    = new TestUploader();
            var config = new CoderrConfiguration();
            var ex     = new Exception("hello");
            var ctx    = new ErrorReporterContext(this, ex);

            config.Uploaders.Register(upl);
            config.AddPartition(x =>
            {
                x.AddPartition("Id", "42");
            });

            var processor = new ExceptionProcessor(config);

            processor.Process(ctx);

            upl.Report.GetCollectionProperty("ErrPartitions", "Id").Should().Be("42");
        }
예제 #3
0
        public void Should_unpack_collections_that_are_attached_to_the_exception()
        {
            var upl    = new TestUploader();
            var config = new CoderrConfiguration();

            config.Uploaders.Register(upl);
            var json =
                @"{""$type"":""System.Collections.Generic.List`1[[codeRR.Client.Contracts.ContextCollectionDTO, Coderr.Client]], mscorlib"",""$values"":[{""Name"":""SqlCommand"",""Properties"":{""CommandText"":""WaitFor Delay '00:00:05'"",""CommandTimeout"":""3"",""ExecutionTime"":""00:00:03.0313327"",""OtherCommand[0]"":""select * from accounts where id=@id""}},{""Name"":""DbConnection"",""Properties"":{""ConnectionString"":""Data Source=.;Initial Catalog=OneTrueError;Integrated Security=True;Connect Timeout=30;multipleactiveresultsets=true"",""DataSource"":""."",""Database"":""OneTrueError"",""RunTime"":""00:00:03.0681702"",""State"":""Open"",""IsDisposed"":""False"",""ServerVersion"":""12.00.5207""}}]}";
            var ex  = new InvalidOperationException();
            var ctx = new ErrorReporterContext(this, ex);

            ex.Data["ErrCollections"] = json;

            var processor = new ExceptionProcessor(config);

            processor.Process(ctx);

            upl.Report.ContextCollections.Should().Contain(x => x.Name == "SqlCommand");
        }
예제 #4
0
        public IHttpActionResult GetMatchPlayers(int matchId)
        {
            try
            {
                using (var db = new HereAndThereDbContext())
                {
                    var match = db.matches.FirstOrDefault(x => x.id == matchId);
                    if (match == null)
                    {
                        return(BadRequest(string.Format("No Such match with id: {0}", matchId)));
                    }

                    return(Ok(match.players.Select(x => new { x.id, x.name }).ToList()));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ExceptionProcessor.Process(ex)));
            }
        }
예제 #5
0
 /// <summary>
 ///     Gets an ongoing Match. you can use GetMatchInfo, if you have the matchId
 /// </summary>
 /// <returns>
 ///     Ongoing Match Info example
 ///     {"id":1,"startTime":"2016-11-07T21:00:29","endTime":"2016-11-10T09:51:28.78","playerCount":3,"players":[{"name":"karri","score":0.0,"id":1},{"name":"test2","score":0.0,"id":4},{"name":"k","score":0.0,"id":5}],"boundaries":[{"name":"lowerLeft","latitude":65.0519270000,"longitude":25.4474250000},{"name":"upperRight","latitude":65.0640070000,"longitude":25.4756460000}]}
 /// </returns>
 public IHttpActionResult GetOnGoingMatch()
 {
     try
     {
         using (var db = new HereAndThereDbContext())
         {
             var match = db.matches.Where(x => (x.endTime != null) && (x.endTime.Value > DateTime.Now))
                         .OrderByDescending(x => x.startTime)
                         .FirstOrDefault();
             if (match == null)
             {
                 return(BadRequest("No Ongoing Match"));
             }
             return(GetMatchInfo((int)match.id));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ExceptionProcessor.Process(ex)));
     }
 }
예제 #6
0
        /// <summary>
        /// End a match
        /// </summary>
        /// <param name="matchId"></param>
        /// <returns></returns>
        public IHttpActionResult EndMatch(int matchId)
        {
            try
            {
                using (var db = new HereAndThereDbContext())
                {
                    var match = db.matches.FirstOrDefault(x => x.id == matchId);
                    if (match == null)
                    {
                        return(BadRequest(string.Format("No Such Match with id: {0}", matchId)));
                    }

                    var endTime = DateTime.Now;
                    match.endTime = endTime;
                    db.SaveChanges();
                    return(Ok(string.Format("Match Ended successfully @ {0}", endTime)));
                }
            }
            catch (Exception ex)
            {
                return(BadRequest(ExceptionProcessor.Process(ex)));
            }
        }
예제 #7
0
        public async Task <IActionResult> Create(NewTenantContract newTenantContract)
        {
            if (newTenantContract == null)
            {
                _logger.LogWarning(LoggingEvents.CreateItemBadData, "Empty tenant cannot be created");
                return(BadRequest());
            }

            try
            {
                _logger.LogInformation(LoggingEvents.CreateItem, "Creating new tenant with name {Name}", newTenantContract.Name);

                var newTenant = _mapper.Map <Tenant>(newTenantContract);
                newTenant.Guid = await _tenantLogic.Create(newTenant);

                return(Ok(newTenant.Guid));
            }
            catch (BasicWebAppException ex)
            {
                ExceptionProcessor.Process(LoggingEvents.CreateItemFailed, _logger, ex, newTenantContract.Name);
            }

            return(StatusCode(StatusCodes.Status500InternalServerError));
        }
예제 #8
0
 /// <summary>
 ///     Gets all  currently visible Player locations of a Match
 /// </summary>
 /// <param name="matchId"></param>
 /// <returns></returns>
 public IHttpActionResult GetAllPlayerLocations(int matchId)
 {
     try
     {
         using (var db = new HereAndThereDbContext())
         {
             var match = db.matches.FirstOrDefault(x => x.id == matchId);
             if (match == null)
             {
                 return(BadRequest(string.Format("No Such match with id: {0}", matchId)));
             }
             var movements =
                 db.locations.Where(x => (x.movement.matchId == matchId) && x.isVisible)
                 .Select(
                     x =>
                     new
             {
                 locationId = x.id,
                 x.movement.playerId,
                 playerName = x.movement.player.name,
                 x.latitude,
                 x.longitude,
                 x.isActual,
                 x.isVisible,
                 x.movement.isMoving,
                 x.timeStamp
             })
                 .ToList();
             return(Ok(movements));
         }
     }
     catch (Exception ex)
     {
         return(BadRequest(ExceptionProcessor.Process(ex)));
     }
 }
예제 #9
0
 /// <summary>
 ///     Report an exception directly.
 /// </summary>
 /// <param name="exception">Exception that you want to get reported</param>
 /// <returns>Unique identifier for this report (generated using <see cref="ReportIdGenerator" />)</returns>
 /// <exception cref="System.ArgumentNullException">exception</exception>
 /// <remarks>
 ///     <para>
 ///         A lot if context information is also included in the error report. You can configure the attached information
 ///         by
 ///         using <c>Err.Configuration.ContextProviders.Add()</c>
 ///     </para>
 ///     <para>
 ///         All library exceptions are directed to the <c>Err.ReportingFailed</c> event.
 ///         Subscribe on that event if you have trouble with reporting exceptions.
 ///     </para>
 /// </remarks>
 /// <example>
 ///     <code>
 /// public ActionResult Activate(UserViewModel model)
 /// {
 ///     if (!ModelState.IsValid)
 ///         return View(model);
 ///
 ///     try
 ///     {
 ///         var user = _repos.GetUser(model.Id);
 ///         user.Activate(model.ActivationCode);
 ///         _repos.Save(user);
 ///         return RedirectToAction("Welcome");
 ///     }
 ///     catch (Exception exception)
 ///     {
 ///         Err.Report(exception);
 ///     }
 /// }
 /// </code>
 /// </example>
 public static void Report(Exception exception)
 {
     _exceptionProcessor.Process(exception);
 }
예제 #10
0
 public void Report(Exception ex)
 {
     _processor.Process(ex);
 }
예제 #11
0
        public IHttpActionResult AddPlayerActivity(string activity)
        {
            try
            {
                using (var db = new HereAndThereDbContext())
                {
                    var activityType = new
                    {
                        playerId  = 1,
                        matchId   = 1,
                        timeStamp = new DateTime(),
                        isMoving  = true,
                        locations = new[]
                        {
                            new
                            {
                                latitude  = 0.1,
                                longitude = 0.1,
                                isActual  = true,
                                isVisible = true,
                                timeStamp = new DateTime()
                            }
                        }
                    };

                    var data = JsonConvert.DeserializeAnonymousType(activity, activityType);

                    var match = db.matches.FirstOrDefault(x => x.id == data.matchId);
                    if (match == null)
                    {
                        return(BadRequest(string.Format("No Such match with id: {0}", data.matchId)));
                    }
                    var player = db.players.FirstOrDefault(x => x.id == data.playerId);
                    if (player == null)
                    {
                        return(BadRequest(string.Format("No Such Player with id: {0}", data.matchId)));
                    }

                    var movement = new Movement
                    {
                        matchId   = data.matchId,
                        playerId  = data.playerId,
                        timeStamp = data.timeStamp,
                        isMoving  = data.isMoving
                    };
                    movement.SetAuditable(movement.timeStamp);
                    db.movements.Add(movement);

                    var locations = new List <Location>();
                    foreach (var location in data.locations)
                    {
                        var loc = new Location
                        {
                            latitude  = (decimal)location.latitude,
                            longitude = (decimal)location.longitude,
                            isActual  = location.isActual,
                            isVisible = location.isVisible,
                            timeStamp = location.timeStamp,
                            movement  = movement
                        };
                        loc.SetAuditable(loc.timeStamp);
                        locations.Add(loc);
                    }
                    db.locations.AddRange(locations);
                    db.SaveChanges();

                    var returnedLocations =
                        locations.Select(
                            x =>
                            new
                    {
                        x.id,
                        x.latitude,
                        x.longitude,
                        x.isActual,
                        x.isVisible,
                        x.timeStamp
                    }).ToList();
                    var returnData = new
                    {
                        movement.playerId,
                        movement.matchId,
                        movement.isMoving,
                        locations = returnedLocations
                    };
                    return(Ok(returnData));
                }
            }
            catch (Exception exception)
            {
                return(BadRequest(ExceptionProcessor.Process(exception)));
            }
        }