tik4net.Api.ApiCommand.ExecuteScalar C# (CSharp) Метод

ExecuteScalar() публичный Метод

public ExecuteScalar ( ) : string
Результат string
        public string ExecuteScalar()
        {
            EnsureConnectionSet();
            EnsureNotRunning();

            _isRuning = true;
            try
            {
                string[] commandRows = ConstructCommandText(TikCommandParameterFormat.NameValue);
                IEnumerable<ApiSentence> response = EnsureApiSentences(_connection.CallCommandSync(commandRows));
                ThrowPossibleResponseError(response.ToArray());

                if (response.Count() ==1) //!done + =ret=result word
                {
                    ApiDoneSentence doneSentence = EnsureDoneResponse(response.Single());
                    return doneSentence.GetResponseWord();
                }
                else if (response.Count() >= 2)
                {
                    EnsureReReponse(response.First());
                    ApiReSentence reResponse = (ApiReSentence)response.First();
                    EnsureDoneResponse(response.Last());

                    return reResponse.Words.First().Value; //first word value from !re
                }
                else
                    throw new TikConnectionException("Single !done response or at least one !re sentences expected. (1x!done or Nx!re + 1x!done )", this, response.Cast<ITikSentence>());

            }
            finally
            {
                _isRuning = false;
            }
        }

Usage Example

Пример #1
0
        private void Login_v1(string user, string password, bool allowLoginProcessVersion2Fallback)
        {
            //Get login hash
            string responseHash;

            try
            {
                ApiCommand readLoginHashCommand = new ApiCommand(this, "/login");
                responseHash = readLoginHashCommand.ExecuteScalar();
            }
            catch (TikCommandException) //TODO catch specific exception / message
            {
                if (allowLoginProcessVersion2Fallback)
                {
                    Login_v2(user, password); // try it via newer login process
                    return;
                }
                else
                {
                    throw;
                }
            }

            //login connection
            string     hashedPass   = ApiConnectionHelper.EncodePassword(password, responseHash);
            ApiCommand loginCommand = new ApiCommand(this, "/login", TikCommandParameterFormat.NameValue,
                                                     new ApiCommandParameter("name", user), new ApiCommandParameter("response", hashedPass));

            loginCommand.ExecuteNonQuery();
        }
All Usage Examples Of tik4net.Api.ApiCommand::ExecuteScalar