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("ret")); } 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; } }
public ITikReSentence ExecuteSingleRow() { EnsureConnectionSet(); EnsureNotRunning(); _isRuning = true; try { string[] commandRows = ConstructCommandText(TikCommandParameterFormat.Filter); IEnumerable <ApiSentence> response = EnsureApiSentences(_connection.CallCommandSync(commandRows)); ThrowPossibleResponseError(response.ToArray()); if (response.OfType <ApiReSentence>().Count() > 1) { throw new TikCommandAmbiguousResultException(this); } EnsureOneReAndDone(response); ApiReSentence result = (ApiReSentence)response.First(); return(result); } finally { _isRuning = false; } }
private void EnsureReReponse(params ApiSentence[] responseSentences) { foreach (ApiSentence responseSentence in responseSentences) { ApiReSentence reSentence = responseSentence as ApiReSentence; if (reSentence == null) { throw new TikConnectionException("!re sentence expected as result.", this, responseSentence); } } }
private string ExecuteScalarInternal(string target, bool allowReturnDefault, string defaultValue = null) { EnsureConnectionSet(); EnsureNotRunning(); _isRuning = true; try { var targetParameterInArray = target != null ? new ITikCommandParameter[] { new ApiCommandParameter(TikSpecialProperties.Proplist, target, TikCommandParameterFormat.NameValue) } : new ITikCommandParameter[] { }; string[] commandRows = ConstructCommandText(TikCommandParameterFormat.NameValue, targetParameterInArray); IEnumerable <ApiSentence> response = EnsureApiSentences(_connection.CallCommandSync(commandRows)); ThrowPossibleResponseError(response.ToArray()); if (response.Count() == 1) //!done + =ret=result word { ApiDoneSentence doneSentence = EnsureDoneResponse(response.Single()); if (doneSentence.Words.ContainsKey(TikSpecialProperties.Ret)) { return(doneSentence.GetResponseWord()); } else if (allowReturnDefault) { return(defaultValue); } else { throw new TikNoSuchItemException(this); } } else if (response.Count() == 2) //!re + !done { EnsureOneReAndDone(response); ApiReSentence reResponse = (ApiReSentence)response.First(); return(reResponse.Words.Single(v => v.Key != TikSpecialProperties.Tag).Value); //single word value from !re //NOTE - .tag could be added when Connection.SendTagWithSyncCommand=true } else { throw new TikCommandUnexpectedResponseException("Single !done response or exactly one !re sentences expected. (1x!done or 1x!re + 1x!done )", this, response.Cast <ITikSentence>()); } } finally { _isRuning = false; } }
public ITikReSentence ExecuteSingleRow() { EnsureConnectionSet(); EnsureNotRunning(); _isRuning = true; try { string[] commandRows = ConstructCommandText(TikCommandParameterFormat.Filter); IEnumerable <ApiSentence> response = EnsureApiSentences(_connection.CallCommandSync(commandRows)); ThrowPossibleResponseError(response.ToArray()); EnsureExcatNumberOfResponses(response, 2); EnsureReReponse(response.First()); //!re ApiReSentence result = (ApiReSentence)response.First(); EnsureDoneResponse(response.Last()); //!done return(result); } finally { _isRuning = false; } }
public void ExecuteAsync(Action <ITikReSentence> oneResponseCallback, Action <ITikTrapSentence> errorCallback = null) { EnsureConnectionSet(); EnsureNotRunning(); System.Diagnostics.Debug.Assert(_asyncLoadingThread == null); int tag = Interlocked.Increment(ref _tagCounter); _isRuning = true; _runningTag = tag; try { string[] commandRows = ConstructCommandText(TikCommandParameterFormat.NameValue); _asyncLoadingThread = _connection.CallCommandAsync(commandRows, tag.ToString(), response => { ApiReSentence reResponse = response as ApiReSentence; if (reResponse != null) { if (oneResponseCallback != null) { oneResponseCallback(reResponse); } } else { ApiTrapSentence trapResponse = response as ApiTrapSentence; if (trapResponse != null) { if (trapResponse.CategoryCode == "2" && trapResponse.Message == "interrupted") { //correct state - async operation has been Cancelled. } else { //incorrect - any error occurs if (errorCallback != null) { errorCallback(trapResponse); } } } else if (response is ApiDoneSentence || response is ApiFatalSentence) { //REMARKS: we are expecting !trap + !done sentences when any error occurs _isRuning = false; _runningTag = -1; _asyncLoadingThread = null; } } }); } catch { _isRuning = false; _runningTag = -1; throw; } finally { //still running } }