Exemple #1
0
        //create a task factory

        private async Task <CharacterFull> GetCharacter()
        {
            CharacterFull result = await pService.GetSingleCharacterAsync(MyCharacter.character_id);

            //MyCharacter = result;
            return(result);
        }
        private CachedCharacter AddToCache(string charID, CharacterFull character)
        {
            var res = new CachedCharacter(character);

            characters.TryAdd(charID, res);
            return(res);
        }
Exemple #3
0
 private async void SetCharacter()
 {
     //theStack.IsVisible = false;
     theLoader.IsRunning = true;
     //theTask = new Task<CharacterFull>(() => GetCharacter().Result);
     //theTask = new Task(async () => await GetAndSetCharacter());
     theTask = new Task <CharacterFull>(() => pService.GetSingleCharacter(_characterId));
     theTask.Start();
     theLoader.IsRunning = false;
     this.Title          = (titleName + "'s stats");
     Console.WriteLine($"\n\n[][]TASK WHILE LOOP START[][]\n{theTask.Status.ToString()}\n");
     while (theTask.IsCompleted == false)
     {
         Console.WriteLine($"\n\n[][]Task status debug[][]\n{theTask.Status.ToString()}\n");
         //do nothing
         //if (theTask.Status == TaskStatus.RanToCompletion) break;
     }
     Console.WriteLine($"\n\n[][]EXITED WHILE LOOP[][]\n{theTask.Status.ToString()}\n");
     if (theTask.IsCompleted && theTask.IsFaulted == false)
     {
         MyCharacter = theTask.Result;
     }
     if (theTask.IsFaulted)
     {
         DisplayAlert("Error", $"Error downloading character.\n{theTask.Exception.InnerException.ToString()}\n", "Okay");
     }
 }
 public CachedCharacter(CharacterFull character)
 {
     _character    = character;
     nameChanged   = false;
     visualChanged = false;
     dataChanged   = false;
     valueAccessed = false;
 }
        public async Task <bool> CreateCharacter(string userID, string charName, JObject visualData)
        {
            var user = await getCharacterData.GetUserData(userID);

            if (user == null)
            {
                return(false);
            }
            var oldChar = await getCharacterData.GetCharacterByName(charName);

            if (oldChar != null)
            {
                return(false);
            }
            if (user.userData.characterCreationLimit > 0)
            {
                var guid    = Guid.NewGuid().ToString();
                var newChar = new CharacterFull
                {
                    characterVisualData = visualData,
                    userID        = userID,
                    characterName = charName,
                    characterID   = guid
                };
                user.userData.characterCreationLimit--;
                var res = await createCharacter.CreateCharacter(newChar, user);

                if (res)
                {
                    eventManager.InvokeEvent(UserServiceEvents.CHARACTER_CREATE_EVENT, guid, userID);
                }
                else
                {
                    user.userData.characterCreationLimit++;
                }
                return(res);
            }

            return(false);
        }
Exemple #6
0
        public async Task <bool> CreateCharacter(CharacterFull character, User user)
        {
            using (var connection = dbHelper.GetConnection())
            {
                connection.Open();
                using (var transaction = connection.BeginTransaction())
                {
                    var res1 = await dbHelper.CallStoredProcedureExec("CreateCharacter",
                                                                      new DynamicParameters()
                                                                      .AddParameter("charID", character.characterID)
                                                                      .AddParameter("userID", character.userID)
                                                                      .AddParameter("charName", character.characterName)
                                                                      .AddParameter("charVisual", character.characterVisualData.ToString(Formatting.None))
                                                                      .AddParameter("charData", JsonConvert.SerializeObject(character.characterGameData))
                                                                      ) > 0;

                    if (!res1)
                    {
                        transaction.Rollback();
                        connection.Close();
                        return(false);
                    }
                    var res2 = await SetUserData(user.userID, user.userData);

                    if (!res2)
                    {
                        transaction.Rollback();
                        connection.Close();
                        return(false);
                    }
                    transaction.Commit();
                    connection.Close();
                    return(true);
                }
            }
        }
Exemple #7
0
        private async Task GetAndSetCharacter()
        {
            CharacterFull result = await pService.GetSingleCharacterAsync(MyCharacter.character_id);

            MyCharacter = result;
        }