Container for the parameters to the Query operation.

A Query operation directly accesses items from a table using the table primary key, or from an index using the index key. You must provide a specific hash key value. You can narrow the scope of the query by using comparison operators on the range key value, or on the index key. You can use the ScanIndexForward parameter to get results in forward or reverse order, by range key or by index key.

Queries that do not return results consume the minimum read capacity units according to the type of read.

If the total number of items meeting the query criteria exceeds the result set size limit of 1 MB, the query stops and results are returned to the user with a LastEvaluatedKey to continue the query in a subsequent operation. Unlike a Scan operation, a Query operation never returns an empty result set and a LastEvaluatedKey . The LastEvaluatedKey is only provided if the results exceed 1 MB, or if you have used Limit .

You can query a table, a local secondary index, or a global secondary index. For a query on a table or on a local secondary index, you can set ConsistentRead to true and obtain a strongly consistent result. Global secondary indexes support eventually consistent reads only, so do not specify ConsistentRead when querying a global secondary index.

상속: AmazonDynamoDBv2Request
예제 #1
0
파일: Dynamo.cs 프로젝트: KyleGobel/Chronos
        /// <summary>
        /// Gets a single record from dynamodb returned as json
        /// </summary>
        /// <param name="tableName">The dynamodb table name</param>
        /// <param name="indexName">The index to use</param>
        /// <param name="keyName">The 'column' to equal compare against</param>
        /// <param name="keyValueAsString">The value to compare againt (as a string)</param>
        /// <returns>Single json object</returns>
        public string Get(string tableName, string indexName,string keyName, string keyValueAsString)
        {
            var request = new QueryRequest
            {
                TableName= tableName,
                KeyConditions = new Dictionary<string, Condition>
                {
                    {
                       keyName,
                       new Condition
                       {
                           ComparisonOperator = "EQ",
                           AttributeValueList = new List<AttributeValue>
                           {
                               new AttributeValue { S = keyValueAsString}
                           }
                       }
                    }
                },
                IndexName = indexName
            };

            var resp = _client.Query(request);
            var item = resp.Items.FirstOrDefault();
            if (item != null)
            {
                var dict = item.ToDictionary(x => x.Key, x => GetValueFromAttribute(x.Value));
                return _serializer.Serialize(dict);
            }
            return string.Empty;
        }
예제 #2
0
        public override int GetErrors(int pageIndex, int pageSize, IList errorEntryList)
        {
            CheckTableExists();

            if (pageIndex < 0)
            {
                throw new ArgumentOutOfRangeException("pageIndex", pageIndex, null);
            }

            if (pageSize < 0)
            {
                throw new ArgumentOutOfRangeException("pageSize", pageSize, null);
            }

            int max = pageSize * (pageIndex + 1);

            // http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LowLevelDotNetQuerying.html
            AmazonDynamoDBClient client = new AmazonDynamoDBClient();
            Dictionary <string, AttributeValue> lastKeyEvaluated = null;
            List <EL.ErrorLogEntry>             list             = new List <EL.ErrorLogEntry>(max);

            // there is a max of 1MB of data returned per read operation, so you have to do repeated reads until you reach the end
            do
            {
                Amazon.DynamoDBv2.Model.QueryRequest request = new Amazon.DynamoDBv2.Model.QueryRequest(s_TableName);
                request.KeyConditionExpression    = "Application = :v_Application";
                request.ExpressionAttributeValues = new Dictionary <string, AttributeValue> {
                    { ":v_Application", new AttributeValue(this.ApplicationName) }
                };
                request.IndexName        = "Application-TimeUtc-index";
                request.ScanIndexForward = false;
                request.Limit            = max;
                request.Select           = Select.ALL_PROJECTED_ATTRIBUTES;
                if (lastKeyEvaluated != null)
                {
                    request.ExclusiveStartKey = lastKeyEvaluated;
                }

                QueryResponse response = client.Query(request);
                foreach (Dictionary <string, AttributeValue> item in response.Items)
                {
                    string   errorXml = item["AllXml"].S;
                    string   errorId  = item["ErrorId"].S;
                    EL.Error error    = EL.ErrorXml.DecodeString(errorXml);
                    list.Add(new EL.ErrorLogEntry(this, errorId, error));
                }
                lastKeyEvaluated = response.LastEvaluatedKey;
            } while (lastKeyEvaluated != null && lastKeyEvaluated.Count > 0);

            int numToSkip = (pageIndex - 1) * pageSize;

            list = list.Skip(numToSkip).ToList();
            list.ForEach(err => errorEntryList.Add(err));
            return(errorEntryList.Count);
        }
예제 #3
0
        public Dictionary<string, object> GetPinWithPinID(string owner, double pinDate)
        {
            Dictionary<string, object> retval = new Dictionary<string, object>();
            QueryResponse response;
            var config = new AmazonDynamoDBConfig();
            config.ServiceURL = System.Configuration.ConfigurationManager.AppSettings["ServiceURL"];
            client = new AmazonDynamoDBClient(config);
            try
            {
                QueryRequest request = new QueryRequest()
                {
                    TableName = "Pin",
                    KeyConditions = new Dictionary<string, Condition>()
                    {
                        {
                            "Owner",
                            new Condition()
                            {
                                ComparisonOperator = ComparisonOperator.EQ,
                                AttributeValueList = new List<AttributeValue> { new AttributeValue { S = owner } }
                            }
                        },
                        {
                            "PinDate",
                            new Condition()
                            {
                                ComparisonOperator = ComparisonOperator.EQ,
                                AttributeValueList = new List<AttributeValue> { new AttributeValue { N = pinDate.ToString() } }
                            }
                        }
                    }

                };
                response = client.Query(request);
                retval.Add("Title", response.Items[0]["Title"].S);
                retval.Add("Owner", response.Items[0]["Owner"].S);
                retval.Add("OwnerName", response.Items[0]["UserName"].S);
                retval.Add("OwnerHeadshot", response.Items[0]["HeadshotURL"].S);
                retval.Add("Latitude", response.Items[0]["Latitude"].S);
                retval.Add("Longitude", response.Items[0]["Longitude"].S);
                retval.Add("PinDate", Convert.ToDouble(response.Items[0]["PinDate"].N));
                retval.Add("Images", response.Items[0]["Images"].SS);
            }
            catch (AmazonDynamoDBException e) { Console.WriteLine(e.Message); }
            catch (AmazonServiceException e) { Console.WriteLine(e.Message); }
            catch (Exception e) { Console.WriteLine(e.Message); }

            return retval;
        }
