Fix reformatting.

This commit is contained in:
2019-11-02 23:52:33 +00:00
parent f6df95b732
commit dcaf51faef
52 changed files with 6663 additions and 5874 deletions

View File

@@ -30,6 +30,7 @@
// Copyright © 2011-2019 Natalia Portillo
// ****************************************************************************/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
@@ -45,60 +46,63 @@ namespace DiscImageChef.Server.Controllers
{
public class UpdateController : Controller
{
private readonly DicServerContext _ctx;
readonly DicServerContext _ctx;
public UpdateController(DicServerContext ctx)
{
_ctx = ctx;
}
public UpdateController(DicServerContext ctx) => _ctx = ctx;
/// <summary>
/// Receives a report from DiscImageChef.Core, verifies it's in the correct format and stores it on the server
/// </summary>
/// <summary>Receives a report from DiscImageChef.Core, verifies it's in the correct format and stores it on the server</summary>
/// <returns>HTTP response</returns>
[Route("api/update")]
[HttpGet]
[Route("api/update"), HttpGet]
public ActionResult Update(long timestamp)
{
var sync = new SyncDto();
var lastSync = DateHandlers.UnixToDateTime(timestamp);
var sync = new SyncDto();
DateTime lastSync = DateHandlers.UnixToDateTime(timestamp);
sync.UsbVendors = new List<UsbVendorDto>();
foreach (var vendor in _ctx.UsbVendors.Where(v => v.ModifiedWhen > lastSync))
sync.UsbVendors.Add(new UsbVendorDto {VendorId = vendor.VendorId, Vendor = vendor.Vendor});
foreach(UsbVendor vendor in _ctx.UsbVendors.Where(v => v.ModifiedWhen > lastSync))
sync.UsbVendors.Add(new UsbVendorDto
{
VendorId = vendor.VendorId, Vendor = vendor.Vendor
});
sync.UsbProducts = new List<UsbProductDto>();
foreach (var product in _ctx.UsbProducts.Include(p => p.Vendor).Where(p => p.ModifiedWhen > lastSync))
foreach(UsbProduct product in _ctx.UsbProducts.Include(p => p.Vendor).Where(p => p.ModifiedWhen > lastSync))
sync.UsbProducts.Add(new UsbProductDto
{
Id = product.Id,
Product = product.Product,
ProductId = product.ProductId,
Id = product.Id, Product = product.Product, ProductId = product.ProductId,
VendorId = product.Vendor.VendorId
});
sync.Offsets = new List<CdOffsetDto>();
foreach (var offset in _ctx.CdOffsets.Where(o => o.ModifiedWhen > lastSync))
foreach(CompactDiscOffset offset in _ctx.CdOffsets.Where(o => o.ModifiedWhen > lastSync))
sync.Offsets.Add(new CdOffsetDto(offset, offset.Id));
sync.Devices = new List<DeviceDto>();
foreach (var device in _ctx.Devices.Where(d => d.ModifiedWhen > lastSync).ToList())
sync.Devices.Add(new
DeviceDto(
JsonConvert.DeserializeObject<DeviceReportV2>(JsonConvert.SerializeObject(device,
Formatting.None,
new JsonSerializerSettings {ReferenceLoopHandling = ReferenceLoopHandling.Ignore})),
device.Id, device.OptimalMultipleSectorsRead));
var js = JsonSerializer.Create();
var sw = new StringWriter();
foreach(Device device in _ctx.Devices.Where(d => d.ModifiedWhen > lastSync).ToList())
sync.Devices.Add(new DeviceDto(JsonConvert.
DeserializeObject<DeviceReportV2>(JsonConvert.SerializeObject(device,
Formatting.
None,
new
JsonSerializerSettings
{
ReferenceLoopHandling
= ReferenceLoopHandling.
Ignore
})),
device.Id, device.OptimalMultipleSectorsRead));
JsonSerializer js = JsonSerializer.Create();
var sw = new StringWriter();
js.Serialize(sw, sync);
return new ContentResult
{
StatusCode = (int) HttpStatusCode.OK,
Content = sw.ToString(),
ContentType = "application/json"
StatusCode = (int)HttpStatusCode.OK, Content = sw.ToString(), ContentType = "application/json"
};
}
}