Esempio n. 1
0
        protected override void OnEventFired(object source, ButtonClickedEventArgs args)
        {
            //Do nothing, it's not valid.
            if (String.IsNullOrWhiteSpace(FriendInputText.Text))
            {
                return;
            }

            //Disable the add button temporarily.
            AddFriendButton.IsInteractable = false;

            //Try adding them
            UnityAsyncHelper.UnityMainThreadContext.PostAsync(async() =>
            {
                try
                {
                    var responseModel = await SocialService.TryAddFriendAsync(FriendInputText.Text);

                    if (responseModel.isSuccessful)
                    {
                        if (Logger.IsInfoEnabled)
                        {
                            Logger.Info($"Friend add successful. EntityId: {responseModel.Result.NewFriendEntityGuid}");
                        }

                        //Just publish us gaining a new friend.
                        FriendAddedPublisher.PublishEvent(this, new CharacterFriendAddedEventArgs(responseModel.Result.NewFriendEntityGuid));
                    }
                    else
                    if (Logger.IsWarnEnabled)
                    {
                        Logger.Warn($"Friend add failed. Result Code: {responseModel.ResultCode}");
                    }
                }
                catch (Exception e)
                {
                    if (Logger.IsErrorEnabled)
                    {
                        Logger.Error($"Friend add failed. Exception: {e.ToString()}");
                    }

                    throw;
                }
                finally
                {
                    //Close it either way, even if the add failed.
                    //Then renable it for future use.
                    FriendsAddModalWindow.SetElementActive(false);
                    AddFriendButton.IsInteractable = true;
                    FriendInputText.Text           = "";
                }
            });
        }