예제 #4
0
        internal static Amazon.DynamoDBv2.Model.QueryRequest CreateQueryRequest <T>(Innovt.Cloud.Table.QueryRequest request)
        {
            var queryRequest = new Amazon.DynamoDBv2.Model.QueryRequest()
            {
                IndexName                 = request.IndexName,
                TableName                 = GetTableName <T>(),
                ConsistentRead            = request.IndexName == null,
                FilterExpression          = request.FilterExpression,
                ScanIndexForward          = request.ScanIndexForward,
                KeyConditionExpression    = request.KeyConditionExpression,
                ProjectionExpression      = request.AttributesToGet,
                ExclusiveStartKey         = PaginationTokenToDictionary(request.Page),
                ExpressionAttributeValues = CreateExpressionAttributeValues(request.Filter, string.Join(',', request.KeyConditionExpression, request.FilterExpression))
            };

            if (request.PageSize.HasValue)
            {
                queryRequest.Limit = request.PageSize == 0 ? 1 : request.PageSize.Value;
            }

            return(queryRequest);
        }
        /// <summary>
        /// Initiates the asynchronous execution of the Query operation.
        /// <seealso cref="Amazon.DynamoDBv2.IAmazonDynamoDB"/>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the Query operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
        public Task<QueryResponse> QueryAsync(QueryRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new QueryRequestMarshaller();
            var unmarshaller = QueryResponseUnmarshaller.Instance;

            return InvokeAsync<QueryRequest,QueryResponse>(request, marshaller, 
                unmarshaller, cancellationToken);
        }
예제 #6
0
        private int GetCount()
        {
            if (IsDone && CollectResults)
            {
                return Matches.Count;
            }
            else
            {
                if (count != -1)
                {
                    return count;
                }
                else
                {
                    switch (SearchMethod)
                    {
                        case SearchType.Scan:
                            ScanRequest scanReq = new ScanRequest
                            {
                                TableName = TableName,
                                Select = EnumMapper.Convert(SelectValues.Count),
                                ExclusiveStartKey = NextKey,
                                ScanFilter = Filter.ToConditions(SourceTable.Conversion),
                            };
                            if (this.FilterExpression != null && this.FilterExpression.IsSet)
                            {
                                this.FilterExpression.ApplyExpression(scanReq, SourceTable.Conversion);
                            }
                            if (scanReq.ScanFilter != null && scanReq.ScanFilter.Count > 1)
                                scanReq.ConditionalOperator = EnumMapper.Convert(ConditionalOperator);

                            if (this.TotalSegments != 0)
                            {
                                scanReq.TotalSegments = this.TotalSegments;
                                scanReq.Segment = this.Segment;
                            }
                            scanReq.BeforeRequestEvent += SourceTable.UserAgentRequestEventHandlerSync;

                            ScanResult scanResult = SourceTable.DDBClient.Scan(scanReq);
                            count = Matches.Count + scanResult.Count;
                            return count;
                        case SearchType.Query:
                            QueryRequest queryReq = new QueryRequest
                            {
                                TableName = TableName,
                                ConsistentRead = IsConsistentRead,
                                Select = EnumMapper.Convert(SelectValues.Count),
                                ExclusiveStartKey = NextKey,
                                ScanIndexForward = !IsBackwardSearch,
                                IndexName = IndexName
                            };

                            if (this.FilterExpression != null && this.FilterExpression.IsSet)
                            {
                                this.FilterExpression.ApplyExpression(queryReq, SourceTable.Conversion);
                            }

                            Dictionary<string, Condition> keyConditions, filterConditions;
                            SplitQueryFilter(Filter, SourceTable, queryReq.IndexName, out keyConditions, out filterConditions);
                            queryReq.KeyConditions = keyConditions;
                            queryReq.QueryFilter = filterConditions;

                            if (queryReq.QueryFilter != null && queryReq.QueryFilter.Count > 1)
                                queryReq.ConditionalOperator = EnumMapper.Convert(ConditionalOperator);

                            queryReq.BeforeRequestEvent += SourceTable.UserAgentRequestEventHandlerSync;

                            QueryResult queryResult = SourceTable.DDBClient.Query(queryReq);
                            count = Matches.Count + queryResult.Count;
                            return count;
                        default:
                            throw new InvalidOperationException("Unknown Search Method");
                    }
                }
            }
        }
예제 #7
0
 /// <summary>
 /// Paginator for Query operation
 ///</summary>
 public IQueryPaginator Query(QueryRequest request)
 {
     return(new QueryPaginator(this.client, request));
 }
 /// <summary>
 /// Initiates the asynchronous execution of the Query operation.
 /// <seealso cref="Amazon.DynamoDBv2.AmazonDynamoDB.Query"/>
 /// </summary>
 /// 
 /// <param name="queryRequest">Container for the necessary parameters to execute the Query operation on AmazonDynamoDBv2.</param>
 /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
 /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 /// 
 /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndQuery
 ///         operation.</returns>
 public IAsyncResult BeginQuery(QueryRequest queryRequest, AsyncCallback callback, object state)
 {
     return invokeQuery(queryRequest, callback, state, false);
 }
        /// <summary>
        /// <para>A <i>Query</i> operation directly accesses items from a table using the table primary key, or from an index using the index key. You
        /// must provide a specific hash key value. You can narrow the scope of the query by using comparison operators on the range key value, or on
        /// the index key. You can use the <i>ScanIndexForward</i> parameter to get results in forward or reverse order, by range key or by index key.
        /// </para> <para>Queries that do not return results consume the minimum read capacity units according to the type of read.</para> <para>If the
        /// total number of items meeting the query criteria exceeds the result set size limit of 1 MB, the query stops and results are returned to the
        /// user with a <i>LastEvaluatedKey</i> to continue the query in a subsequent operation. Unlike a <i>Scan</i> operation, a <i>Query</i>
        /// operation never returns an empty result set <i>and</i> a
        /// <i>LastEvaluatedKey</i> . The <i>LastEvaluatedKey</i> is only provided if the results exceed 1 MB, or if you have used
        /// <i>Limit</i> . </para> <para>You can query a table, a local secondary index, or a global secondary index. For a query on a table or on a
        /// local secondary index, you can set <i>ConsistentRead</i> to true and obtain a strongly consistent result. Global secondary indexes support
        /// eventually consistent reads only, so do not specify <i>ConsistentRead</i> when querying a global secondary index.</para>
        /// </summary>
        /// 
        /// <param name="queryRequest">Container for the necessary parameters to execute the Query service method on AmazonDynamoDBv2.</param>
        /// 
        /// <returns>The response from the Query service method, as returned by AmazonDynamoDBv2.</returns>
        /// 
        /// <exception cref="T:Amazon.DynamoDBv2.Model.ResourceNotFoundException" />
        /// <exception cref="T:Amazon.DynamoDBv2.Model.ProvisionedThroughputExceededException" />
        /// <exception cref="T:Amazon.DynamoDBv2.Model.InternalServerErrorException" />
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
		public Task<QueryResponse> QueryAsync(QueryRequest queryRequest, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new QueryRequestMarshaller();
            var unmarshaller = QueryResponseUnmarshaller.GetInstance();
            return Invoke<IRequest, QueryRequest, QueryResponse>(queryRequest, marshaller, unmarshaller, signer, cancellationToken);
        }
