Esempio n. 1
0
        private void InsertCharacterOnTable()
        {
            var resources = new SingleAssemblyResourceManager(typeof(Language));

            lock (stateLock)
            {
                // does not allow add a character on table when refresh list
                while (updateTableThread != null &&
                       updateTableThread.ThreadState != ThreadState.Stopped &&
                       updateTableThread.ThreadState != ThreadState.Unstarted)
                {
                    Thread.Sleep(1000);
                }

                var character = default(CharacterDTO);

                if (_charactersOnTable.All(x => x.Name.ToLower().Trim() != this.textBoxPlayerName.Text.ToLower().Trim()))
                {
                    try
                    {
                        character          = _requestService.GetCharacterInformation(this.textBoxPlayerName.Text);
                        character.IsOnline = _requestService.GetOnlineCharacters(character.World).Any(x => x.Name.ToLower() == character.Name.ToLower());

                        _charactersOnTable.Add(character);
                    }
                    catch (OfflineWorldException)
                    {
                        character.IsOnline = false;

                        _charactersOnTable.Add(character);
                    }
                    catch (InvalidCharacterException)
                    {
                        var message = resources.GetString("InvalidCharacterName");
                        MessageBox.Show(message);
                    }
                    catch (Exception)
                    {
                        var message = resources.GetString("UnableToConnectTibiaWebsite");
                        MessageBox.Show(message);
                    }
                }
            }

            Invoke(new MethodInvoker(InsertCharacterOnTableFinish));
        }
Esempio n. 2
0
        private void GetCharacterDeaths()
        {
            var updateCounterDelegate = new MethodInvoker(UpdateCount);

            lock (stateLock)
            {
                numPlayersOnline = 0;
                numPlayerCount   = 0;
            }
            Invoke(updateCounterDelegate);

            lock (stateLock)
            {
                try
                {
                    characters = _requestService.GetOnlineCharacters(selectedWorld).ToList();
                }
                catch (OfflineWorldException)
                {
                    var resources = new SingleAssemblyResourceManager(typeof(Language));
                    MessageBox.Show(resources.GetString("SelectedWorldIsOffline"));

                    Invoke(new MethodInvoker(Finish));
                    return;
                }

                numPlayersOnline = characters.Count;
            }

            // I tested a parallel for. Does not worth.
            for (var i = 0; i < characters.Count; i++)
            {
                lock (stateLock)
                {
                    characters[i] = _requestService.GetCharacterInformation(characters[i].Name);
                    numPlayerCount++;
                }

                Invoke(updateCounterDelegate);
            }

            Invoke(new MethodInvoker(Finish));
        }