public string RightsToString(AccessRights rights) { var sb = new StringBuilder(); if (rights.HasFlag(AccessRights.Read)) { sb.Append('r'); } if (rights.HasFlag(AccessRights.Write)) { sb.Append('w'); } //if (rights.HasFlag(AccessRights.Remove)) sb.Append('d'); return(sb.ToString()); }
/// <summary> /// получение доступных прав /// </summary> /// <param name="accessRights">Число, по которому выводится перечень прав</param> public static void ProcedureForTask3(AccessRights accessRights) { if (accessRights.HasFlag(AccessRights.AccessDenied)) // если значение >= 64, то нет прав { Console.WriteLine(AccessRights.AccessDenied); } else { Console.WriteLine(accessRights); } }
public static string[] AccessRightsToStringArray(AccessRights accessRights) { var values = new List<string>(2); foreach (AccessRights right in Enum.GetValues(typeof(AccessRights))) { if (accessRights.HasFlag(right)) { values.Add(right.ToString()); } } return values.ToArray(); }
public static string[] AccessRightsToStringArray(AccessRights accessRights) { var values = new List <string>(2); foreach (AccessRights right in Enum.GetValues(typeof(AccessRights))) { if (accessRights.HasFlag(right)) { values.Add(right.ToString()); } } return(values.ToArray()); }
/// <summary> /// Показывает права пользователя. /// </summary> /// <param name="rights">Список прав пользователя</param> public static void ShowRights(AccessRights rights) { byte count = (byte)rights; if (rights.HasFlag(AccessRights.AccessDenied)) { Console.WriteLine((AccessRights)64); return; } double power = Math.Floor(Math.Log2(count - 1)); double finalPower = Math.Pow(2, power + 1) - 1; Console.WriteLine((AccessRights)finalPower); }
public static List <AccessRights> GetAccessRights(this AccessRights mask) { var rights = new List <AccessRights>(); foreach (AccessRights right in Enum.GetValues(typeof(AccessRights))) { if (right == AccessRights.None) { continue; } if (mask.HasFlag(right)) { rights.Add(right); } } return(rights); }
/// <summary> /// Распечатать перечень действий, разрешенных правами /// </summary> /// <param name="accessRight">Тип прав</param> public void PrintAllowedAction(AccessRights accessRight) { if (accessRight.HasFlag(AccessRights.AccessDenied)) { Console.WriteLine(AccessRights.AccessDenied); return; } IEnumerable <AccessRights> allowedRights = Enum.GetValues(typeof(AccessRights)) .Cast <AccessRights>() .Where(a => accessRight >= a); foreach (var accRight in allowedRights) { Console.WriteLine(accRight); } }
/// <summary> /// Print rights in console /// </summary> /// <param name="rights">Right flags</param> public static void ShowRights(AccessRights rights) { if (rights.HasFlag(AccessRights.AccessDenied)) { Console.Write("Access denied\n"); return; } if (rights.HasFlag(AccessRights.View)) { Console.Write("View "); } if (rights.HasFlag(AccessRights.Run)) { Console.Write("Run "); } if (rights.HasFlag(AccessRights.Add)) { Console.Write("Add "); } if (rights.HasFlag(AccessRights.Edit)) { Console.Write("Edit "); } if (rights.HasFlag(AccessRights.Ratify)) { Console.Write("Ratify "); } if (rights.HasFlag(AccessRights.Delete)) { Console.Write("Delete"); } Console.WriteLine(); }
static internal string GetAccessRightsAsString(AccessRights enumValue) { List <string> valueArray = new List <string>(); string returnValue = "None"; if (enumValue.HasFlag(AccessRights.ReadAccess) || enumValue.HasFlag(AccessRights.All)) { valueArray.Add("ReadAccess"); } if (enumValue.HasFlag(AccessRights.WriteAccess) || enumValue.HasFlag(AccessRights.All)) { valueArray.Add("WriteAccess"); } if (enumValue.HasFlag(AccessRights.ShareAccess) || enumValue.HasFlag(AccessRights.All)) { valueArray.Add("ShareAccess"); } if (enumValue.HasFlag(AccessRights.AssignAccess) || enumValue.HasFlag(AccessRights.All)) { valueArray.Add("AssignAccess"); } if (enumValue.HasFlag(AccessRights.AppendAccess) || enumValue.HasFlag(AccessRights.All)) { valueArray.Add("AppendAccess"); } if (enumValue.HasFlag(AccessRights.AppendToAccess) || enumValue.HasFlag(AccessRights.All)) { valueArray.Add("AppendToAccess"); } if (enumValue.HasFlag(AccessRights.CreateAccess) || enumValue.HasFlag(AccessRights.All)) { valueArray.Add("CreateAccess"); } if (enumValue.HasFlag(AccessRights.DeleteAccess) || enumValue.HasFlag(AccessRights.All)) { valueArray.Add("DeleteAccess"); } returnValue = String.Join(" ", valueArray.ToArray()); return(returnValue); }