예제 #10
0
 private void FindRepliesForAThread(string forumName, string threadSubject)
 {
     resultText.text = ("*** Executing FindRepliesForAThread() ***");
     string replyId = forumName + "#" + threadSubject;
     
     var request = new QueryRequest
     {
         TableName = "Reply",
         ReturnConsumedCapacity = "TOTAL",
         KeyConditions = new Dictionary<string, Condition>()
         {
             {
                 "Id",
                 new Condition
                 {
                     ComparisonOperator = "EQ",
                     AttributeValueList = new List<AttributeValue>()
                     {
                         new AttributeValue { S = replyId }
                     }
                 }
             }
         }
     };
     
     _client.QueryAsync(request,(result)=>{
         resultText.text = string.Format("No. of reads used (by query in FindRepliesForAThread) {0}\n",
                             result.Response.ConsumedCapacity.CapacityUnits);
         foreach (Dictionary<string, AttributeValue> item
                  in result.Response.Items)
         {
             PrintItem(item);
         }
     });
 }
예제 #11
0
 void FindRepliesHelper(QueryRequest request, Dictionary<string,AttributeValue> lastKeyEvaluated)
 {
     string forumName = "Amazon DynamoDB";
     string threadSubject = "DynamoDB Thread 1";
     string replyId = forumName + "#" + threadSubject;
     
     DateTime twoWeeksAgoDate = DateTime.UtcNow - TimeSpan.FromDays(15);
     string twoWeeksAgoString = twoWeeksAgoDate.ToString(AWSSDKUtils.ISO8601DateFormat);
     
     request.TableName = "Reply";
     
     request.KeyConditions = new Dictionary<string, Condition>()
     {
         { 
             "Id",  new Condition()
             { 
                 ComparisonOperator = "EQ",
                 AttributeValueList = new List<AttributeValue>()
                 {
                     new AttributeValue { S = replyId }
                 }
             }
         },
         { 
             "ReplyDateTime", new Condition()
             {
                 ComparisonOperator = "GT",
                 AttributeValueList = new List<AttributeValue>()
                 { 
                     new AttributeValue { S = twoWeeksAgoString }
                 }
             }
         }
     };
     
     // Optional parameter.
     request.ProjectionExpression = "Id, ReplyDateTime, PostedBy";
     
     // Optional parameter.
     request.ConsistentRead = true;
     request.Limit = 2; // The Reply table has only a few sample items. So the page size is smaller.
     request.ExclusiveStartKey = lastKeyEvaluated;
     request.ReturnConsumedCapacity = "TOTAL";
     
     _client.QueryAsync(request,(result)=>{
         resultText.text = string.Format("No. of reads used (by query in FindRepliesForAThreadSpecifyLimit) {0}\n",
                                          result.Response.ConsumedCapacity.CapacityUnits);
         
         foreach (var item in result.Response.Items)
         {
             PrintItem(item);
         }
         
         lastKeyEvaluated = result.Response.LastEvaluatedKey;
         if(lastKeyEvaluated !=null && lastKeyEvaluated.Count >0)
         {
             FindRepliesHelper(request,result.Response.LastEvaluatedKey);
         }
     });
 }
 /// <summary>
 /// Initiates the asynchronous execution of the Query operation.
 /// </summary>
 /// 
 /// <param name="request">Container for the necessary parameters to execute the Query operation on AmazonDynamoDBClient.</param>
 /// <param name="callback">An Action delegate that is invoked when the operation completes.</param>
 /// <param name="options">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
 ///          procedure using the AsyncState property.</param>
 public void QueryAsync(QueryRequest request, AmazonServiceCallback<QueryRequest, QueryResponse> callback, AsyncOptions options = null)
 {
     options = options == null?new AsyncOptions():options;
     var marshaller = new QueryRequestMarshaller();
     var unmarshaller = QueryResponseUnmarshaller.Instance;
     Action<AmazonWebServiceRequest, AmazonWebServiceResponse, Exception, AsyncOptions> callbackHelper = null;
     if(callback !=null )
         callbackHelper = (AmazonWebServiceRequest req, AmazonWebServiceResponse res, Exception ex, AsyncOptions ao) => { 
             AmazonServiceResult<QueryRequest,QueryResponse> responseObject 
                     = new AmazonServiceResult<QueryRequest,QueryResponse>((QueryRequest)req, (QueryResponse)res, ex , ao.State);    
                 callback(responseObject); 
         };
     BeginInvoke<QueryRequest>(request, marshaller, unmarshaller, options, callbackHelper);
 }
예제 #13
0
 internal void ApplyExpression(QueryRequest request, DynamoDBEntryConversion conversion)
 {
     request.FilterExpression = this.ExpressionStatement;
     request.ExpressionAttributeNames = new Dictionary<string, string>(this.ExpressionAttributeNames);
     request.ExpressionAttributeValues = this.ConvertToAttributeValues(conversion);
 }
예제 #14
0
        public virtual bool IsImageInDynamo(AmazonDynamoDBClient dynamoDbClient, string tableName, string key)
        {
            try
            {
                var queryRequest = new QueryRequest
                {
                    TableName = tableName,
                    KeyConditions = new Dictionary<string, Condition>
                    {
                        {
                            "Key",
                            new Condition
                            {
                                ComparisonOperator = "EQ",
                                AttributeValueList = new List<AttributeValue>
                                {
                                    new AttributeValue {S = key}
                                }
                            }
                        }
                    },
                    ConsistentRead = true,
                };

                QueryResponse queryResponse = dynamoDbClient.Query(queryRequest);
                return queryResponse.Count > 0;
            }
            catch (Exception ex)
            {
                _Default.LogMessageToPage("IsImageInDynamo Error: {0}", ex.Message);
                return false;
            }
        }
