namespace Xylem.Common.Ui.GenesisToolBox.Infrastructure { using System; using System.Collections.Generic; using System.Linq; internal class ApplicationState { internal const string UNAVAILABLE = "Genesis Toolbox is currently not available."; private static IEnumerable softwareFunctions; internal static int Id { get; private set; } internal static bool IsAuthorized { get; private set; } internal static bool 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 bool 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; if (!IsAuthorized) { error = "Genesis Toolbox is currently not available."; softwareFunctions = Array.Empty(); } } return IsAuthorized; } internal static Boolean IsEnabled(SoftwareFunctions softwareFunction) => softwareFunctions.Contains(softwareFunction); } }