private IActionResult Process(HttpContext context, HttpRequest request, Survey value, CancellationToken ct) { var id = request.Headers["ghosts-id"]; _log.Trace($"Request by {id}"); var m = WebRequestReader.GetMachine(HttpContext); if (!string.IsNullOrEmpty(id)) { m.Id = new Guid(id); } else { if (!m.IsValid()) { return(StatusCode(StatusCodes.Status401Unauthorized, "Invalid machine request")); } } value.MachineId = m.Id; if (value.Created == DateTime.MinValue) { value.Created = DateTime.UtcNow; } this._service.Enqueue(new QueueEntry { Type = QueueEntry.Types.Survey, Payload = value }); return(NoContent()); }
public async Task <IActionResult> Index([FromBody] string timeline, CancellationToken ct) { var id = Request.Headers["ghosts-id"]; _log.Trace($"Request by {id}"); var m = WebRequestReader.GetMachine(HttpContext); if (!string.IsNullOrEmpty(id)) { m.Id = new Guid(id); await _machineService.CreateAsync(m, ct); } else { if (!m.IsValid()) { return(StatusCode(StatusCodes.Status401Unauthorized, "Invalid machine request")); } } Timeline tl; try { tl = JsonConvert.DeserializeObject <Timeline>(timeline); } catch (Exception e) { Console.WriteLine(e); return(StatusCode(StatusCodes.Status400BadRequest, "Invalid timeline file")); } return(Ok(await _service.CreateAsync(m, tl, ct))); }
public async Task <IActionResult> Index(CancellationToken ct) { var id = Request.Headers["ghosts-id"]; if (string.IsNullOrEmpty(id)) { throw new Exceptions.GhostsClientFormattingException("Web Headers are not configured correctly"); } log.Trace($"Request by {id}"); var m = WebRequestReader.GetMachine(HttpContext); if (!string.IsNullOrEmpty(id)) { m.Id = new Guid(id); } else { if (!m.IsValid()) { return(StatusCode(StatusCodes.Status401Unauthorized, "Invalid machine request")); } } _queue.Enqueue( new QueueEntry { Payload = new MachineQueueEntry { Machine = m, LogDump = null, HistoryType = Machine.MachineHistoryItem.HistoryType.RequestedUpdates }, Type = QueueEntry.Types.Machine }); if (m.Id == Guid.Empty) { return(NotFound()); } //check dB for new updates to deliver var u = await _updateService.GetAsync(m.Id, ct); if (u == null) { return(NotFound()); } var update = new UpdateClientConfig { Type = u.Type, Update = u.Update }; await _updateService.DeleteAsync(u.Id, ct); return(Json(update)); }
public async Task <IActionResult> Index(CancellationToken ct) { var id = Request.Headers["ghosts-id"]; log.Trace($"Request by {id}"); var m = new Machine(); if (!string.IsNullOrEmpty(id)) { m = await this._service.GetByIdAsync(new Guid(id), ct); } if (m == null || !m.IsValid()) { m = await this._service.FindByValue(WebRequestReader.GetMachine(HttpContext), ct); } if (m == null || !m.IsValid()) { m = WebRequestReader.GetMachine(HttpContext); m.History.Add(new Machine.MachineHistoryItem { Type = Machine.MachineHistoryItem.HistoryType.Created }); await this._service.CreateAsync(m, ct); } if (!m.IsValid()) { return(StatusCode(StatusCodes.Status401Unauthorized, "Invalid machine request")); } m.History.Add(new Machine.MachineHistoryItem { Type = Machine.MachineHistoryItem.HistoryType.RequestedId }); await this._service.UpdateAsync(m, ct); //client saves this for future calls return(Json(m.Id)); }
// ReSharper disable once UnusedParameter.Local private IActionResult Process(HttpContext context, HttpRequest request, TransferLogDump value, CancellationToken ct) { var id = request.Headers["ghosts-id"]; //log.Trace($"Request by {id}"); var m = WebRequestReader.GetMachine(HttpContext); if (!string.IsNullOrEmpty(id)) { m.Id = new Guid(id); } else { if (!m.IsValid()) { return(StatusCode(StatusCodes.Status401Unauthorized, "Invalid machine request")); } } if (!string.IsNullOrEmpty(value.Log)) { log.Trace($"payload received: {value.Log}"); _service.Enqueue( new QueueEntry { Payload = new MachineQueueEntry { Machine = m, LogDump = value, HistoryType = Machine.MachineHistoryItem.HistoryType.PostedResults }, Type = QueueEntry.Types.Machine }); } return(NoContent()); }