예제 #15
0
        private List<Document> GetNextSetHelper(bool isAsync)
        {
            List<Document> ret = new List<Document>();

            if (!IsDone)
            {
                switch (SearchMethod)
                {
                    case SearchType.Scan:
                        ScanRequest scanReq = new ScanRequest
                        {
                            ExclusiveStartKey = NextKey,
                            Limit = Limit,
                            TableName = TableName,
                            AttributesToGet = AttributesToGet,
                            ScanFilter = Filter,
                            Select = EnumToStringMapper.Convert(Select)
                        };

                        if (this.TotalSegments != 0)
                        {
                            scanReq.TotalSegments = this.TotalSegments;
                            scanReq.Segment = this.Segment;
                        }

                        scanReq.BeforeRequestEvent += isAsync ?
                            new RequestEventHandler(SourceTable.UserAgentRequestEventHandlerAsync) :
                            new RequestEventHandler(SourceTable.UserAgentRequestEventHandlerSync);

                        ScanResult scanResult = SourceTable.DDBClient.Scan(scanReq).ScanResult;
                        foreach (var item in scanResult.Items)
                        {
                            Document doc = Document.FromAttributeMap(item);
                            ret.Add(doc);
                            if (CollectResults)
                            {
                                Matches.Add(doc);
                            }
                        }
                        NextKey = scanResult.LastEvaluatedKey;
                        if (NextKey == null)
                        {
                            IsDone = true;
                        }
                        return ret;
                    case SearchType.Query:
                        QueryRequest queryReq = new QueryRequest
                        {
                            ConsistentRead = IsConsistentRead,
                            ExclusiveStartKey = NextKey,
                            Limit = Limit,
                            ScanIndexForward = !IsBackwardSearch,
                            TableName = TableName,
                            AttributesToGet = AttributesToGet,
                            KeyConditions = Filter,
                            IndexName = IndexName,
                            Select = EnumToStringMapper.Convert(Select)
                        };
                        queryReq.BeforeRequestEvent += isAsync ?
                            new RequestEventHandler(SourceTable.UserAgentRequestEventHandlerAsync) :
                            new RequestEventHandler(SourceTable.UserAgentRequestEventHandlerSync);

                        QueryResult queryResult = SourceTable.DDBClient.Query(queryReq).QueryResult;
                        foreach (var item in queryResult.Items)
                        {
                            Document doc = Document.FromAttributeMap(item);
                            ret.Add(doc);
                            if (CollectResults)
                            {
                                Matches.Add(doc);
                            }
                        }
                        NextKey = queryResult.LastEvaluatedKey;
                        if (NextKey == null)
                        {
                            IsDone = true;
                        }
                        return ret;
                    default:
                        throw new InvalidOperationException("Unknown Search Method");
                }
            }

            return ret;
        }
        public Dictionary<string, string> GameGetAll(string appId, string key)
        {
            var request = new QueryRequest
            {
                TableName = ConfigurationManager.AppSettings["TableName"],
                KeyConditions = new Dictionary<string, Condition>
                {
                    {
                        HashKey,
                        new Condition
                        {
                            ComparisonOperator = "EQ",
                            AttributeValueList = new List<AttributeValue>()
                            {
                                new AttributeValue {S = string.Format("{0}_{1}", appId, key)}
                            }
                        }
                    }
                }
            };

            var response = WebApiApplication.AmazonDynamoDBClient.Query(request);

            return response.Items.ToDictionary(item => item[RangeKey].S, item => item[ActorNr].N);
        }
