Exemplo n.º 1
0
        /// <summary>
        /// Loads a player stash using the drop down list.
        /// </summary>
        /// <param name="selectedSave">Item from the drop down list.</param>
        /// <returns></returns>
        public LoadPlayerStashResult LoadPlayerStash(PlayerSave selectedSave)
        {
            var result = new LoadPlayerStashResult();

            if (string.IsNullOrWhiteSpace(selectedSave?.Name))
            {
                return(result);
            }

            #region Get the player's stash

            result.StashFile = GamePathResolver.GetPlayerStashFile(selectedSave.Name);

            result.Stash = this.userContext.Stashes.GetOrAddAtomic(result.StashFile, k =>
            {
                var stash = new Stash(selectedSave.Name, k);
                try
                {
                    stash.StashFound = StashProvider.LoadFile(stash);
                }
                catch (ArgumentException argumentException)
                {
                    stash.ArgumentException = argumentException;
                }
                return(stash);
            });

            #endregion

            return(result);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Loads a player using the drop down list.
        /// Assumes designators are appended to character name.
        /// </summary>
        /// <param name="selectedText">Player string from the drop down list.</param>
        /// <param name="isIT"></param>
        /// <returns></returns>
        public LoadPlayerResult LoadPlayer(string selectedText, bool isIT = false)
        {
            var result = new LoadPlayerResult();

            if (string.IsNullOrWhiteSpace(selectedText))
            {
                return(result);
            }

            result.IsCustom = selectedText.EndsWith(PlayerService.CustomDesignator, StringComparison.Ordinal);
            if (result.IsCustom)
            {
                // strip off the end from the player name.
                selectedText = selectedText.Remove(selectedText.IndexOf(PlayerService.CustomDesignator, StringComparison.Ordinal), PlayerService.CustomDesignator.Length);
            }

            #region Get the player

            result.PlayerFile = GamePathResolver.GetPlayerFile(selectedText);

            try
            {
                result.Player = this.userContext.Players[result.PlayerFile];
            }
            catch (KeyNotFoundException)
            {
                result.Player = new PlayerCollection(selectedText, result.PlayerFile);
                result.Player.IsImmortalThrone = isIT;
                try
                {
                    PlayerCollectionProvider.LoadFile(result.Player);
                    this.userContext.Players.Add(result.PlayerFile, result.Player);
                }
                catch (ArgumentException argumentException)
                {
                    result.PlayerArgumentException = argumentException;
                }
            }

            #endregion

            #region Get the player's stash

            result.StashFile = GamePathResolver.GetPlayerStashFile(selectedText);

            try
            {
                result.Stash = this.userContext.Stashes[result.StashFile];
            }
            catch (KeyNotFoundException)
            {
                result.Stash = new Stash(selectedText, result.StashFile);
                try
                {
                    result.StashFound = StashProvider.LoadFile(result.Stash);
                    if (result.StashFound.Value)
                    {
                        this.userContext.Stashes.Add(result.StashFile, result.Stash);
                    }
                }
                catch (ArgumentException argumentException)
                {
                    result.StashArgumentException = argumentException;
                }
            }

            #endregion

            return(result);
        }