a819d2722a
Document Template Attachments, Device Batches, Device Profiles and User Flags can be associated with an Active Directory group. This AD group is then automatically synchronized with relevant User/Machine accounts. Contains various other UI tweaks and configuration enhancements.
64 lines
1.7 KiB
C#
64 lines
1.7 KiB
C#
using Disco.Data.Repository;
|
|
using Disco.Models.Repository;
|
|
using System.Collections.Concurrent;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Disco.Services.Users.UserFlags
|
|
{
|
|
internal class Cache
|
|
{
|
|
private ConcurrentDictionary<int, UserFlag> _Cache;
|
|
|
|
public Cache(DiscoDataContext Database)
|
|
{
|
|
Initialize(Database);
|
|
}
|
|
|
|
public void ReInitialize(DiscoDataContext Database)
|
|
{
|
|
Initialize(Database);
|
|
}
|
|
|
|
private void Initialize(DiscoDataContext Database)
|
|
{
|
|
// Queues from Database
|
|
var flags = Database.UserFlags.ToList();
|
|
|
|
// Add Queues to In-Memory Cache
|
|
this._Cache = new ConcurrentDictionary<int, UserFlag>(flags.Select(f => new KeyValuePair<int, UserFlag>(f.Id, f)));
|
|
}
|
|
|
|
public UserFlag GetUserFlag(int UserFlagId)
|
|
{
|
|
UserFlag item;
|
|
if (_Cache.TryGetValue(UserFlagId, out item))
|
|
return item;
|
|
else
|
|
return null;
|
|
}
|
|
public List<UserFlag> GetUserFlags()
|
|
{
|
|
return _Cache.Values.ToList();
|
|
}
|
|
|
|
public void AddOrUpdate(UserFlag UserFlag)
|
|
{
|
|
_Cache.AddOrUpdate(UserFlag.Id, UserFlag, (key, existingItem) => UserFlag);
|
|
}
|
|
|
|
public UserFlag Remove(int UserFlagId)
|
|
{
|
|
UserFlag item;
|
|
if (_Cache.TryRemove(UserFlagId, out item))
|
|
return item;
|
|
else
|
|
return null;
|
|
}
|
|
public UserFlag Remove(UserFlag UserFlag)
|
|
{
|
|
return Remove(UserFlag.Id);
|
|
}
|
|
}
|
|
}
|