예제 #17
0
        public void SearchSamples()
        {
            RemoveTables();
            CreateLSITable();
            TableUtils.WaitUntilTableActive("SampleTable", TestClient);

            {
                // Create items to put into first table
                Dictionary<string, AttributeValue> item1 = new Dictionary<string, AttributeValue>();
                item1["Author"] = new AttributeValue { S = "Mark Twain" };
                item1["Title"] = new AttributeValue { S = "A Connecticut Yankee in King Arthur's Court" };
                item1["Pages"] = new AttributeValue { N = "575" };
                Dictionary<string, AttributeValue> item2 = new Dictionary<string, AttributeValue>();
                item2["Author"] = new AttributeValue { S = "Booker Taliaferro Washington" };
                item2["Title"] = new AttributeValue { S = "My Larger Education" };
                item2["Pages"] = new AttributeValue { N = "313" };
                item2["Year"] = new AttributeValue { N = "1911" };

                // Construct write-request for first table
                List<WriteRequest> sampleTableItems = new List<WriteRequest>();
                sampleTableItems.Add(new WriteRequest
                {
                    PutRequest = new PutRequest { Item = item1 }
                });
                sampleTableItems.Add(new WriteRequest
                {
                    PutRequest = new PutRequest { Item = item2 }
                });
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();
                client.BatchWriteItem(new BatchWriteItemRequest
                {
                    RequestItems = new Dictionary<string, List<WriteRequest>>
                    {
                        { "SampleTable", sampleTableItems }
                    }
                });

                PutSample();
            }


            {
                #region Query Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Define item hash-key to be string value "Mark Twain"
                AttributeValue hashKey = new AttributeValue { S = "Mark Twain" };

                // Define query condition to search for range-keys that begin with the string "The Adventures"
                Condition condition = new Condition
                {
                    ComparisonOperator = "BEGINS_WITH",
                    AttributeValueList = new List<AttributeValue>
                    {
                        new AttributeValue { S = "The Adventures" }
                    }
                };

                // Create the key conditions from hashKey and condition
                Dictionary<string, Condition> keyConditions = new Dictionary<string, Condition>
                {
                    // Hash key condition. ComparisonOperator must be "EQ".
                    { 
                        "Author",
                        new Condition
                        {
                            ComparisonOperator = "EQ",
                            AttributeValueList = new List<AttributeValue> { hashKey }
                        }
                    },
                    // Range key condition
                    {
                        "Title",
                        condition
                    }
                };

                // Define marker variable
                Dictionary<string, AttributeValue> startKey = null;

                do
                {
                    // Create Query request
                    QueryRequest request = new QueryRequest
                    {
                        TableName = "SampleTable",
                        ExclusiveStartKey = startKey,
                        KeyConditions = keyConditions
                    };

                    // Issue request
                    var result = client.Query(request);

                    // View all returned items
                    List<Dictionary<string, AttributeValue>> items = result.Items;
                    foreach (Dictionary<string, AttributeValue> item in items)
                    {
                        Console.WriteLine("Item:");
                        foreach (var keyValuePair in item)
                        {
                            Console.WriteLine("{0} : S={1}, N={2}, SS=[{3}], NS=[{4}]",
                                keyValuePair.Key,
                                keyValuePair.Value.S,
                                keyValuePair.Value.N,
                                string.Join(", ", keyValuePair.Value.SS ?? new List<string>()),
                                string.Join(", ", keyValuePair.Value.NS ?? new List<string>()));
                        }
                    }

                    // Set marker variable
                    startKey = result.LastEvaluatedKey;
                } while (startKey != null && startKey.Count > 0);

                #endregion
            }

            {
                #region Query Local Secondary Index Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Define item hash-key to be string value "Mark Twain"
                AttributeValue hashKey = new AttributeValue { S = "Mark Twain" };

                // Define query condition to search for range-keys ("Year", in "YearsIndex") that are less than 1900
                Condition condition = new Condition
                {
                    ComparisonOperator = "LT",
                    AttributeValueList = new List<AttributeValue>
                    {
                        new AttributeValue { N = "1900" }
                    }
                };

                // Create the key conditions from hashKey and condition
                Dictionary<string, Condition> keyConditions = new Dictionary<string, Condition>
                {
                    // Hash key condition. ComparisonOperator must be "EQ".
                    { 
                        "Author",
                        new Condition
                        {
                            ComparisonOperator = "EQ",
                            AttributeValueList = new List<AttributeValue> { hashKey }
                        }
                    },
                    // Range key condition
                    {
                        "Year", // Reference the correct range key when using indexes
                        condition
                    }
                };

                // Define marker variable
                Dictionary<string, AttributeValue> startKey = null;

                do
                {
                    // Create Query request
                    QueryRequest request = new QueryRequest
                    {
                        TableName = "SampleTable",
                        ExclusiveStartKey = startKey,
                        KeyConditions = keyConditions,
                        IndexName = "YearsIndex" // Specify the index to query against
                    };

                    // Issue request
                    var result = client.Query(request);

                    // View all returned items
                    List<Dictionary<string, AttributeValue>> items = result.Items;
                    foreach (Dictionary<string, AttributeValue> item in items)
                    {
                        Console.WriteLine("Item:");
                        foreach (var keyValuePair in item)
                        {
                            Console.WriteLine("{0} : S={1}, N={2}, SS=[{3}], NS=[{4}]",
                                keyValuePair.Key,
                                keyValuePair.Value.S,
                                keyValuePair.Value.N,
                                string.Join(", ", keyValuePair.Value.SS ?? new List<string>()),
                                string.Join(", ", keyValuePair.Value.NS ?? new List<string>()));
                        }
                    }

                    // Set marker variable
                    startKey = result.LastEvaluatedKey;
                } while (startKey != null && startKey.Count > 0);

                #endregion
            }

            {
                #region Scan Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Define scan conditions
                Dictionary<string, Condition> conditions = new Dictionary<string, Condition>();

                // Title attribute should contain the string "Adventures"
                Condition titleCondition = new Condition();
                titleCondition.ComparisonOperator = ComparisonOperator.CONTAINS;
                titleCondition.AttributeValueList.Add(new AttributeValue { S = "Adventures" });
                conditions["Title"] = titleCondition;

                // Pages attributes must be greater-than the numeric value "200"
                Condition pagesCondition = new Condition();
                pagesCondition.ComparisonOperator = ComparisonOperator.GT;;
                pagesCondition.AttributeValueList.Add(new AttributeValue { N = "200" });
                conditions["Pages"] = pagesCondition;


                // Define marker variable
                Dictionary<string, AttributeValue> startKey = null;

                do
                {
                    // Create Scan request
                    ScanRequest request = new ScanRequest
                    {
                        TableName = "SampleTable",
                        ExclusiveStartKey = startKey,
                        ScanFilter = conditions
                    };

                    // Issue request
                    ScanResult result = client.Scan(request);

                    // View all returned items
                    List<Dictionary<string, AttributeValue>> items = result.Items;
                    foreach (Dictionary<string, AttributeValue> item in items)
                    {
                        Console.WriteLine("Item:");
                        foreach (var keyValuePair in item)
                        {
                            Console.WriteLine("{0} : S={1}, N={2}, SS=[{3}], NS=[{4}]",
                                keyValuePair.Key,
                                keyValuePair.Value.S,
                                keyValuePair.Value.N,
                                string.Join(", ", keyValuePair.Value.SS ?? new List<string>()),
                                string.Join(", ", keyValuePair.Value.NS ?? new List<string>()));
                        }
                    }

                    // Set marker variable
                    startKey = result.LastEvaluatedKey;
                } while (startKey != null && startKey.Count > 0);

                #endregion
            }

            {
                // Create lots of items to put into first table
                var table = Amazon.DynamoDBv2.DocumentModel.Table.LoadTable(TestClient, "SampleTable");
                var batchWrite = table.CreateBatchWrite();
                for (int i = 0; i < 100; i++)
                {
                    var document = new Amazon.DynamoDBv2.DocumentModel.Document();
                    document["Author"] = "FakeAuthor" + i;
                    document["Title"] = "Book" + i;
                    document["Pages"] = (180 + i);
                    document["Year"] = 1900 + i;
                    batchWrite.AddDocumentToPut(document);
                }
                batchWrite.Execute();
            }


            {
                #region Parallel Scan Sample

                // Create a client
                AmazonDynamoDBClient client = new AmazonDynamoDBClient();

                // Define scan conditions
                Dictionary<string, Condition> conditions = new Dictionary<string, Condition>();

                // Pages attributes must be greater-than the numeric value "200"
                Condition pagesCondition = new Condition();
                pagesCondition.ComparisonOperator = ComparisonOperator.GT;
                pagesCondition.AttributeValueList.Add(new AttributeValue { N = "200" });
                conditions["Pages"] = pagesCondition;

                // Setup 10 simultaneous threads, each thread calling Scan operation
                // with its own segment value.
                int totalSegments = 10;
                Parallel.For(0, totalSegments, segment =>
                {
                    // Define marker variable
                    Dictionary<string, AttributeValue> startKey = null;

                    do
                    {
                        // Create Scan request
                        ScanRequest request = new ScanRequest
                        {
                            TableName = "SampleTable",
                            ExclusiveStartKey = startKey,
                            ScanFilter = conditions,
                            // Total segments to split the table into
                            TotalSegments = totalSegments,
                            // Current segment to scan
                            Segment = segment
                        };

                        // Issue request
                        var result = client.Scan(request);

                        // Write returned items to file
                        string path = string.Format("ParallelScan-{0}-of-{1}.txt", totalSegments, segment);
                        List<Dictionary<string, AttributeValue>> items = result.Items;
                        using (Stream stream = File.OpenWrite(path))
                        using (StreamWriter writer = new StreamWriter(stream))
                        {
                            foreach (Dictionary<string, AttributeValue> item in items)
                            {
                                writer.WriteLine("Item:");
                                foreach (var keyValuePair in item)
                                {
                                    writer.WriteLine("{0} : S={1}, N={2}, SS=[{3}], NS=[{4}]",
                                        keyValuePair.Key,
                                        keyValuePair.Value.S,
                                        keyValuePair.Value.N,
                                        string.Join(", ", keyValuePair.Value.SS ?? new List<string>()),
                                        string.Join(", ", keyValuePair.Value.NS ?? new List<string>()));
                                }
                            }
                        }

                        // Set marker variable
                        startKey = result.LastEvaluatedKey;
                    } while (startKey != null && startKey.Count > 0);
                });

                #endregion
            }

        }
