private void ThrowPossibleResponseError(params ApiSentence[] responseSentences) { foreach (ApiSentence responseSentence in responseSentences) { ApiTrapSentence trapSentence = responseSentence as ApiTrapSentence; if (trapSentence != null) { //detect well known error responses and convert them to special exceptions if (trapSentence.Message.StartsWith("no such command")) { throw new TikNoSuchCommandException(this, trapSentence); } else if (trapSentence.Message.StartsWith("no such item")) { throw new TikNoSuchItemException(this, trapSentence); } else if (AlreadyWithSuchRegex.IsMatch(trapSentence.Message)) { throw new TikAlreadyHaveSuchItemException(this, trapSentence); } else { throw new TikCommandTrapException(this, trapSentence); } } ApiFatalSentence fatalSentence = responseSentence as ApiFatalSentence; if (fatalSentence != null) { throw new TikCommandFatalException(this, fatalSentence.Message); } } }
private void ThrowPossibleResponseError(params ApiSentence[] responseSentences) { foreach (ApiSentence responseSentence in responseSentences) { ApiTrapSentence trapSentence = responseSentence as ApiTrapSentence; if (trapSentence != null) { throw new TikCommandException(this, trapSentence); } ApiFatalSentence fatalSentence = responseSentence as ApiFatalSentence; if (fatalSentence != null) { throw new TikCommandException(this, fatalSentence.Message); } } }
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 } }