remove device custom details
this plugin functionality has never been used
This commit is contained in:
@@ -58,11 +58,11 @@ namespace Disco.Services.Devices.Exporting
|
||||
if (Options.DetailBatteries)
|
||||
r.DeviceDetailBatteries = r.DeviceDetails.Batteries();
|
||||
|
||||
var detailsService = new DetailsProviderService(Database);
|
||||
if (Options.DetailCustom)
|
||||
r.DeviceDetailCustom = detailsService.GetDetails(r.Device).Details;
|
||||
if (Options.AssignedUserDetailCustom && r.AssignedUser != null)
|
||||
{
|
||||
var detailsService = new DetailsProviderService(Database);
|
||||
r.AssignedUserCustomDetails = detailsService.GetDetails(r.AssignedUser).Details;
|
||||
}
|
||||
});
|
||||
|
||||
TaskStatus.UpdateStatus(40, "Building metadata and database query");
|
||||
@@ -259,14 +259,11 @@ namespace Disco.Services.Devices.Exporting
|
||||
var certificateMaxCount = Math.Max(1, records.Max(r => r.DeviceCertificates?.Count() ?? 0));
|
||||
var batteriesMaxCount = Math.Max(1, records.Max(r => r.DeviceDetailBatteries?.Count ?? 0));
|
||||
|
||||
IEnumerable<string> deviceDetailCustomKeys = null;
|
||||
IEnumerable<string> assignedUserDetailCustomKeys = null;
|
||||
if (options.DetailCustom)
|
||||
deviceDetailCustomKeys = records.Where(r => r.DeviceDetailCustom != null).SelectMany(r => r.DeviceDetailCustom.Keys).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
|
||||
if (options.AssignedUserDetailCustom)
|
||||
assignedUserDetailCustomKeys = records.Where(r => r.AssignedUserCustomDetails != null).SelectMany(r => r.AssignedUserCustomDetails.Keys).Distinct(StringComparer.OrdinalIgnoreCase).ToList();
|
||||
|
||||
var allAssessors = BuildRecordAccessors(processorMaxCount, memoryMaxCount, diskDriveMaxCount, lanAdapterMaxCount, wlanAdapterMaxCount, certificateMaxCount, batteriesMaxCount, deviceDetailCustomKeys, assignedUserDetailCustomKeys);
|
||||
var allAssessors = BuildRecordAccessors(processorMaxCount, memoryMaxCount, diskDriveMaxCount, lanAdapterMaxCount, wlanAdapterMaxCount, certificateMaxCount, batteriesMaxCount, assignedUserDetailCustomKeys);
|
||||
|
||||
return typeof(DeviceExportOptions).GetProperties()
|
||||
.Where(p => p.PropertyType == typeof(bool))
|
||||
@@ -288,7 +285,7 @@ namespace Disco.Services.Devices.Exporting
|
||||
}).ToList();
|
||||
}
|
||||
|
||||
private static Dictionary<string, List<DeviceExportFieldMetadata>> BuildRecordAccessors(int processorMaxCount, int memoryMaxCount, int diskDriveMaxCount, int lanAdapterMaxCount, int wlanAdapterMaxCount, int certificateMaxCount, int batteriesMaxCount, IEnumerable<string> deviceDetailCustomKeys, IEnumerable<string> assignedUserDetailCustomKeys)
|
||||
private static Dictionary<string, List<DeviceExportFieldMetadata>> BuildRecordAccessors(int processorMaxCount, int memoryMaxCount, int diskDriveMaxCount, int lanAdapterMaxCount, int wlanAdapterMaxCount, int certificateMaxCount, int batteriesMaxCount, IEnumerable<string> assignedUserDetailCustomKeys)
|
||||
{
|
||||
const string DateFormat = "yyyy-MM-dd";
|
||||
const string DateTimeFormat = DateFormat + " HH:mm:ss";
|
||||
@@ -535,16 +532,6 @@ namespace Disco.Services.Devices.Exporting
|
||||
}
|
||||
metadata.Add(nameof(DeviceExportOptions.DetailBatteries), batteriesFields);
|
||||
metadata.Add(nameof(DeviceExportOptions.DetailKeyboard), new List<DeviceExportFieldMetadata>() { new DeviceExportFieldMetadata(nameof(DeviceExportOptions.DetailKeyboard), typeof(string), r => r.DeviceDetails.Where(dd => dd.Key == DeviceDetail.HardwareKeyKeyboard).Select(dd => dd.Value).FirstOrDefault(), csvStringEncoded) });
|
||||
if (deviceDetailCustomKeys != null)
|
||||
{
|
||||
var deviceDetailCustomFields = new List<DeviceExportFieldMetadata>();
|
||||
foreach (var detailKey in deviceDetailCustomKeys.OrderBy(k => k, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
var key = detailKey;
|
||||
deviceDetailCustomFields.Add(new DeviceExportFieldMetadata(detailKey, detailKey, typeof(string), r => r.DeviceDetailCustom != null && r.DeviceDetailCustom.TryGetValue(key, out var value) ? value : null, csvStringEncoded));
|
||||
}
|
||||
metadata.Add(nameof(DeviceExportOptions.DetailCustom), deviceDetailCustomFields);
|
||||
}
|
||||
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@@ -209,16 +209,13 @@ namespace Disco.Services.Expressions
|
||||
if (target is User targetUser)
|
||||
{
|
||||
detailsVariables.Add("UserDetails", new LazyDictionary(() => detailsService.GetDetails(targetUser).Details));
|
||||
detailsVariables.Add("AssignedDeviceDetails", targetUser.CurrentDeviceUserAssignments().Select(a => new { a.Device, Details = new LazyDictionary(() => detailsService.GetDetails(targetUser).Details) }).ToDictionary(d => d.Device.SerialNumber, d => d.Details, StringComparer.OrdinalIgnoreCase));
|
||||
}
|
||||
else if (target is Job targetJob)
|
||||
{
|
||||
detailsVariables.Add("UserDetails", targetJob.User == null ? (IDictionary<string, string>)new Dictionary<string, string>() : new LazyDictionary(() => detailsService.GetDetails(targetJob.User).Details));
|
||||
detailsVariables.Add("DeviceDetails", targetJob.Device == null ? (IDictionary<string, string>)new Dictionary<string, string>() : new LazyDictionary(() => detailsService.GetDetails(targetJob.Device).Details));
|
||||
}
|
||||
else if (target is Device targetDevice)
|
||||
{
|
||||
detailsVariables.Add("DeviceDetails", new LazyDictionary(() => detailsService.GetDetails(targetDevice).Details));
|
||||
detailsVariables.Add("UserDetails", targetDevice.AssignedUser == null ? (IDictionary<string, string>)new Dictionary<string, string>() : new LazyDictionary(() => detailsService.GetDetails(targetDevice.AssignedUser).Details));
|
||||
}
|
||||
}
|
||||
@@ -285,16 +282,6 @@ namespace Disco.Services.Expressions
|
||||
"#UserDetails",
|
||||
typeof(Dictionary<string, string>).AssemblyQualifiedName
|
||||
},
|
||||
|
||||
{
|
||||
"#DeviceDetails",
|
||||
typeof(Dictionary<string, string>).AssemblyQualifiedName
|
||||
},
|
||||
|
||||
{
|
||||
"#AssignedDeviceDetails",
|
||||
typeof(Dictionary<string, Dictionary<string, string>>).AssemblyQualifiedName
|
||||
},
|
||||
};
|
||||
}
|
||||
public static Dictionary<string, string> ExtensionLibraryTypes()
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
using Disco.Data.Repository;
|
||||
using Disco.Models.Services.Plugins.Details;
|
||||
using Disco.Models.UI.Device;
|
||||
using Disco.Models.UI.Job;
|
||||
using Disco.Models.UI.User;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Disco.Services.Plugins.Features.DetailsProvider
|
||||
{
|
||||
@@ -16,27 +14,13 @@ namespace Disco.Services.Plugins.Features.DetailsProvider
|
||||
|
||||
model.UserDetails = service.GetDetails(model.User);
|
||||
model.HasUserPhoto = service.HasUserPhoto(model.User);
|
||||
|
||||
var currentAssignments = model.User.CurrentDeviceUserAssignments();
|
||||
if (currentAssignments.Count > 0)
|
||||
{
|
||||
model.AssignedDevicesDetails = new Dictionary<string, DetailsResult>(currentAssignments.Count);
|
||||
|
||||
foreach (var device in currentAssignments)
|
||||
{
|
||||
model.AssignedDevicesDetails[device.DeviceSerialNumber] = service.GetDetails(device.Device);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void PopulateDetails(this DeviceShowModel model, DiscoDataContext database)
|
||||
{
|
||||
var service = new DetailsProviderService(database);
|
||||
|
||||
model.DeviceDetails = service.GetDetails(model.Device);
|
||||
|
||||
if (model.Device.AssignedUser != null)
|
||||
{
|
||||
var service = new DetailsProviderService(database);
|
||||
model.AssignedUserDetails = service.GetDetails(model.Device.AssignedUser);
|
||||
model.HasAssignedUserPhoto = service.HasUserPhoto(model.Device.AssignedUser);
|
||||
}
|
||||
@@ -44,13 +28,9 @@ namespace Disco.Services.Plugins.Features.DetailsProvider
|
||||
|
||||
public static void PopulateDetails(this JobShowModel model, DiscoDataContext database)
|
||||
{
|
||||
var service = new DetailsProviderService(database);
|
||||
|
||||
if (model.Job.Device != null)
|
||||
model.DeviceDetails = service.GetDetails(model.Job.Device);
|
||||
|
||||
if (model.Job.User != null)
|
||||
{
|
||||
var service = new DetailsProviderService(database);
|
||||
model.UserDetails = service.GetDetails(model.Job.User);
|
||||
model.HasUserPhoto = service.HasUserPhoto(model.Job.User);
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Disco.Services.Plugins.Features.DetailsProvider
|
||||
public abstract class DetailsProviderFeature : PluginFeature
|
||||
{
|
||||
public abstract DetailsResult GetDetails(DiscoDataContext database, User user, DateTime? cacheTimestamp);
|
||||
[Obsolete("Never used")]
|
||||
public abstract DetailsResult GetDetails(DiscoDataContext database, Device device, DateTime? cacheTimestamp);
|
||||
public abstract byte[] GetUserPhoto(DiscoDataContext database, User user, DateTime? cacheTimestamp);
|
||||
}
|
||||
|
||||
@@ -158,78 +158,5 @@ namespace Disco.Services.Plugins.Features.DetailsProvider
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public DetailsResult GetDetails(Device device)
|
||||
{
|
||||
var result = new DetailsResult();
|
||||
var saveChangesRequired = false;
|
||||
|
||||
if (!UserService.CurrentAuthorization.HasAll(Claims.Device.Show, Claims.Device.ShowDetails))
|
||||
return result;
|
||||
|
||||
var features = Plugins.GetPluginFeatures(typeof(DetailsProviderFeature));
|
||||
|
||||
if (features.Count == 0)
|
||||
return result;
|
||||
|
||||
var cache = device.DeviceDetails?.Where(d => d.Scope == DetailsScope).ToDictionary(d => d.Key, d => new { DbDetails = d, Details = JsonConvert.DeserializeObject<DetailsResult>(d.Value) }, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
foreach (var feature in features)
|
||||
{
|
||||
var featureResult = default(DetailsResult);
|
||||
if (!cache.TryGetValue(feature.Id, out var cacheResult) || cacheResult.Details.ExpiresOn < DateTime.Now || cacheResult.Details.GatheredOn < database.DiscoConfiguration.PluginDetailsCacheExpiration)
|
||||
{
|
||||
var timestamp = cacheResult?.Details.GatheredOn;
|
||||
if (timestamp.HasValue && timestamp.Value < database.DiscoConfiguration.PluginDetailsCacheExpiration)
|
||||
timestamp = null;
|
||||
|
||||
try
|
||||
{
|
||||
var featureInstance = feature.CreateInstance<DetailsProviderFeature>();
|
||||
featureResult = featureInstance.GetDetails(database, device, timestamp);
|
||||
|
||||
if (featureResult != null)
|
||||
{
|
||||
if (featureResult.ExpiresOn > DateTime.Now)
|
||||
{
|
||||
if (cacheResult == null)
|
||||
database.DeviceDetails.Add(new DeviceDetail() { DeviceSerialNumber = device.SerialNumber, Scope = DetailsScope, Key = feature.Id, Value = JsonConvert.SerializeObject(featureResult) });
|
||||
else
|
||||
cacheResult.DbDetails.Value = JsonConvert.SerializeObject(featureResult);
|
||||
saveChangesRequired = true;
|
||||
}
|
||||
else if (cacheResult != null)
|
||||
{
|
||||
database.DeviceDetails.Remove(cacheResult.DbDetails);
|
||||
saveChangesRequired = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// ignore exceptions when plugins behave badly
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
featureResult = cacheResult.Details;
|
||||
}
|
||||
|
||||
// apply feature results
|
||||
if (featureResult != null)
|
||||
{
|
||||
result.SetExpiration(featureResult.ExpiresOn);
|
||||
foreach (var value in featureResult.Details)
|
||||
{
|
||||
result.Details[value.Key] = value.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (saveChangesRequired)
|
||||
database.SaveChanges();
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user