예제 #18
0
 private void FindRepliesForAThreadSpecifyOptionalLimitHelper(Dictionary<string, AttributeValue> lastKeyEvaluated)
 {
     string forumName = "Amazon DynamoDB";
     string threadSubject = "DynamoDB Thread 1";
     string replyId = forumName + "#" + threadSubject;
     
     resultText.text = ("*** Executing FindRepliesForAThreadSpecifyOptionalLimit() ***");
     
     var request = new QueryRequest
     {
         TableName = "Reply",
         ReturnConsumedCapacity = "TOTAL",
         KeyConditions = new Dictionary<string, Condition>()
         {
             {
                 "Id",
                 new Condition
                 {
                     ComparisonOperator = "EQ",
                     AttributeValueList = new List<AttributeValue>()
                     {
                         new AttributeValue { S = replyId }
                     }
                 }
             }
         },
         Limit = 2, // The Reply table has only a few sample items. So the page size is smaller.
         ExclusiveStartKey = lastKeyEvaluated
     };
     
     _client.QueryAsync(request,(result)=>
     {
         resultText.text += string.Format("No. of reads used (by query in FindRepliesForAThreadSpecifyLimit) {0}\n",
                             result.Response.ConsumedCapacity.CapacityUnits);
         foreach (Dictionary<string, AttributeValue> item
                  in result.Response.Items)
         {
                 PrintItem(item);
         }
         lastKeyEvaluated = result.Response.LastEvaluatedKey;
         if(lastKeyEvaluated != null && lastKeyEvaluated.Count != 0)
         {
             FindRepliesForAThreadSpecifyOptionalLimitHelper(lastKeyEvaluated);
         }
     });
 }
예제 #19
0
        public override int GetErrors(int pageIndex, int pageSize, IList errorEntryList)
        {
            CheckTableExists();

            if (pageIndex < 0)
                throw new ArgumentOutOfRangeException("pageIndex", pageIndex, null);

            if (pageSize < 0)
                throw new ArgumentOutOfRangeException("pageSize", pageSize, null);

            int max = pageSize * (pageIndex + 1);

            // http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/LowLevelDotNetQuerying.html
            AmazonDynamoDBClient client = new AmazonDynamoDBClient();
            Dictionary<string, AttributeValue> lastKeyEvaluated = null;
            List<EL.ErrorLogEntry> list = new List<EL.ErrorLogEntry>(max);
            // there is a max of 1MB of data returned per read operation, so you have to do repeated reads until you reach the end
            do
            {
                Amazon.DynamoDBv2.Model.QueryRequest request = new Amazon.DynamoDBv2.Model.QueryRequest(s_TableName);
                request.KeyConditionExpression = "Application = :v_Application";
                request.ExpressionAttributeValues = new Dictionary<string, AttributeValue> { { ":v_Application", new AttributeValue(this.ApplicationName) } };
                request.IndexName = "Application-TimeUtc-index";
                request.ScanIndexForward = false;
                request.Limit = max;
                request.Select = Select.ALL_PROJECTED_ATTRIBUTES;
                if (lastKeyEvaluated != null)
                    request.ExclusiveStartKey = lastKeyEvaluated;

                QueryResponse response = client.Query(request);
                foreach (Dictionary<string, AttributeValue> item in response.Items)
                {
                    string errorXml = item["AllXml"].S;
                    string errorId = item["ErrorId"].S;
                    EL.Error error = EL.ErrorXml.DecodeString(errorXml);
                    list.Add(new EL.ErrorLogEntry(this, errorId, error));
                }
                lastKeyEvaluated = response.LastEvaluatedKey;
            } while (lastKeyEvaluated != null && lastKeyEvaluated.Count > 0);

            int numToSkip = (pageIndex - 1) * pageSize;
            list = list.Skip(numToSkip).ToList();
            list.ForEach(err => errorEntryList.Add(err));
            return errorEntryList.Count;
        }
		internal QueryResponse Query(QueryRequest request)
        {
            var task = QueryAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                ExceptionDispatchInfo.Capture(e.InnerException).Throw();
                return null;
            }
        }
예제 #21
0
        /// <summary>
        /// Initiates the asynchronous execution of the Query operation.
        /// <seealso cref="Amazon.DynamoDBv2.IAmazonDynamoDB.Query"/>
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the Query operation.</param>
        /// <param name="cancellationToken">
        ///     A cancellation token that can be used by other objects or threads to receive notice of cancellation.
        /// </param>
        /// <returns>The task object representing the asynchronous operation.</returns>
		public async Task<QueryResponse> QueryAsync(QueryRequest request, CancellationToken cancellationToken = default(CancellationToken))
        {
            var marshaller = new QueryRequestMarshaller();
            var unmarshaller = QueryResponseUnmarshaller.GetInstance();
            var response = await Invoke<IRequest, QueryRequest, QueryResponse>(request, marshaller, unmarshaller, signer, cancellationToken)
                .ConfigureAwait(continueOnCapturedContext: false);
            return response;
        }
 IAsyncResult invokeQuery(QueryRequest queryRequest, AsyncCallback callback, object state, bool synchronized)
 {
     IRequest irequest = new QueryRequestMarshaller().Marshall(queryRequest);
     var unmarshaller = QueryResponseUnmarshaller.GetInstance();
     AsyncResult result = new AsyncResult(irequest, callback, state, synchronized, signer, unmarshaller);
     Invoke(result);
     return result;
 }
