Esempio n. 1
0
        /// <summary>
        /// Used to generate tokens or verify the validity of tokens
        /// </summary>
        /// <returns>Validation results</returns>
        public async Task <InitResultType> InitAsync()
        {
            InitResultType result = InitResultType.Success;

            if (string.IsNullOrEmpty(Token))
            {
                var token = await NetworkTools.GetClientCredentialsToken(_clientId, _clientSecret, _permissions, (msg) =>
                {
                    var args = new ExceptionEventArgs(msg);
                    OnException?.Invoke(this, args);
                });

                if (token.IsError)
                {
                    if (token.ErrorType == IdentityModel.Client.ResponseErrorType.Http)
                    {
                        result = InitResultType.HttpError;
                    }
                    else
                    {
                        result = InitResultType.InvalidParameters;
                    }
                }
                else
                {
                    Token  = token.AccessToken;
                    result = InitResultType.Success;
                }
            }
            else
            {
                string testRoute = "basic/earthStatus";
                await NetworkTools.GetEntityAsync <EarthStatus>(testRoute, Token, (msg) =>
                {
                    if (msg.Code == 601)
                    {
                        result = InitResultType.HttpError;
                    }
                    else
                    {
                        result = InitResultType.TokenExpiry;
                    }
                });
            }
            return(result);
        }
Esempio n. 2
0
        public CoreViewModel()
        {
            _currentAppMode = AppMode.None;
            _initResult = InitResultType.None;
            _userVars = new Dictionary<string, EnVar>();
            _systemVars = new Dictionary<string, EnVar>();
            _modificationMode = ModificationModeType.None;
            _modificationTitle = string.Empty;
            _modifiedKey = string.Empty;
            _modifiedValue = string.Empty;
            _validationMessage = string.Empty;
            _hasUserImportVariables = false;
            _hasSystemImportVariables = false;
            _hasUserExportVariables = false;
            _hasSystemExportVariables = false;
            _hasInitImportStatus = false;
            _hasImportConflicts = false;

            // Get the services
            _messageService = ServiceManager.Instance.GetService<IMessageService>();
            _modificationService = ServiceManager.Instance.GetService<IModificationService>();
            _fileService = ServiceManager.Instance.GetService<IFileService>();
            _progressService = ServiceManager.Instance.GetService<IProgressService>();

            // InitializeEnvironmentVariables the commands
            InitializeCommands();
        }