27c21175d7
Migrate much of BI to Services. Added Wireless Profile Provider plugin feature. Added Certificate Authority Provider plugin feature. Modified Certificate Provider plugin feature. Database migration v17, for Device Profiles. Enrolment Client Updated to support CA Certificates, Wireless Profiles and Hardware Info. New Client Enrolment Protocol to support new features. Plugin Manifest Generator added to main solution. Improved AD search performance.
80 lines
2.8 KiB
C#
80 lines
2.8 KiB
C#
using Disco.Models.Repository;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel.DataAnnotations;
|
|
using System.Linq;
|
|
|
|
namespace Disco.Services
|
|
{
|
|
public static class JobFlagExtensions
|
|
{
|
|
|
|
private static Dictionary<string, Dictionary<long, string>> allFlags;
|
|
private static void CacheAllFlags()
|
|
{
|
|
if (allFlags == null)
|
|
{
|
|
var fType = typeof(Job.UserManagementFlags);
|
|
var fMembers = fType.GetFields(System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
|
|
|
|
var flags = new Dictionary<string, Dictionary<long, string>>();
|
|
foreach (var f in fMembers)
|
|
{
|
|
DisplayAttribute display = (DisplayAttribute)(f.GetCustomAttributes(typeof(DisplayAttribute), false)[0]);
|
|
string gn = display.GroupName;
|
|
Dictionary<long, string> g;
|
|
if (!flags.TryGetValue(gn, out g))
|
|
{
|
|
g = new Dictionary<long, string>();
|
|
flags.Add(gn, g);
|
|
}
|
|
g[(long)f.GetRawConstantValue()] = display.Name;
|
|
}
|
|
allFlags = flags;
|
|
}
|
|
}
|
|
|
|
public static Dictionary<string, List<Tuple<long, string, bool>>> ValidFlagsGrouped(this Job j)
|
|
{
|
|
Dictionary<string, List<Tuple<long, string, bool>>> validFlags = new Dictionary<string, List<Tuple<long, string, bool>>>();
|
|
|
|
CacheAllFlags();
|
|
|
|
var currentFlags = (long)(j.Flags ?? 0);
|
|
|
|
foreach (var jt in j.JobSubTypes)
|
|
{
|
|
Dictionary<long, string> g;
|
|
if (allFlags.TryGetValue(jt.Id, out g))
|
|
{
|
|
validFlags[jt.Id] = g.Select(f => new Tuple<long, string, bool>(f.Key, f.Value, ((currentFlags & f.Key) == f.Key))).ToList();
|
|
}
|
|
else
|
|
{
|
|
validFlags[jt.Id] = null;
|
|
}
|
|
}
|
|
return validFlags;
|
|
}
|
|
public static Dictionary<long, Tuple<string, bool>> ValidFlags(this Job j)
|
|
{
|
|
Dictionary<long, Tuple<string, bool>> validFlags = new Dictionary<long, Tuple<string, bool>>();
|
|
|
|
CacheAllFlags();
|
|
|
|
var currentFlags = (long)(j.Flags ?? 0);
|
|
|
|
foreach (var jt in j.JobSubTypes)
|
|
{
|
|
Dictionary<long, string> g;
|
|
if (allFlags.TryGetValue(jt.Id, out g))
|
|
{
|
|
foreach (var f in g)
|
|
validFlags[f.Key] = new Tuple<string, bool>(string.Format("{0}: {1}", jt.Description, f.Value), ((currentFlags & f.Key) == f.Key));
|
|
}
|
|
}
|
|
return validFlags;
|
|
}
|
|
}
|
|
}
|