public static bool IsFlagsSet(ObjectAccessId accessObject, RightsFlags[] flags,SetType setType=SetType.Any) { if (LoggedUser == null) throw new Exception("Invalid user!"); if (LoggedUser.IsAdmin) return true; switch (setType) { case SetType.All: if (flags.Select(flag => IsFlagSet(accessObject, flag)).All(result => result)) { return true; } break; case SetType.Any: if (flags.Select(flag => IsFlagSet(accessObject, flag)).Any(result => result)) { return true; } break; default: throw new ArgumentOutOfRangeException("setType"); } return false; }
public static bool IsAccesible(ObjectAccessId accessObject) { if (LoggedUser==null) return false; if (LoggedUser.IsAdmin) return true; return !IsFlagSet(accessObject, RightsFlags.None) & IsFlagSet(accessObject, RightsFlags.View); }
public static bool IsFlagSet(ObjectAccessId accessObject, RightsFlags flag) { if (LoggedUser==null) throw new Exception("Invalid user!"); var association = LoggedUser.Access_Associations.SingleOrDefault(a => a.ElementId == accessObject.Id); if (association == null) return false; if (flag.Equals(RightsFlags.None)) return false; return ((RightsFlags) association.RightFlags).HasFlag(flag); }
private bool LoadMainAssemply(string assemblyName) { try { Assembly projectA = Assembly.LoadFile(assemblyName); //Assembly.Load("AccountingEquipment_V2"); _accessObjects = new List<ObjectAccessId>(); var typeAppId = projectA.GetTypes().SingleOrDefault(t => t.GetField("AppId") != null); if (typeAppId != null) { FieldInfo infoAppId = typeAppId.GetField("AppId"); if (infoAppId != null) { var value = infoAppId.GetValue(null);// as ObjectAccessId; if (value != null) AppId = value as ObjectAccessId; } } if (AppId == null) { throw new Exception("Unknown Application!!!"); } foreach (Type t in projectA.GetTypes()) { FieldInfo info = t.GetField("ObjectAccessId"); if (info != null) { ObjectAccessId value = info.GetValue(null) as ObjectAccessId; if (value != null) _accessObjects.Add(value); } } return true; } catch (Exception e) { MessageBox.Show(e.Message); return false; } }
public static bool IsEditable(ObjectAccessId accessObject) { return IsFlagSet(accessObject, RightsFlags.Change | RightsFlags.Delete); }
public static bool IsAccesible(ObjectAccessId accessObject) { return !IsFlagSet(accessObject, RightsFlags.None) & IsFlagSet(accessObject, RightsFlags.View); }