remove device custom details
this plugin functionality has never been used
This commit is contained in:
@@ -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