private static QueryError ParseError(string errorString) { // Ex: // error id=2568 msg=insufficient\sclient\spermissions failed_permid=27 if (errorString == null) { throw new ArgumentNullException(nameof(errorString)); } errorString = errorString.Remove(0, "error ".Length); var errParams = errorString.Split(' '); /* * id=2568 * msg=insufficient\sclient\spermissions * failed_permid=27 */ var parsedError = new QueryError { FailedPermissionId = -1 }; for (int i = 0; i < errParams.Length; ++i) { var errData = errParams[i].Split('='); /* * id * 2568 */ var fieldName = errData[0].ToUpperInvariant(); switch (fieldName) { case "ID": parsedError.Id = errData.Length > 1 ? int.Parse(errData[1], NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.CurrentCulture) : -1; continue; case "MSG": parsedError.Message = errData.Length > 1 ? errData[1].TeamSpeakUnescape() : null; continue; case "FAILED_PERMID": parsedError.FailedPermissionId = errData.Length > 1 ? int.Parse(errData[1], NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.CurrentCulture) : -1; continue; default: throw new QueryProtocolException(); } } return(parsedError); }
private static QueryError ParseError(string errorString) { // Ex: // error id=2568 msg=insufficient\sclient\spermissions failed_permid=27 if (errorString == null) throw new ArgumentNullException(nameof(errorString)); errorString = errorString.Remove(0, "error ".Length); var errParams = errorString.Split(' '); /* id=2568 msg=insufficient\sclient\spermissions failed_permid=27 */ var parsedError = new QueryError { FailedPermissionId = -1 }; for (int i = 0; i < errParams.Length; ++i) { var errData = errParams[i].Split('='); /* id 2568 */ string fieldName = errData[0].ToUpperInvariant(); switch (fieldName) { case "ID": parsedError.Id = errData.Length > 1 ? int.Parse(errData[1], NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.CurrentCulture) : -1; continue; case "MSG": parsedError.Message = errData.Length > 1 ? errData[1].TeamSpeakUnescape() : null; continue; case "FAILED_PERMID": parsedError.FailedPermissionId = errData.Length > 1 ? int.Parse(errData[1], NumberStyles.AllowLeadingWhite | NumberStyles.AllowTrailingWhite, CultureInfo.CurrentCulture) : -1; continue; default: throw new QueryProtocolException(); } } return parsedError; }
/// <summary>Initializes a new instance of the <see cref="T:TeamSpeak3QueryApi.Net.QueryException"/> class with a specified error returned by the Query API.</summary> /// <param name="error">The <see cref="T:TeamSpeak3QueryApi.Net.QueryError"/> that was returned by the Query API.</param> public QueryException(QueryError error) : this("An error occurred during the query.") { Error = error; }
/// <summary>Initializes a new instance of the <see cref="T:TeamSpeak3QueryApi.Net.QueryException"/> class with a specified error returned by the Query API.</summary> /// <param name="error">The <see cref="T:TeamSpeak3QueryApi.Net.QueryError"/> that was returned by the Query API.</param> public QueryException(QueryError error) : this("An error occurred during the query.") { Error = error; }