示例#1
0
        private async Task <CharacterCreationResponseCode> RequestCharacterCreation(string name)
        {
            CharacterNameValidationResponse nameValidationResponse = await CharacterService.ValidateName(name);

            CharacterCreationResponseCode responseCode = CharacterCreationResponseCode.Success;

            if (!nameValidationResponse.isSuccessful)
            {
                if (Logger.IsInfoEnabled)
                {
                    Logger.Info($"Failed to validate name. Reason: {nameValidationResponse.ResultCode}");
                }

                responseCode = CharacterCreationResponseCode.NameUnavailableError;
            }
            else
            {
                //If it's valid, we can create it.
                CharacterCreationResponse creationResponse = await CharacterService.CreateCharacter(name);

                if (!creationResponse.isSuccessful)
                {
                    if (Logger.IsInfoEnabled)
                    {
                        Logger.Info($"Failed to create character. Reason: {creationResponse.ResultCode}");
                    }
                }

                responseCode = creationResponse.ResultCode;
            }

            return(responseCode);
        }
示例#2
0
        protected override void OnEventFired(object source, ButtonClickedEventArgs args)
        {
            string name = CharacterNameInput.Text;

            UnityAsyncHelper.UnityMainThreadContext.PostAsync(async() =>
            {
                CharacterCreationResponseCode responseCode = CharacterCreationResponseCode.Success;

                try
                {
                    responseCode = await RequestCharacterCreation(name);
                }
                catch (Exception e)
                {
                    if (Logger.IsErrorEnabled)
                    {
                        Logger.Error($"Failed to handle character creation request. Reason: {e.Message}");
                    }

                    //For the finally block we need to set error
                    responseCode = CharacterCreationResponseCode.GeneralServerError;

                    throw;
                }
                finally
                {
                    if (Logger.IsInfoEnabled)
                    {
                        Logger.Info($"Character creation request Result: {responseCode}");
                    }

                    //Now, we dispatch an event for the result on the main thread.
                    await new UnityYieldAwaitable();

                    OnCharacterCreationAttempted?.Invoke(this, new CharacterCreationAttemptedEventArgs(name, responseCode));
                }
            });
        }