SelectResponse AmazonSimpleDB.Select(SelectRequest request)
{
var match = QueryAnalyzer.Match(request.SelectExpression);
if (!match.Success)
{
throw new InvalidOperationException("The specified request does not contain a valid select expression.");
}
var attributes = match.Groups[1].Value;
var domain = match.Groups[2].Value;
Dictionary<string, Dictionary<string, string>> items;
if (!Domains.TryGetValue(domain, out items))
{
throw new InvalidOperationException("The specified domain does not exist.");
}
var skip = 0;
if (request.IsSetNextToken())
{
int.TryParse(request.NextToken, out skip);
}
var result = new SelectResponse()
.WithSelectResult(new SelectResult()
.WithItem(IntoItem(items
.Skip(skip)
.Take(MaxItems))));
if (result.SelectResult.Item.Count == MaxItems)
{
result.SelectResult.WithNextToken((skip + MaxItems).ToString());
}
++SelectCount;
return result;
}