e9042f7666
Dynamic device importing. better input parsing and 5 additional import fields.
53 lines
1.8 KiB
C#
53 lines
1.8 KiB
C#
using Disco.Data.Repository;
|
|
using Disco.Models.Repository;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Disco.Services.Devices.Importing
|
|
{
|
|
internal class DeviceImportInMemoryCache : IDeviceImportCache
|
|
{
|
|
private DiscoDataContext Database;
|
|
|
|
private Lazy<IEnumerable<Device>> devices;
|
|
private Lazy<IEnumerable<DeviceModel>> deviceModels;
|
|
private Lazy<IEnumerable<DeviceProfile>> deviceProfiles;
|
|
private Lazy<IEnumerable<DeviceBatch>> deviceBatches;
|
|
|
|
public DeviceImportInMemoryCache(DiscoDataContext Database)
|
|
{
|
|
this.Database = Database;
|
|
|
|
this.devices = new Lazy<IEnumerable<Device>>(() => Database.Devices.Include("DeviceDetails").ToList());
|
|
this.deviceModels = new Lazy<IEnumerable<DeviceModel>>(() => Database.DeviceModels.ToList());
|
|
this.deviceProfiles = new Lazy<IEnumerable<DeviceProfile>>(() => Database.DeviceProfiles.ToList());
|
|
this.deviceBatches = new Lazy<IEnumerable<DeviceBatch>>(() => Database.DeviceBatches.ToList());
|
|
}
|
|
|
|
public Device FindDevice(string DeviceSerialNumber)
|
|
{
|
|
return devices.Value.FirstOrDefault(d => d.SerialNumber.Equals(DeviceSerialNumber, StringComparison.OrdinalIgnoreCase));
|
|
}
|
|
|
|
public IEnumerable<Device> Devices
|
|
{
|
|
get { return devices.Value; }
|
|
}
|
|
|
|
public IEnumerable<DeviceModel> DeviceModels
|
|
{
|
|
get { return deviceModels.Value; }
|
|
}
|
|
|
|
public IEnumerable<DeviceProfile> DeviceProfiles
|
|
{
|
|
get { return deviceProfiles.Value; }
|
|
}
|
|
|
|
public IEnumerable<DeviceBatch> DeviceBatches
|
|
{
|
|
get { return deviceBatches.Value; }
|
|
}
|
|
}
|
|
} |