Ejemplo n.º 1
0
        public void Stop()
        {
            if (_watching)
            {
                throw new InvalidOperationException("not started");
            }

            _onRunJob.RemoveListener(OnRunJob);
            _onError.RemoveListener(OnError);

            _watching = false;
        }
Ejemplo n.º 2
0
        public static IEnumerator AutoLogin(
            Client client,
            IAccountRepository repository,
            string accountNamespaceName,
            string accountEncryptionKeyId,
            CreateAccountEvent onCreateAccount,
            LoginEvent onLogin,
            ErrorEvent onError
            )
        {
            var error = false;

            void OnCreateAccount(EzAccount account)
            {
                repository.SaveAccount(
                    new PersistAccount
                {
                    UserId   = account.UserId,
                    Password = account.Password,
                }
                    );
            }

            void OnError(Gs2Exception e)
            {
                error = true;
            }

            onCreateAccount.AddListener(OnCreateAccount);
            onError.AddListener(OnError);

            try
            {
                if (!repository.IsExistsAccount())
                {
                    yield return(CreateAccount(
                                     client,
                                     accountNamespaceName,
                                     onCreateAccount,
                                     onError
                                     ));
                }

                if (error)
                {
                    yield break;
                }

                var account = repository.LoadAccount();
                yield return(Login(
                                 client,
                                 account?.UserId,
                                 account?.Password,
                                 accountNamespaceName,
                                 accountEncryptionKeyId,
                                 onLogin,
                                 onError
                                 ));
            }
            finally
            {
                onError.RemoveListener(OnError);
                onCreateAccount.RemoveListener(OnCreateAccount);
            }
        }