public async Task <IActionResult> PutLikes([FromRoute] int id, [FromBody] ZoneRequest request)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != request.Id)
            {
                return(BadRequest());
            }

            var oldZone = await _dataContext.Zones.Include(p => p.Manager)
                          .Include(p => p.ZoneType)
                          .Include(p => p.Comments)
                          .Include(p => p.Locations)
                          .FirstOrDefaultAsync(c => c.Id == request.Id);

            if (oldZone == null)
            {
                return(BadRequest("La Zona No Existe."));
            }


            oldZone.Like    = request.like;
            oldZone.DisLike = request.dislike;


            _dataContext.Zones.Update(oldZone);
            await _dataContext.SaveChangesAsync();

            return(Ok(true));
        }
Пример #2
0
        public virtual Release Release(ZoneRequest request)
        {
            var release = new Release(World.Environment, request, TriggerRequest);

            ReleaseQueue.Enqueue(release);
            TriggerRelease();
            return(release);
        }
Пример #3
0
        public virtual ZoneRequest Request(double lower, double higher)
        {
            var request = new ZoneRequest(World, TriggerRelease, DisposeCallback, lower, higher);

            RequestQueue.AddLast(request);
            TriggerRequest();
            return(request);
        }
Пример #4
0
        private IRequest CreateRequest(string data)
        {
            var args = data.Split(':');

            if (args.Length < 3)
            {
                throw new PerpetuumException(ErrorCodes.TooManyOrTooFewArguments);
            }

            var commandText = args[0];

            var command = _commandFactory(commandText);

            if (command == null)
            {
                throw PerpetuumException.Create(ErrorCodes.NoSuchCommand).SetData("command", commandText);
            }

            if (!_accessLevel.HasFlag(command.AccessLevel))
            {
                throw PerpetuumException.Create(ErrorCodes.InsufficientPrivileges)
                      .SetData("command", command.Text)
                      .SetData("accessLevel", (int)_accessLevel);
            }

            var targetPlugin = args[1];

            var dictionary = GenxyConverter.Deserialize(args[2]);

            command.CheckArguments(dictionary);

            var request = new Request
            {
                Command = command,
                Session = this,
                Target  = _globalConfiguration.RelayName,
                Data    = dictionary,
            };

            if (!targetPlugin.StartsWith("zone_"))
            {
                return(request);
            }

            request.Target = targetPlugin;
            var zoneID = int.Parse(targetPlugin.Remove(0, 5));
            var zr     = new ZoneRequest(request)
            {
                Zone = _zoneManager.GetZone(zoneID)
            };

            return(zr);
        }
Пример #5
0
 protected virtual void DoRequest(ZoneRequest request)
 {
     if (!Users.Any(x => IsOverlap(x, request)))
     {
         // there is no other ZoC request overlapping
         var cranesInZoC = World.CraneAgents.Where(x =>
                                                   IsOverlap(Math.Min(x.GetGirderPosition(), x.TargetPosition), Math.Max(x.GetGirderPosition(), x.TargetPosition),
                                                             request.LowerPosition, request.HigherPosition)).ToList();
         if (cranesInZoC.Count == 0)
         {
             // there is no crane within the ZoC
             Users.Add(request);
             request.Succeed();
         }
         else
         {
             if (cranesInZoC.All(x => x.State == CraneAgentState.Waiting))
             {
                 // all cranes within the requested ZoC are waiting -> dodge them if possible
                 // to calculate this, we compute how much space is available left of the ZoC and how much is available right of the ZoC
                 var zocLeft         = Users.Where(x => x.HigherPosition <= request.LowerPosition).MaxItems(x => x.HigherPosition).FirstOrDefault();
                 var zocRight        = Users.Where(x => x.LowerPosition >= request.HigherPosition).MaxItems(x => - x.LowerPosition).FirstOrDefault();
                 var cranesLeft      = World.CraneAgents.Where(x => x.GetGirderPosition() > (zocLeft?.LowerPosition ?? 0) && x.GetGirderPosition() <= request.LowerPosition).Sum(x => x.Width);
                 var cranesRight     = World.CraneAgents.Where(x => x.GetGirderPosition() < (zocRight?.HigherPosition ?? World.Width) && x.GetGirderPosition() >= request.HigherPosition).Sum(x => x.Width);
                 var spaceLeftOfZoC  = request.LowerPosition - (zocLeft?.HigherPosition ?? 0) - cranesLeft;
                 var spaceRightOfZoC = (zocRight?.LowerPosition ?? World.Width) - request.HigherPosition - cranesRight;
                 if (IsEnoughSpaceForDodge(cranesInZoC, spaceLeftOfZoC, spaceRightOfZoC))
                 {
                     var         sumWidth = cranesInZoC.Sum(x => x.Width);
                     ICraneAgent goLeft = null, goRight = null;
                     foreach (var c in cranesInZoC.OrderBy(x => x.GetGirderPosition()))
                     {
                         if (sumWidth <= spaceRightOfZoC)
                         {
                             // we can either go left or right
                             if (c.GetGirderPosition() - request.LowerPosition > request.HigherPosition - c.GetGirderPosition())
                             {
                                 // going right is shorter from this crane onward
                                 goRight = c;
                                 break;
                             }
                         } // not enough space to accomodate all remaining cranes on the right -> this has to go left
                         sumWidth -= c.Width;
                         goLeft    = c;
                     }
                     // the goLeft and goRight crane will dodge all others to move out of the way
                     goLeft?.Dodge(request.LowerPosition - goLeft.Width / 2, 0);
                     goRight?.Dodge(request.HigherPosition + goRight.Width / 2, 0);
                 }
             }
         }
     }
 }
