using System; using System.Collections.Generic; using System.Linq; namespace Xylem.Common.Utils.UserAccessCtrl { internal class ApplicationState { internal const String UNAVAILABLE = "Genesis Toolbox is currently not available."; private static IEnumerable softwareFunctions; internal static Int32 Id { get; private set; } internal static String User { get; private set; } internal static Boolean IsAuthorized { get; private set; } internal static Boolean Initialized { get; private set; } internal static ApplicationVersion Version { get; private set; } = ApplicationVersion.Current; internal static void Initialize() { Id = ApplicationHttp.ApplicationId( software: Version.Assembly.Name, functions: Enum.GetNames(typeof(SoftwareFunctions))); Initialized = Id > 0; } internal static Boolean Authorize(String username, String password, out String error) { error = default(String); if (Id <= 0) { error = "Genesis Toolbox is currently not available."; } else { softwareFunctions = ApplicationHttp.GetSoftwareFunction(Id, username, password); IsAuthorized = softwareFunctions != null; User = username; if (!IsAuthorized) { error = "Genesis Toolbox is currently not available."; softwareFunctions = Array.Empty(); } } return IsAuthorized; } internal static Boolean IsEnabled(SoftwareFunctions softwareFunction) => softwareFunctions.Contains(softwareFunction); } }