예제 #23
0
        public List<Dictionary<string, object>> GetPinWithUserID(string userID, double since, int takeCnt)
        {
            List<Dictionary<string, object>> retval = new List<Dictionary<string, object>>();
            Dictionary<string, object> tmpObject = null;
            QueryResponse response = null;
            var config = new AmazonDynamoDBConfig();
            config.ServiceURL = System.Configuration.ConfigurationManager.AppSettings["ServiceURL"];
            client = new AmazonDynamoDBClient(config);
            try
            {
                QueryRequest query = new QueryRequest()
                {
                    TableName = "Pin",
                    KeyConditions = new Dictionary<string, Condition>()
                    {
                        {
                            "Owner",
                            new Condition()
                            {
                                ComparisonOperator = ComparisonOperator.EQ,
                                AttributeValueList = new List<AttributeValue> { new AttributeValue { S = userID } }
                            }
                        },
                        {
                            "PinDate",
                            new Condition()
                            {
                                ComparisonOperator = ComparisonOperator.LT,
                                AttributeValueList = new List<AttributeValue> { new AttributeValue { N = since.ToString() } }
                            }
                        }
                    },
                    Limit = takeCnt,
                    ScanIndexForward = false

                };

                response = client.Query(query);
                foreach (var item in response.Items)
                {
                    tmpObject = new Dictionary<string, object>();
                    tmpObject.Add("Title", item["Title"].S);
                    tmpObject.Add("Owner", item["Owner"].S);
                    tmpObject.Add("OwnerName", item["UserName"].S);
                    tmpObject.Add("OwnerHeadshot", item["HeadshotURL"].S);
                    tmpObject.Add("Latitude", item["Latitude"].S);
                    tmpObject.Add("Longitude", item["Longitude"].S);
                    tmpObject.Add("PinDate", Convert.ToDouble(item["PinDate"].N));
                    tmpObject.Add("Images", item["Images"].SS);
                    retval.Add(tmpObject);
                }
            }
            catch (AmazonDynamoDBException e) { Console.WriteLine(e.Message); }
            catch (AmazonServiceException e) { Console.WriteLine(e.Message); }
            catch (Exception e) { Console.WriteLine(e.Message); }

            return retval;
        }
 /// <summary>
 /// <para>A <i>Query</i> operation directly accesses items from a table using the table primary key, or from an index using the index key. You
 /// must provide a specific hash key value. You can narrow the scope of the query by using comparison operators on the range key value, or on
 /// the index key. You can use the <i>ScanIndexForward</i> parameter to get results in forward or reverse order, by range key or by index key.
 /// </para> <para>Queries that do not return results consume the minimum read capacity units according to the type of read.</para> <para>If the
 /// total number of items meeting the query criteria exceeds the result set size limit of 1 MB, the query stops and results are returned to the
 /// user with a <i>LastEvaluatedKey</i> to continue the query in a subsequent operation. Unlike a <i>Scan</i> operation, a <i>Query</i>
 /// operation never returns an empty result set <i>and</i> a
 /// <i>LastEvaluatedKey</i> . The <i>LastEvaluatedKey</i> is only provided if the results exceed 1 MB, or if you have used
 /// <i>Limit</i> . </para> <para>To request a strongly consistent result, set <i>ConsistentRead</i> to true.</para>
 /// </summary>
 /// 
 /// <param name="queryRequest">Container for the necessary parameters to execute the Query service method on AmazonDynamoDBv2.</param>
 /// 
 /// <returns>The response from the Query service method, as returned by AmazonDynamoDBv2.</returns>
 /// 
 /// <exception cref="ResourceNotFoundException"/>
 /// <exception cref="ProvisionedThroughputExceededException"/>
 /// <exception cref="InternalServerErrorException"/>
 public QueryResponse Query(QueryRequest queryRequest)
 {
     IAsyncResult asyncResult = invokeQuery(queryRequest, null, null, true);
     return EndQuery(asyncResult);
 }
예제 #25
0
		internal QueryResponse Query(QueryRequest request)
        {
            var task = QueryAsync(request);
            try
            {
                return task.Result;
            }
            catch(AggregateException e)
            {
                throw e.InnerException;
            }
        }
예제 #26
0
        internal List<Document> GetNextSetHelper(bool isAsync)
        {
            List<Document> ret = new List<Document>();

            if (!IsDone)
            {
                switch (SearchMethod)
                {
                    case SearchType.Scan:
                        ScanRequest scanReq = new ScanRequest
                        {
                            ExclusiveStartKey = NextKey,
                            Limit = Limit,
                            TableName = TableName,
                            AttributesToGet = AttributesToGet,
                            ScanFilter = Filter.ToConditions(SourceTable.Conversion),
                            Select = EnumMapper.Convert(Select),
                        };
                        if (this.FilterExpression != null && this.FilterExpression.IsSet)
                            this.FilterExpression.ApplyExpression(scanReq, SourceTable.Conversion);
                        if (scanReq.ScanFilter != null && scanReq.ScanFilter.Count > 1)
                            scanReq.ConditionalOperator = EnumMapper.Convert(ConditionalOperator);
                        Common.ConvertAttributesToGetToProjectionExpression(scanReq);

                        if (this.TotalSegments != 0)
                        {
                            scanReq.TotalSegments = this.TotalSegments;
                            scanReq.Segment = this.Segment;
                        }

                        scanReq.BeforeRequestEvent += isAsync ?
                            new RequestEventHandler(SourceTable.UserAgentRequestEventHandlerAsync) :
                            new RequestEventHandler(SourceTable.UserAgentRequestEventHandlerSync);

                        ScanResult scanResult = SourceTable.DDBClient.Scan(scanReq);
                        foreach (var item in scanResult.Items)
                        {
                            Document doc = Document.FromAttributeMap(item);
                            ret.Add(doc);
                            if (CollectResults)
                            {
                            Matches.Add(doc);
                        }
                        }
                        NextKey = scanResult.LastEvaluatedKey;
                        if (NextKey == null || NextKey.Count == 0)
                        {
                            IsDone = true;
                        }
                        return ret;
                    case SearchType.Query:
                        QueryRequest queryReq = new QueryRequest
                        {
                            TableName = TableName,
                            ConsistentRead = IsConsistentRead,
                            Select = EnumMapper.Convert(Select),
                            ExclusiveStartKey = NextKey,
                            Limit = Limit,
                            ScanIndexForward = !IsBackwardSearch,
                            AttributesToGet = AttributesToGet,
                            IndexName = IndexName,
                        };

                        if (this.FilterExpression != null && this.FilterExpression.IsSet)
                        {
                            this.FilterExpression.ApplyExpression(queryReq, SourceTable.Conversion);
                        }

                        Dictionary<string, Condition> keyConditions, filterConditions;
                        SplitQueryFilter(Filter, SourceTable, queryReq.IndexName, out keyConditions, out filterConditions);
                        queryReq.KeyConditions = keyConditions;
                        queryReq.QueryFilter = filterConditions;
                        Common.ConvertAttributesToGetToProjectionExpression(queryReq);

                        if (queryReq.QueryFilter != null && queryReq.QueryFilter.Count > 1)
                            queryReq.ConditionalOperator = EnumMapper.Convert(ConditionalOperator);

                        queryReq.BeforeRequestEvent += isAsync ?
                            new RequestEventHandler(SourceTable.UserAgentRequestEventHandlerAsync) :
                            new RequestEventHandler(SourceTable.UserAgentRequestEventHandlerSync);

                        QueryResult queryResult = SourceTable.DDBClient.Query(queryReq);
                        foreach (var item in queryResult.Items)
                        {
                            Document doc = Document.FromAttributeMap(item);
                            ret.Add(doc);
                            if (CollectResults)
                            {
                                Matches.Add(doc);
                            }
                        }
                        NextKey = queryResult.LastEvaluatedKey;
                        if (NextKey == null || NextKey.Count == 0)
                        {
                            IsDone = true;
                        }
                        return ret;
                    default:
                        throw new InvalidOperationException("Unknown Search Method");
                }
            }

            return ret;
        }