Пример #6
0
        public void should_correctly_prepare_dto_with_just_name()
        {
            var dto = new ZoneRequest
            {
                Name = Name
            };

            var json = dto.Prepare();

            json.ShouldContain(Name);
            json.ShouldNotContain(Group);
            json.ShouldNotContain(Template);
        }
Пример #7
0
        public void should_correctly_prepare_full_dto()
        {
            var dto = new ZoneRequest
            {
                Group    = Group,
                Name     = Name,
                Template = Template
            };

            var json = dto.Prepare();

            json.ShouldContain(Name);
            json.ShouldContain(Group);
            json.ShouldContain(Template);
        }
Пример #8
0
        public async Task <Zone> UpdateZoneAsync(int zoneId, string group = null)
        {
            var dto = new ZoneRequest
            {
                Group = group
            };

            var response = await _client.Put($"{BaseUrl}/{zoneId}", dto.Prepare());

            ErrorHandler(response.StatusCode);

            var content = await response.Content.ReadAsStringAsync();

            var responseDto = JsonConvert.DeserializeObject <ZoneResponse>(content);

            return(responseDto.Extract());
        }
 public ZoneResponse ProcessESB(ZoneRequest objRequest)
 {
     try
     {
         {
             objZoneResponse.ZoneGrid = objclsDashboard.GetESBLatencyData(objRequest.DateTime, objRequest.LatencyType, objRequest.SerID, objRequest.MetID);
             return(objZoneResponse);
         }
     }
     catch (Exception)
     {
         return(objZoneResponse);
     }
     finally
     {
         objZoneResponse = null;
         objclsDashboard = null;
     }
 }
Пример #10
0
        public async Task <Zone> CreateZoneAsync(string name, string group = null, string template = null)
        {
            var dto = new ZoneRequest
            {
                Group    = group,
                Name     = name,
                Template = template
            };

            var response = await _client.Post(BaseUrl, dto.Prepare());

            ErrorHandler(response.StatusCode);

            var content = await response.Content.ReadAsStringAsync();

            var responseDto = JsonConvert.DeserializeObject <ZoneResponse>(content);

            return(responseDto.Extract());
        }
Пример #11
0
        public List <ZoneModel> GetListZone(string StoreId, string AppKey, string AppSecret)
        {
            List <ZoneModel> model = new List <ZoneModel>();

            try
            {
                ZoneRequest paraBody = new ZoneRequest();
                paraBody.StoreId   = StoreId;
                paraBody.AppKey    = AppKey;
                paraBody.AppSecret = AppSecret;
                NSLog.Logger.Info("GetListZone_Request: ", paraBody);
                var     result      = (ResponseBaseModels)ApiResponse.Post <ResponseBaseModels>(Commons.Zone_Get, null, paraBody);
                dynamic dataDynamic = result.Data;
                NSLog.Logger.Info("GetListZone_Response: ", result);
                var lstContent = JsonConvert.SerializeObject(dataDynamic["ListZone"]);
                model = JsonConvert.DeserializeObject <List <ZoneModel> >(lstContent);
            }
            catch (Exception ex)
            {
                NSLog.Logger.Info("GetListZone_False: ", ex);
            }
            return(model);
        }
Пример #12
0
 private bool IsOverlap(ZoneRequest user, ZoneRequest newReq)
 {
     return(IsOverlap(user.LowerPosition, user.HigherPosition, newReq.LowerPosition, newReq.HigherPosition));
 }