public BaseResult <List <SolarSystemKills> > Get(string id)
        {
            //TODO helper method
            id = SingleSolarSystemKillsV1Controller.CleanupSystemName(id);
            try
            {
                var startTime     = DateTime.UtcNow;
                var startDateTime = DateTime.UtcNow - ONE_HOUR;
                using (var context = new DatabaseContext())
                {
                    var clientIp = Request.GetClientIp();
                    IpBlock.ThrowIfBlocked(Request, context);

                    using (var scope = new TransactionScope(TransactionScopeOption.Required, new
                                                            TransactionOptions
                    {
                        IsolationLevel = IsolationLevel.ReadUncommitted
                    }))
                    {
                        var kills = context.ExecuteSqlQuery <SolarSystemKills>(
                            "SELECT toSolarSystemID AS SolarSystemId, s2.solarSystemName AS SolarSystemName, s2.security AS SolarSystemSecurity FROM (eveuniversedata.dbo.mapSolarSystems AS s1 JOIN eveuniversedata.dbo.mapSolarSystemJumps ON s1.solarSystemID = fromSolarSystemID) JOIN eveuniversedata.dbo.mapSolarSystems AS s2 ON toSolarSystemID = s2.solarSystemID WHERE s1.solarSystemName = @originSolarSystemName",
                            new SqlParameter("originSolarSystemName", id));

                        var originSolarSystem =
                            GetSolarSystemKillBasic(id, context);

                        kills.Add(originSolarSystem);
                        var systemIds = kills.Select(k => k.SolarSystemId).ToList();

                        var result = GetKillsForSystems(context, startDateTime, systemIds, kills);

                        AddSmartbombPoddingCounts(result, context);

                        LOGGER.Debug(string.Format("SolarSystemInfo from {1} for system {0} retrieved in {2}s", id,
                                                   clientIp,
                                                   (DateTime.UtcNow - startTime).TotalSeconds));

                        scope.Complete();

                        return(result);
                    }
                }
            }
            catch (HttpResponseException)
            {
                throw;
            }
            catch (Exception e)
            {
                LOGGER.Error(string.Format("Error getting solarsystementry for {0}", id), e);
                throw;
            }
        }
Esempio n. 2
0
        public BaseResult <List <SolarSystemKills> > Get(string id)
        {
            id = CleanupSystemName(id);
            try
            {
                var startTime     = DateTime.UtcNow;
                var startDateTime = DateTime.UtcNow - ONE_HOUR;
                using (var context = new DatabaseContext())
                {
                    var clientIp = Request.GetClientIp();

                    IpBlock.ThrowIfBlocked(Request, context);

                    using (var scope = new TransactionScope(TransactionScopeOption.Required, new
                                                            TransactionOptions
                    {
                        IsolationLevel = IsolationLevel.ReadUncommitted
                    }))
                    {
                        var kills = new List <SolarSystemKills>();

                        var originSolarSystem =
                            SolarSystemCheckV1Controller.GetSolarSystemKillBasic(id, context);

                        kills.Add(originSolarSystem);
                        var systemIds = kills.Select(k => k.SolarSystemId).ToList();

                        var result = SolarSystemCheckV1Controller.GetKillsForSystems(context, startDateTime, systemIds, kills);

                        SolarSystemCheckV1Controller.AddSmartbombPoddingCounts(result, context);

                        LOGGER.Debug(string.Format("SingleSolarSystemKills from {1} for system {0} retrieved in {2}s", id,
                                                   clientIp,
                                                   (DateTime.UtcNow - startTime).TotalSeconds));

                        scope.Complete();

                        return(result);
                    }
                }
            }

            catch (HttpResponseException)
            {
                throw;
            }
            catch (Exception e)
            {
                LOGGER.Error(string.Format("Error getting singlesolarsystemkills for {0}", id), e);
                throw;
            }
        }
Esempio n. 3
0
        //  [EnableCors(origins: "*", headers: "*", methods: "*")]
        public async Task <Object> Get(int id)
        {
            HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
            var clientIp = Request.GetClientIp();

            var start = DateTime.UtcNow;

            try
            {
                using (var context = new DatabaseContext())
                {
                    IpBlock.ThrowIfBlocked(Request, context);

                    context.ExecuteSqlCommand("SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;");

                    var result = await UpdateEntryFor(context, id);

                    LOGGER.Info(string.Format("{0}: request from {1} done in {2}s", clientIp, id, (DateTime.UtcNow - start).TotalSeconds));
                    return(new Result(result));
                }
            }
            catch (HttpResponseException)
            {
                throw;
            }
            catch (AggregateException e)
            {
                var innerException = e.Flatten();
                LOGGER.Error(string.Format("{0}: Error getting DataEntry for {1}", clientIp, id), innerException);
                return(new { status = "error", message = innerException.Message, stacktrace = innerException.StackTrace });
            }
            catch (Exception e)
            {
                LOGGER.Error(string.Format("{0}: Error getting DataEntry for {1}", clientIp, id), e);
                return(new { status = "error", message = e.Message, stacktrace = e.StackTrace });
            }
        }