예제 #27
0
        internal static void ApplyExpression(QueryRequest request, DynamoDBEntryConversion conversion,
            Expression keyExpression, Expression filterExpression)
        {
            if (keyExpression == null)
                keyExpression = new Expression();
            if (filterExpression == null)
                filterExpression = new Expression();

            if (!keyExpression.IsSet && !filterExpression.IsSet)
                return;

            if (keyExpression.IsSet)
                request.KeyConditionExpression = keyExpression.ExpressionStatement;
            if (filterExpression.IsSet)
                request.FilterExpression = filterExpression.ExpressionStatement;

            var kean = keyExpression.ExpressionAttributeNames;
            var fean = filterExpression.ExpressionAttributeNames;
            var combinedEan = Common.Combine(kean, fean, StringComparer.Ordinal);
            request.ExpressionAttributeNames = combinedEan;

            var keav = new Document(keyExpression.ExpressionAttributeValues).ForceConversion(conversion);
            var feav = new Document(filterExpression.ExpressionAttributeValues).ForceConversion(conversion);
            var combinedEav = Common.Combine(keav, feav, null);
            request.ExpressionAttributeValues = ConvertToAttributeValues(combinedEav, conversion);
        }
        internal QueryResponse Query(QueryRequest request)
        {
            var marshaller = new QueryRequestMarshaller();
            var unmarshaller = QueryResponseUnmarshaller.Instance;

            return Invoke<QueryRequest,QueryResponse>(request, marshaller, unmarshaller);
        }
예제 #29
0
        public async Task<Result<List<ActivityClaim>>> ValidateCredentialsAsync(Credentials credentials)
        {
            var result = new Result<List<ActivityClaim>>();
            var queryRequest = new QueryRequest
            {
                TableName = DatabaseTableName,
                IndexName = UsernameIndexName,
                KeyConditionExpression = "#username = :v_Username",
                ExpressionAttributeNames = new Dictionary<string, string>
                {
                    { "#username", DatabaseFields.USERNAME }
                },
                ExpressionAttributeValues = new Dictionary<string, AttributeValue> {
                    {":v_Username", new AttributeValue { S =  credentials.Username }}
                }
            };

            var response = await Client.QueryAsync(queryRequest);
            var user = response.Items.Where(u => u.Keys.Contains(DatabaseFields.OBJECT_TYPE) && u[DatabaseFields.OBJECT_TYPE].S.Equals(DatabaseObjectType.USER))
                                     .FirstOrDefault();
            if (user != null && HashHelper.ValidateHashedValue(user[DatabaseFields.PASSWORD].S, credentials.Password))
            {
                result.ResultCode = ResultCode.Ok;
                ActivityClaim claim;
                result.Data = user[DatabaseFields.USER_CLAIMS].SS.Select(c => Enum.TryParse(c, out claim) ? claim : ActivityClaim.None).Where(c => c != ActivityClaim.None).ToList();
            }
            return result;
        }
예제 #30
0
        private int GetCount()
        {
            if (IsDone && CollectResults)
            {
                return Matches.Count;
            }
            else
            {
                if (count != -1)
                {
                    return count;
                }
                else
                {
                    switch (SearchMethod)
                    {
                        case SearchType.Scan:
                            ScanRequest scanReq = new ScanRequest
                            {
                                TableName = TableName,
                                Select = EnumToStringMapper.Convert(SelectValues.Count),
                                ExclusiveStartKey = NextKey,
                                ScanFilter = Filter,
                            };

                            if (this.TotalSegments != 0)
                            {
                                scanReq.TotalSegments = this.TotalSegments;
                                scanReq.Segment = this.Segment;
                            }
                            scanReq.BeforeRequestEvent += SourceTable.UserAgentRequestEventHandlerSync;

                            ScanResult scanResult = SourceTable.DDBClient.Scan(scanReq).ScanResult;
                            count = Matches.Count + scanResult.Count;
                            return count;
                        case SearchType.Query:
                            QueryRequest queryReq = new QueryRequest
                            {
                                TableName = TableName,
                                ConsistentRead = IsConsistentRead,
                                Select = EnumToStringMapper.Convert(SelectValues.Count),
                                ExclusiveStartKey = NextKey,
                                ScanIndexForward = !IsBackwardSearch,
                                KeyConditions = Filter,
                                IndexName = IndexName
                            };
                            queryReq.BeforeRequestEvent += SourceTable.UserAgentRequestEventHandlerSync;

                            QueryResult queryResult = SourceTable.DDBClient.Query(queryReq).QueryResult;
                            count = Matches.Count + queryResult.Count;
                            return count;
                        default:
                            throw new InvalidOperationException("Unknown Search Method");
                    }
                }
            }
        }
        /// <summary>
        /// Initiates the asynchronous execution of the Query operation.
        /// </summary>
        /// 
        /// <param name="request">Container for the necessary parameters to execute the Query operation on AmazonDynamoDBClient.</param>
        /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param>
        /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback
        ///          procedure using the AsyncState property.</param>
        /// 
        /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndQuery
        ///         operation.</returns>
        public IAsyncResult BeginQuery(QueryRequest request, AsyncCallback callback, object state)
        {
            var marshaller = new QueryRequestMarshaller();
            var unmarshaller = QueryResponseUnmarshaller.Instance;

            return BeginInvoke<QueryRequest>(request, marshaller, unmarshaller,
                callback, state);
        }
예제 #32
0
 internal QueryPaginator(IAmazonDynamoDB client, QueryRequest request)
 {
     this._client  = client;
     this._request = request;
 }
예제 #33
0
        public virtual QueryResponse LookupByHashKey(AmazonDynamoDBClient ddbClient, string tableName, string company)
        {
            // Build request

            var queryRequest = new QueryRequest
            {
                TableName = tableName,
                KeyConditions = new Dictionary<string, Condition>
                {
                    {
                        "Company",
                        new Condition
                        {
                            ComparisonOperator = "EQ",
                            AttributeValueList = new List<AttributeValue>
                            {
                                new AttributeValue {S = company}
                            }
                        }
                    }
                },
                ConsistentRead = true,
            };

            // Submit request and return the response
            return ddbClient.Query(queryRequest);
        }