/// <summary> /// This method will use whatever information is supplied to scan the table /// supported fields are: /// CustomerId /// UserName /// Password(Hash) /// EmailAddress /// </summary> /// <param name="searchCriteria"></param> /// <returns></returns> public IEnumerable <UserInfo> Search(UserInfo searchCriteria) { AmazonDynamoDBClient client = DynamoUtilities.InitializeClient(); using (client) { ScanRequest request = CreateScanRequest(searchCriteria); if (request.ScanFilter.Count == 0) { throw new InvalidOperationException(ErrorMessages.NoSearchCriteria); } List <UserInfo> returnValue = new List <UserInfo>(); try { ScanResponse response = client.Scan(request); if (response.Items == null) { string errorMessage = string.Format(ErrorMessages.MisingResponseItem, "Search User"); throw new MissingFieldException(errorMessage); } foreach (Dictionary <string, AttributeValue> item in response.Items) { UserInfo user = DynamoUtilities.GetItemFromAttributeStore <UserInfo>(item); returnValue.Add(user); } } catch (AmazonDynamoDBException ex) { //expected exception, 404 } return(returnValue); } throw new NotImplementedException(); }
public List <Vendor> GetByPaymentFrequency(RecurringInvoices.Frequency paymentFrequency) { if (paymentFrequency != RecurringInvoices.Frequency.Weekly && paymentFrequency != RecurringInvoices.Frequency.Monthly) { throw new Exception($"Unknown payment frequency {paymentFrequency}"); } var scanRequest = new ScanRequest(new Vendor().GetTable()) { ExpressionAttributeValues = new Dictionary <string, AttributeValue> { { ":paymentFrequency", new AttributeValue { S = paymentFrequency == RecurringInvoices.Frequency.Weekly ? "weekly" : "monthly" } } }, ExpressionAttributeNames = new Dictionary <string, string> { { "#paymentFrequency", "paymentFrequency" } }, FilterExpression = "#paymentFrequency = :paymentFrequency" }; ScanResponse scanResponse = null; var items = new List <Vendor>(); do { if (scanResponse != null) { scanRequest.ExclusiveStartKey = scanResponse.LastEvaluatedKey; } scanResponse = DbClient.ScanAsync(scanRequest).Result; foreach (var item in scanResponse.Items) { items.Add(JsonConvert.DeserializeObject <Vendor>(Document.FromAttributeMap(item).ToJson())); } } while (scanResponse.LastEvaluatedKey.Any()); return(items); }
public void Get_all_items_with_AWSSDK() { db.PutItem(new Todo { Id = 1, Content = "TODO 1", Order = 1 }); var request = new ScanRequest { TableName = "Todo", Limit = 1000, }; var allTodos = new List <Todo>(); ScanResponse response = null; do { if (response != null) { request.ExclusiveStartKey = response.LastEvaluatedKey; } response = awsDb.Scan(request); foreach (var item in response.Items) { var todo = new Todo { Id = Convert.ToInt64(item["Id"].N), Content = item["Content"].S, Order = Convert.ToInt32(item["Order"].N), Done = item["Done"].BOOL, }; allTodos.Add(todo); } } while (response.LastEvaluatedKey != null && response.LastEvaluatedKey.Count > 0); allTodos.PrintDump(); }
public void Run(APIGatewayProxyRequest request, APIGatewayProxyResponse response) { var items = new List <ArtistModel>(); var client = new AmazonDynamoDBClient(); var scanRequest = new ScanRequest(new ArtistModel().GetTable()); ScanResponse queryResponse = null; do { if (queryResponse != null) { scanRequest.ExclusiveStartKey = queryResponse.LastEvaluatedKey; } queryResponse = client.ScanAsync(scanRequest).Result; foreach (var item in queryResponse.Items) { var model = JsonConvert.DeserializeObject <ArtistModel>(Document.FromAttributeMap(item).ToJson()); items.Add(model); } } while (queryResponse.LastEvaluatedKey.Any()); items = items.OrderBy(x => x.Artist).ToList(); response.Body = JsonConvert.SerializeObject(items); }
internal static void Cleanup() { Logging.LogDebug("Cleaning connections"); AmazonDynamoDBClient client = new AmazonDynamoDBClient(); DateTime threshold = DateTime.UtcNow.AddHours(-12); ScanRequest request = new ScanRequest { TableName = "connections", FilterExpression = "joinTime < :ts", ExpressionAttributeValues = new Dictionary <string, AttributeValue> { { ":ts", new AttributeValue { N = threshold.Ticks.ToString() } } }, ProjectionExpression = "room, connectionId", }; ScanResponse response = client.ScanAsync(request).Result; foreach (Dictionary <string, AttributeValue> item in response.Items) { Delete("", item["room"].S, item["connectionId"].S); } }
public List <T> ScanAll(ScanRequest scanRequest, int limit = 0) { ScanResponse scanResponse = null; var items = new List <T>(); do { if (scanResponse != null) { scanRequest.ExclusiveStartKey = scanResponse.LastEvaluatedKey; } scanResponse = Client.ScanAsync(scanRequest).Result; foreach (var item in scanResponse.Items) { if (limit > 0 && items.Count >= limit) { return(items); } items.Add(JsonConvert.DeserializeObject <T>(Document.FromAttributeMap(item).ToJson())); } } while (scanResponse.LastEvaluatedKey.Any()); return(items); }
public static long GetItemCount(string tableName) { long itemCount = 0; try { AmazonDynamoDBClient client; using (client = new AmazonDynamoDBClient(MyAWSConfigs.DynamodbRegion)) { Dictionary <string, AttributeValue> lastKeyEvaluated = null; do { ScanRequest scanRequest = new ScanRequest { TableName = tableName, ExclusiveStartKey = lastKeyEvaluated }; ScanResponse scanResponse = client.Scan(scanRequest); itemCount += scanResponse.Count; lastKeyEvaluated = scanResponse.LastEvaluatedKey; }while (lastKeyEvaluated != null && lastKeyEvaluated.Count != 0); } } catch (AmazonDynamoDBException e) { Console.WriteLine("AmazonDynamoDBException: " + e); } catch (Exception e) { Console.WriteLine("Error: " + e); } return(itemCount); }
public async Task <ScanResponse> Scan([FromBody] ScanRequest value) { var shipsInRange = await this.ShipManager.ScanAsync(value.CommandCode); var response = new ScanResponse { Ships = shipsInRange.Select(s => new ShipSummary { Name = s.Name, TransponderCode = s.TransponderCode, Location = s.Location == null ? null : new LocationRequestOrResponse { X = s.Location.X, Y = s.Location.Y, Z = s.Location.Z } }) }; return(response); }
public static async Task Songlist_upload__read_old_songs__none_found() { // Arrange var scanResults = new ScanResponse { Items = new List <Dictionary <string, AttributeValue> > { new Dictionary <string, AttributeValue>() } }; Mock <IDynamodbDependencyProvider> dynamodbProvider = new Mock <IDynamodbDependencyProvider>(MockBehavior.Strict); Mock <IS3DependencyProvider> s3Provider = new Mock <IS3DependencyProvider>(MockBehavior.Strict); dynamodbProvider.Setup(x => x.DynamoDbScanAsync()).Returns(Task.FromResult(scanResults)); var songlistUpload = new Logic(dynamodbProvider.Object, s3Provider.Object) { BucketName = "foo", KeyName = "bar" }; // Act await songlistUpload.ReadOldSongs(); // Assert Assert.Empty(songlistUpload.OldSongs); }
public IEnumerable <MovieResponse> ToMovieResponseContract(ScanResponse response) { return(response.Items.Select(ToMovieResponseContract)); }
public async Task <APIGatewayProxyResponse> Handler(APIGatewayProxyRequest input, ILambdaContext context) { var client = new AmazonDynamoDBClient(); var scanRequest = new ScanRequest { TableName = Environment.ExpandEnvironmentVariables("%TABLE_NAME%"), ProjectionExpression = "connectionId" }; ScanResponse connections = null; try { connections = await client.ScanAsync(scanRequest); } catch (Exception e) { return(new APIGatewayProxyResponse { StatusCode = (int)HttpStatusCode.InternalServerError, Body = e.Message, Headers = new Dictionary <string, string> { { "Content-Type", "text/plain" } }, }); } var data = JObject.Parse(input.Body)["data"].ToString(); var byteArray = Encoding.UTF8.GetBytes(data); var config = new AmazonApiGatewayManagementApiConfig { ServiceURL = $"https://{input.RequestContext.DomainName}/{input.RequestContext.Stage}" }; var apiClient = new AmazonApiGatewayManagementApiClient(config); var connectionIds = connections.Items.Select(item => item["connectionId"].S).ToList(); foreach (var connectionId in connectionIds) { var postData = new MemoryStream(byteArray); try { var postToRequest = new PostToConnectionRequest { ConnectionId = connectionId, Data = postData }; await apiClient.PostToConnectionAsync(postToRequest); } catch (GoneException) { Console.WriteLine($"Found dead connection, deleting {connectionId}"); var attributes = new Dictionary <string, AttributeValue>(); attributes["connectionId"] = new AttributeValue { S = connectionId }; var deleteRequest = new DeleteItemRequest { TableName = Environment.ExpandEnvironmentVariables("%TABLE_NAME%"), Key = attributes }; try { await client.DeleteItemAsync(deleteRequest); } catch (Exception e) { return(new APIGatewayProxyResponse { StatusCode = (int)HttpStatusCode.InternalServerError, Body = e.Message, Headers = new Dictionary <string, string> { { "Content-Type", "text/plain" } }, }); } } catch (Exception e) { return(new APIGatewayProxyResponse { StatusCode = (int)HttpStatusCode.InternalServerError, Body = e.Message, Headers = new Dictionary <string, string> { { "Content-Type", "text/plain" } }, }); } } return(new APIGatewayProxyResponse { StatusCode = (int)HttpStatusCode.OK, Body = "data sent", Headers = new Dictionary <string, string> { { "Content-Type", "text/plain" } }, }); }
private static async Task Backup() { ShowInfo("Backing up data for table {0} to file {1}", _tableName, _fileName); if (File.Exists(_fileName)) { if (_overwrite) { ShowWarning("Deleting existing backup file"); try { File.Delete(_fileName); } catch (Exception ex) { ShowError("There was an error deliting existing backup file {0}. {1}", _fileName, ex.Message); return; } } else { ShowError("File {0} alredy exists. To avoid overwriting data, please delete it manually first, or supplied the -o argument to overwrite it", _fileName); return; } } // Get a Table object for the table that you created in Step 1 if (!await GetTableObject(_tableName, false)) { PauseForDebugWindow(); return; } // Load the movie data into the table (this could take some time) ShowInfo("Scanning DynamoDB table", _describeTableResponse.Table.ItemCount); Dictionary <string, AttributeValue> lastEvaluatedKey = null; int totalItemsCount = 0; bool isFirstItem = true; using (var writer = File.CreateText(_fileName)) { writer.WriteLine("["); do { ScanRequest scanRequest = new ScanRequest(_tableName) { Select = Select.ALL_ATTRIBUTES, ExclusiveStartKey = lastEvaluatedKey, Limit = 500 }; ScanResponse scanResponse = await _client.ScanAsync(scanRequest); lastEvaluatedKey = scanResponse.LastEvaluatedKey; int batchItems = scanResponse.Items.Count; totalItemsCount += batchItems; ShowInfo("Writing batch of {0} item to backup file", batchItems); StringBuilder builder = new StringBuilder(); foreach (var item in scanResponse.Items) { Document document = Document.FromAttributeMap(item); string json = document.ToJsonPretty(); string line = (!isFirstItem ? "," : string.Empty) + json; // await writer.WriteLineAsync(line); builder.AppendLine(line); isFirstItem = false; } await writer.WriteLineAsync(builder.ToString()); } while (lastEvaluatedKey != null && lastEvaluatedKey.Count > 0); writer.Write("]"); } ShowInfo("Finished importing {0} records from DynamoDB", totalItemsCount); PauseForDebugWindow(); }
private List <PositionData> CovertresponseIntoJSON(ScanResponse response) { List <Dictionary <string, AttributeValue> > result = response.Items; List <PositionData> positionList = new List <PositionData>(); PositionData position = new PositionData(); foreach (Dictionary <string, AttributeValue> items in result) { List <string> listofselectedIdentities = new List <string>(); List <string> listofTasks = new List <string>(); List <string> listofCountries = new List <string>(); List <string> tasklistHistory = new List <string>(); Dictionary <string, string> item = new Dictionary <string, string>(); foreach (var val in items) { if (val.Key == "SelectedIdentities") { foreach (var web in val.Value.L) { if (!listofselectedIdentities.Contains(web.S)) { listofselectedIdentities.Add(web.S); } } } if (val.Key == "SelectTasks") { foreach (var web in val.Value.L) { if (!listofTasks.Contains(web.S)) { listofTasks.Add(web.S); } } } if (val.Key == "SelectCountries") { foreach (var web in val.Value.L) { if (!listofCountries.Contains(web.S)) { listofCountries.Add(web.S); } } } if (val.Key == "TasksHistoryList") { foreach (var web in val.Value.L) { if (!tasklistHistory.Contains(web.S)) { tasklistHistory.Add(web.S); } } } item.Add(val.Key, val.Value.S); } string jsonString = JsonConvert.SerializeObject(item, Formatting.Indented); position = JsonConvert.DeserializeObject <PositionData>(jsonString); position.SelectedIdentities = listofselectedIdentities; position.SelectTasks = listofTasks; position.TasksHistoryList = tasklistHistory; position.SelectCountries = listofCountries; positionList.Add(position); } return(positionList); }
private static void UnmarshallResult(JsonUnmarshallerContext context, ScanResponse response) { int originalDepth = context.CurrentDepth; int targetDepth = originalDepth + 1; while (context.Read()) { if (context.TestExpression("Items", targetDepth)) { context.Read(); response.Items = new List <Dictionary <string, AttributeValue> >(); if (context.CurrentTokenType == JsonToken.Null) { continue; } DictionaryUnmarshaller <string, AttributeValue, StringUnmarshaller, AttributeValueUnmarshaller> unmarshaller = new DictionaryUnmarshaller <string, AttributeValue, StringUnmarshaller, AttributeValueUnmarshaller>(StringUnmarshaller.GetInstance(), AttributeValueUnmarshaller.GetInstance()); while (context.Read()) { JsonToken token = context.CurrentTokenType; if (token == JsonToken.ArrayStart) { continue; } if (token == JsonToken.ArrayEnd) { break; } response.Items.Add(unmarshaller.Unmarshall(context)); } continue; } if (context.TestExpression("Count", targetDepth)) { context.Read(); response.Count = IntUnmarshaller.GetInstance().Unmarshall(context); continue; } if (context.TestExpression("ScannedCount", targetDepth)) { context.Read(); response.ScannedCount = IntUnmarshaller.GetInstance().Unmarshall(context); continue; } if (context.TestExpression("LastEvaluatedKey", targetDepth)) { context.Read(); response.LastEvaluatedKey = new Dictionary <String, AttributeValue>(); if (context.CurrentTokenType == JsonToken.Null) { continue; } KeyValueUnmarshaller <string, AttributeValue, StringUnmarshaller, AttributeValueUnmarshaller> unmarshaller = new KeyValueUnmarshaller <string, AttributeValue, StringUnmarshaller, AttributeValueUnmarshaller>(StringUnmarshaller.GetInstance(), AttributeValueUnmarshaller.GetInstance()); while (context.Read()) { JsonToken token = context.CurrentTokenType; if (token == JsonToken.ArrayStart || token == JsonToken.ObjectStart) { continue; } if (token == JsonToken.ArrayEnd || token == JsonToken.ObjectEnd) { break; } KeyValuePair <string, AttributeValue> kvp = unmarshaller.Unmarshall(context); response.LastEvaluatedKey.Add(kvp.Key, kvp.Value); } continue; } if (context.TestExpression("ConsumedCapacity", targetDepth)) { context.Read(); response.ConsumedCapacity = ConsumedCapacityUnmarshaller.GetInstance().Unmarshall(context); continue; } if (context.CurrentDepth <= originalDepth) { return; } } return; }
public static List <T> ConvertAll <T>(this ScanResponse response) { return(response.Items .Select(values => DynamoMetadata.GetType <T>().ConvertTo <T>(values)) .ToList()); }
internal Response DynamoDbSearchPLVIdentities(IdentitiesFilterCriteria filterCriteria) { if ((null == filterCriteria.Email || "" == filterCriteria.Email) && (null == filterCriteria.CountryofResidence || "" == filterCriteria.CountryofResidence) && (null == filterCriteria.Affiliate || "" == filterCriteria.Affiliate)) { return(new Response(false, "First enter Search String")); } Dictionary <string, Condition> filter = new Dictionary <string, Condition>(); if (null != filterCriteria.Email && "" != filterCriteria.Email) { filter.Add("Email", new Condition { ComparisonOperator = "CONTAINS", AttributeValueList = new List <AttributeValue>() { new AttributeValue { S = filterCriteria.Email.ToLower() } } }); } if (null != filterCriteria.CountryofResidence && "" != filterCriteria.CountryofResidence) { filter.Add("CountryOfResidence", new Condition { ComparisonOperator = "CONTAINS", AttributeValueList = new List <AttributeValue>() { new AttributeValue { S = filterCriteria.CountryofResidence.ToLower() } } }); } if (null != filterCriteria.Affiliate && "" != filterCriteria.Affiliate) { filter.Add("Affiliate", new Condition { ComparisonOperator = "CONTAINS", AttributeValueList = new List <AttributeValue>() { new AttributeValue { S = filterCriteria.Affiliate.ToLower() } } }); } ScanRequest request = new ScanRequest { TableName = _tableName, AttributesToGet = new List <string> { "Affiliate", "CountryOfResidence", "Email", "PLV" }, ScanFilter = filter }; ScanResponse response = AmazonDynamoDBClientConnection.Client.Scan(request); List <IdentityDataModel> identityList = CovertresponseIntoJSON(response); return(new Response(true, "Search data found", identityList)); }
private List <IdentityDataModel> CovertresponseIntoJSON(ScanResponse response) { List <Dictionary <string, AttributeValue> > result = response.Items; if (null == result) { return(null); } List <IdentityDataModel> identityList = new List <IdentityDataModel>(); IdentityDataModel identity = new IdentityDataModel(); List <WebsiteDataModel> listofWebsiteData; foreach (Dictionary <string, AttributeValue> items in result) { listofWebsiteData = new List <WebsiteDataModel>(); Dictionary <string, string> item = new Dictionary <string, string>(); Dictionary <string, List <string> > websiteDataModel = new Dictionary <string, List <string> >(); foreach (var val in items) { if (val.Key == "WebsiteDataModel") { foreach (var web in val.Value.L) { WebsiteDataModel model = new WebsiteDataModel(); foreach (var w in web.M) { if (w.Key == "WebsiteAccountNumber") { model.WebsiteAccountNumber = w.Value.S; } if (w.Key == "WebsiteName") { model.WebsiteName = w.Value.S; } if (w.Key == "PIN") { model.PIN = w.Value.S; } if (w.Key == "UserName") { model.UserName = w.Value.S; } if (w.Key == "UserPassword") { model.UserPassword = w.Value.S; } if (w.Key == "SecurityQuestion") { model.SecurityQuestion = w.Value.S; } if (w.Key == "SecurityAnswer") { model.SecurityAnswer = w.Value.S; } if (w.Key == "Notes") { model.Notes = w.Value.S; } } listofWebsiteData.Add(model); } } item.Add(val.Key, val.Value.S); } string jsonString = JsonConvert.SerializeObject(item, Formatting.Indented); identity = JsonConvert.DeserializeObject <IdentityDataModel>(jsonString); identity.WebsiteDataModel = listofWebsiteData; identityList.Add(identity); } return(identityList); }
private void AddIpAddressToList(ScanResponse ipAddressResponse) { NetworkRange.ListOfActiveNetworkIpAddresses.Add(ipAddressResponse); }
public async Task <IEnumerable <int> > GetAsync(double magnitude, double latitude, double longitude, int searchRadius) { var result = new List <int>(); var searchRectangle = S2Manager.GetBoundingLatLngRect(latitude, longitude, searchRadius); Dictionary <string, Condition> conditions = new Dictionary <string, Condition> { { "Magnitude", new Condition { ComparisonOperator = ComparisonOperator.LE, AttributeValueList = new List <AttributeValue> { new AttributeValue { N = magnitude.ToString() } } } } }; Dictionary <string, AttributeValue> lastEvaluatedKey = null; do { ScanRequest request = new ScanRequest { TableName = _tableName, ScanFilter = conditions }; if (lastEvaluatedKey != null && lastEvaluatedKey.ContainsKey("chatid")) { request.ExclusiveStartKey["chatid"] = lastEvaluatedKey["chatid"]; } ScanResponse scanResponse = await _amazonDynamoDB.ScanAsync(request); foreach (var item in scanResponse.Items) { if (item.ContainsKey("chatid") && int.TryParse(item["chatid"].S, out int chatId)) { if (item.ContainsKey("LocationHash")) { if (ulong.TryParse(item["LocationHash"].N, out ulong locationHash) && searchRectangle.Intersects(new S2Cell(new S2CellId(locationHash)))) { result.Add(chatId); } } else { result.Add(chatId); } } } lastEvaluatedKey = scanResponse.LastEvaluatedKey; } while (lastEvaluatedKey != null && lastEvaluatedKey.Count > 0); return(result); }
internal Response DynamoDbSearchTasks(TasksFilterCriteria taskCriteria) { if ((null == taskCriteria.TaskName || "" == taskCriteria.TaskName) && (null == taskCriteria.Task || "" == taskCriteria.Task) && (null == taskCriteria.Website || "" == taskCriteria.Website) && (null == taskCriteria.State || "" == taskCriteria.State)) { return(new Response(false, "First enter Search String")); } Dictionary <string, Condition> filter = new Dictionary <string, Condition>(); if (null != taskCriteria.TaskName && "" != taskCriteria.TaskName) { filter.Add("TaskName", new Condition { ComparisonOperator = "CONTAINS", AttributeValueList = new List <AttributeValue>() { new AttributeValue { S = taskCriteria.TaskName.ToLower() } } }); } if (null != taskCriteria.Task && "" != taskCriteria.Task) { filter.Add("SelectTask", new Condition { ComparisonOperator = "CONTAINS", AttributeValueList = new List <AttributeValue>() { new AttributeValue { S = taskCriteria.Task.ToLower() } } }); } if (null != taskCriteria.Website && "" != taskCriteria.Website) { filter.Add("TaskWebsite", new Condition { ComparisonOperator = "CONTAINS", AttributeValueList = new List <AttributeValue>() { new AttributeValue { S = taskCriteria.Website.ToLower() } } }); } if (null != taskCriteria.State && "" != taskCriteria.State) { filter.Add("State", new Condition { ComparisonOperator = "CONTAINS", AttributeValueList = new List <AttributeValue>() { new AttributeValue { S = taskCriteria.State.ToLower() } } }); } ScanRequest request = new ScanRequest { TableName = _tablename, AttributesToGet = new List <string> { "TaskName", "SelectTask", "TaskWebsite", "SelectedIdentities" }, ScanFilter = filter }; ScanResponse response = AmazonDynamoDBClientConnection.Client.Scan(request); List <IdentityTaskData> identityList = CovertresponseIntoJSON(response); return(new Response(true, "Search data found", identityList)); }
public async Task <IEnumerable <Rooms> > GetAllRooms() { AwsAccessHelper awsAccessHelper = new AwsAccessHelper(configuration); var awsDb = awsAccessHelper.AwsConnecttion(); var request = new ScanRequest { TableName = tableName, Limit = 1, }; var allRooms = new List <Rooms>(); ScanResponse response = null; try { do { if (response != null) { request.ExclusiveStartKey = response.LastEvaluatedKey; } response = await awsDb.ScanAsync(request); foreach (var item in response.Items) { var room = new Rooms { Id = Convert.ToInt32(item["Id"].N), RoomNumber = Convert.ToInt32(item["RoomNumber"].N), Status = Convert.ToInt32(item["Status"].N), Note = item["Note"].S, CheckDate = Convert.ToDateTime(item["CheckDate"].S, CultureInfo.InvariantCulture), BaseMaterial = new BaseMaterials { Id = Convert.ToInt32(item["BaseMaterials"].M["Id"].N), Name = item["BaseMaterials"].M["Name"].S, Status = Convert.ToInt16(item["BaseMaterials"].M["Status"].N) }, HouseKeeper = new HouseKeepers { Id = Convert.ToInt32(item["HouseKeepers"].M["Id"].N), Name = item["HouseKeepers"].M["Name"].S, Point = item["HouseKeepers"].M["Point"].S, CheckDate = Convert.ToDateTime(item["HouseKeepers"].M["CheckDate"].S, CultureInfo.InvariantCulture) }, creator = Convert.ToInt32(item["creator"].N) == 1 ? Creator.Admin : Creator.Personel }; allRooms.Add(room); } } while (response.LastEvaluatedKey != null && response.LastEvaluatedKey.Count > 0); } catch (AmazonDynamoDBException e) { Console.WriteLine(e.Message); } catch (AmazonServiceException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } _context.HouseKeeper.ToList(); _context.BaseMaterial.ToList(); //reponse null control yap return(allRooms); }
private static async Task Backup() { ShowInfo("Backing up data for table {0} to file {1}", _tableName, _fileName); if (File.Exists(_fileName)) { if (_overwrite) { ShowWarning("Deleting existing backup file"); try { File.Delete(_fileName); } catch (Exception ex) { ShowError("There was an error deliting existing backup file {0}. {1}", _fileName, ex.Message); return; } } else { ShowError("File {0} alredy exists. To avoid overwriting data, please delete it manually first, or supplied the -o argument to overwrite it", _fileName); return; } } // Get a Table object for the table that you created in Step 1 if (!await GetTableObject(_tableName, false)) { PauseForDebugWindow(); return; } // Load the movie data into the table (this could take some time) ShowInfo("Scanning DynamoDB table", _describeTableResponse.Table.ItemCount); ScanRequest scanRequest = new ScanRequest(_tableName) { Select = Select.ALL_ATTRIBUTES }; ScanResponse scanResponse = await _client.ScanAsync(scanRequest); int totalItems = scanResponse.Items.Count; ShowInfo("Writting {0} item to backup file", totalItems); using (var writer = File.CreateText(_fileName)) { writer.WriteLine("["); int itemIndex = 0; foreach (var item in scanResponse.Items) { itemIndex++; Document document = Document.FromAttributeMap(item); string json = document.ToJsonPretty(); await writer.WriteLineAsync(json + (itemIndex < totalItems ? "," : string.Empty)); } writer.Write("]"); } ShowInfo("Finished importing {0} records from DynamoDB", scanResponse.Items.Count); PauseForDebugWindow(); }
/** * Get a list of all the audit records in a time range. * The response is limited to a 1000 records. */ internal static async Task <List <CountryAuditRecord> > GetCountryAuditRecords(AmazonDynamoDBClient dbClient, GetCountryAuditsRequest getCountryAuditsRequest) { Debug.Tested(); Debug.AssertValid(dbClient); Debug.AssertValid(getCountryAuditsRequest); Debug.Assert(APIHelper.IsValidAPIDateTimeString(getCountryAuditsRequest.from)); Debug.Assert(APIHelper.IsValidAPIDateTimeString(getCountryAuditsRequest.to)); // Check that the system is not locked. await SystemHelper.CheckSystemNotLocked(dbClient); // DateTime from = (DateTime)APIHelper.DateTimeFromAPIDateTimeString(getCountryAuditsRequest.from); DateTime to = (DateTime)APIHelper.DateTimeFromAPIDateTimeString(getCountryAuditsRequest.to); if (from <= to) { Debug.Tested(); bool limitResults = ((to - from).TotalSeconds > 60); List <string> attributes = new List <string>(); attributes.Add(FIELD_COUNTRY_AUDIT_ID); attributes.Add(FIELD_COUNTRY_AUDIT_TIMESTAMP); attributes.Add(FIELD_COUNTRY_AUDIT_NAME); attributes.Add(FIELD_COUNTRY_AUDIT_ADMINISTRATOR_ID); attributes.Add(FIELD_COUNTRY_AUDIT_CHANGE_TYPE); attributes.Add(FIELD_COUNTRY_AUDIT_CODE); attributes.Add(FIELD_COUNTRY_AUDIT_NAME); attributes.Add(FIELD_COUNTRY_AUDIT_CURRENCIES); attributes.Add(FIELD_COUNTRY_AUDIT_AVAILABLE); ScanResponse response = await dbClient.ScanAsync(DATASET_COUNTRY_AUDIT, attributes); Debug.AssertValid(response); //??++CHECK RESPONSE? List <CountryAuditRecord> retVal = new List <CountryAuditRecord>(); // Code = item[FIELD_COUNTRIES_CODE].S, // Name = item[FIELD_COUNTRIES_NAME].S, // Currencies = item[FIELD_COUNTRIES_CURRENCIES].SS, // Available = item[FIELD_COUNTRIES_AVAILABLE].BOOL // }); foreach (var item in response.Items) { Debug.Untested(); Debug.AssertValid(item); DateTime?timestamp = APIHelper.DateTimeFromAPITimestampString(item[FIELD_COUNTRY_AUDIT_TIMESTAMP].S); Debug.AssertValid(timestamp); if (from <= timestamp) { Debug.Tested(); if (timestamp < to) { Debug.Tested(); CountryAuditRecord countryAuditRecord = new CountryAuditRecord { ID = item[FIELD_COUNTRY_AUDIT_ID].S, Timestamp = (DateTime)timestamp, AdministratorID = item[FIELD_COUNTRY_AUDIT_ADMINISTRATOR_ID].S, ChangeType = (CountryAuditRecord.AuditChangeType) int.Parse(item[FIELD_COUNTRY_AUDIT_CHANGE_TYPE].N), Code = item[FIELD_COUNTRY_AUDIT_CODE].S, Name = item[FIELD_COUNTRY_AUDIT_NAME].S, Currencies = item[FIELD_COUNTRY_AUDIT_CURRENCIES].SS, Available = item[FIELD_COUNTRY_AUDIT_AVAILABLE].BOOL }; retVal.Add(countryAuditRecord); if (limitResults) { Debug.Tested(); if (retVal.Count == 1000) { Debug.Untested(); break; } else { Debug.Tested(); } } else { Debug.Untested(); } } else { Debug.Untested(); } } else { Debug.Untested(); } } return(retVal); } else { Debug.Tested(); throw new Exception(SharedLogicLayer.ERROR_FROM_GREATER_THAN_TO); } }
public async Task List_files() { // Arrange var expected = new ScanResponse<File>(new File[0], null); _connector.GetsJson("/stores/acme/foo/buckets/front/files", expected); // Act var response = await _client.ListFilesAsync("acme", "foo", "front", new ScanOptions(null, 0), None); // Assert response.ShouldBe(expected); }
public ResponseWrapper(ScanResponse scanResponse) { Items = scanResponse.Items; ItemCount = scanResponse.Items.Count; LastEvaluatedKey = scanResponse.LastEvaluatedKey; }
private void WorkerEntryPrt() { try { OnStatusChanged(new StatusChangedEventArgs("Connecting")); while (true) { try { //Scan 10 items. If middle of scan, pick up there ScanResponse response = ScanData( PersistentState.Database.GetKey("crashdumps_last_timestamp"), PersistentState.Database.GetKey("crashdumps_last_key")); //Start scanning based on last key in db //Into anon type with a little extra info. DB lookup to see if known, parse guid var newItems = response.Items .Select(x => new { item = x, guid = Guid.Parse(x["crash_id"].S) }) .Select(old => new { item = old.item, guid = old.guid, known = PersistentState.Database.GetCrash(old.guid) != null }) .ToList(); //If all items are known if (newItems.All(item => item.known)) { //reset progress so we start from start (new first on dynamoDB) PersistentState.Database.SetKey("crashdumps_last_timestamp", null); PersistentState.Database.SetKey("crashdumps_last_key", null); //And sleep for exponential backoff int timeout = _backoff.GetSeconds(); OnStatusChanged(new StatusChangedEventArgs($"No data. Retrying in {TimeSpan.FromSeconds(timeout)}")); for (int i = timeout - 1; i >= 0; i--) { Thread.Sleep(1000); } continue; } //Otherwise, add _NEW_ items to db using (SQLiteTransaction transaction = PersistentState.Database.GetTransaction()) { if (response.LastEvaluatedKey.Count == 0) { //If we reached the last (oldest), reset progress meter PersistentState.Database.SetKey("crashdumps_last_timestamp", null); PersistentState.Database.SetKey("crashdumps_last_key", null); } else { //Otherwise set next to take next block Dictionary <string, AttributeValue> nextRead = response.LastEvaluatedKey; PersistentState.Database.SetKey("crashdumps_last_timestamp", nextRead["upload_timestamp"].N); PersistentState.Database.SetKey("crashdumps_last_key", nextRead["crash_id"].S); } //Write stuff foreach (var item in newItems.Where(x => !x.known)) { WriteCrashToDb(item.item); //Don't take so long waiting for the next if we found anything. //Theoretically this should keep it checking roughly same frequency as new items gets added //in reality it is probably bull _backoff.Sucess(); } transaction.Commit(); } //Tell the good news that we have new items. Also tell guids so it can be found OnStatusChanged(new StatusChangedEventArgs("Working", newItems .Where(x => !x.known) .Select(x => x.guid) .ToList() )); } catch (InternalServerErrorException) { int timeout = _backoff.GetSeconds(); for (int i = timeout - 1; i >= 0; i--) { OnStatusChanged(new StatusChangedEventArgs($"Internal server error, retrying in {i} seconds")); Thread.Sleep(1000); } } catch (ProvisionedThroughputExceededException) { int timeout = _backoff.GetSeconds(); for (int i = timeout - 1; i >= 0; i--) { OnStatusChanged(new StatusChangedEventArgs($"Too fast, retrying in {i} seconds")); Thread.Sleep(1000); } } } } #if DEBUG catch (StackOverflowException ex) #else catch (Exception ex) #endif { OnStatusChanged(new StatusChangedEventArgs("Crashed", ex)); throw; } }
public void DisplayGarageInfo(ScanResponse result) { }
internal Response DynamoDbSearchTasks(PositionFilterCriteria positionCriteria) { if ((null == positionCriteria.PositionLabel || "" == positionCriteria.PositionLabel) && (null == positionCriteria.Website || "" == positionCriteria.Website) && (null == positionCriteria.Status || "" == positionCriteria.Status)) { return(new Response(false, "First enter Search String")); } Dictionary <string, Condition> filter = new Dictionary <string, Condition>(); if (null != positionCriteria.PositionLabel && "" != positionCriteria.PositionLabel) { filter.Add("PositionLabel", new Condition { ComparisonOperator = "CONTAINS", AttributeValueList = new List <AttributeValue>() { new AttributeValue { S = positionCriteria.PositionLabel.ToLower() } } }); } if (null != positionCriteria.Website && "" != positionCriteria.Website) { filter.Add("PositionWebsite", new Condition { ComparisonOperator = "CONTAINS", AttributeValueList = new List <AttributeValue>() { new AttributeValue { S = positionCriteria.Website.ToLower() } } }); } if (null != positionCriteria.Status && "" != positionCriteria.Status) { filter.Add("Status", new Condition { ComparisonOperator = "CONTAINS", AttributeValueList = new List <AttributeValue>() { new AttributeValue { S = positionCriteria.Status.ToLower() } } }); } ScanRequest request = new ScanRequest { TableName = _tablename, AttributesToGet = new List <string> { "PositionLabel", "PositionWebsite", "SelectSelection", "StartDateTime", "EndDateTime", "StartDate", "EndDate", "TotalDateTime", "SelectTasks", "SelectCountries", "SelectedIdentities", "Note" }, ScanFilter = filter }; ScanResponse response = AmazonDynamoDBClientConnection.Client.Scan(request); List <PositionData> positionList = CovertresponseIntoJSON(response); return(new Response(true, "Search data found", positionList)); }
//this is for get by scan public IEnumerable <ContactsResponse> ToContactContract(ScanResponse response) { return(response.Items.Select(ToContactContract)); }
/** * Search for users. */ internal static async Task <SearchUsersResponse> SearchUsers(AmazonDynamoDBClient dbClient, string loggedInUserId, string searchText) { Debug.Untested(); Debug.AssertID(loggedInUserId); Debug.AssertString(searchText); //??++NEEDS TO BE MORE EFFICIENT List <SearchUserResponse> users = new List <SearchUserResponse>(); string lowerSearchText = searchText.ToLower(); List <string> attributes = new List <string>(); attributes.Add(IdentityServiceDataLayer.FIELD_USERS_ID); attributes.Add(IdentityServiceDataLayer.FIELD_USERS_DELETED); attributes.Add(IdentityServiceDataLayer.FIELD_USERS_GIVEN_NAME); attributes.Add(IdentityServiceDataLayer.FIELD_USERS_FAMILY_NAME); attributes.Add(IdentityServiceDataLayer.FIELD_USERS_FULL_NAME); attributes.Add(IdentityServiceDataLayer.FIELD_USERS_PREFERRED_NAME); attributes.Add(IdentityServiceDataLayer.FIELD_USERS_EMAIL_ADDRESS); ScanResponse response = await dbClient.ScanAsync(IdentityServiceDataLayer.DATASET_USERS, attributes); Debug.AssertValid(response); //??++CHECK RESPONSE? LoggingHelper.LogMessage($"Get users: {response.Count} items"); foreach (var item in response.Items) { Debug.Untested(); Debug.AssertValid(item); if (item[IdentityServiceDataLayer.FIELD_USERS_DELETED] == null) { // User is not soft deleted. Debug.Tested(); if (Match(item[IdentityServiceDataLayer.FIELD_USERS_GIVEN_NAME].S, lowerSearchText) || Match(item[IdentityServiceDataLayer.FIELD_USERS_FAMILY_NAME].S, lowerSearchText) || Match(item[IdentityServiceDataLayer.FIELD_USERS_FULL_NAME].S, lowerSearchText) || Match(item[IdentityServiceDataLayer.FIELD_USERS_PREFERRED_NAME].S, lowerSearchText) || Match(item[IdentityServiceDataLayer.FIELD_USERS_EMAIL_ADDRESS].S, lowerSearchText)) { // User matches search text. Debug.Tested(); users.Add(new SearchUserResponse() { id = item[IdentityServiceDataLayer.FIELD_USERS_ID].S, givenName = item[IdentityServiceDataLayer.FIELD_USERS_GIVEN_NAME].S, familyName = item[IdentityServiceDataLayer.FIELD_USERS_FAMILY_NAME].S, fullName = item[IdentityServiceDataLayer.FIELD_USERS_FULL_NAME].S, emailAddress = item[IdentityServiceDataLayer.FIELD_USERS_EMAIL_ADDRESS].S }); } else { // User does not match search text. Debug.Tested(); } } else { // User is soft deleted. Debug.Untested(); } //??-- countries.Add(new Country { // Code = item[FIELD_COUNTRIES_CODE].S, // Name = item[FIELD_COUNTRIES_NAME].S, // Currencies = item[FIELD_COUNTRIES_CURRENCIES].SS, // Available = item[FIELD_COUNTRIES_AVAILABLE].BOOL // }); } //??-- foreach (var user in Users) { // Debug.Tested(); // Debug.AssertValid(user); // if (user.Deleted == null) { // // User is not soft deleted. // Debug.Tested(); // if (Match(user.GivenName, lowerSearchText) || // Match(user.FamilyName, lowerSearchText) || // Match(user.FullName, lowerSearchText) || // Match(user.PreferredName, lowerSearchText) || // Match(user.EmailAddress, lowerSearchText)) { // // User matches search text. // Debug.Tested(); // users.Add(new SearchUserResponse() { // id = user.ID, // givenName = user.GivenName, // familyName = user.FamilyName, // fullName = user.FullName, // emailAddress = user.EmailAddress // }); // } else { // // User does not match search text. // Debug.Tested(); // } // } else { // // User is soft deleted. // Debug.Untested(); // } // } return(new SearchUsersResponse() { users = users.ToArray() }); }
public async Task <List <Classtime> > ScanForRooms(BCSearchParams bcSearchParams) { String variableBuildingLetter = ":v_" + ClasstimeAsString.building; String variableRoomNumber = ":v_" + ClasstimeAsString.roomNumber; String variableDay = ":v_" + ClasstimeAsString.day; ScanRequest scanRequest = new ScanRequest() { TableName = base.tableName, ExpressionAttributeValues = new Dictionary <string, AttributeValue>() { { variableBuildingLetter, new AttributeValue() { S = bcSearchParams.buildingLetter } }, { variableRoomNumber, new AttributeValue() { S = bcSearchParams.roomNumber } }, { variableDay, new AttributeValue() { S = bcSearchParams.day } } }, //ExperssionAttributeNames allows me to swap using "#d" instead of "day", //since "day" is a key word for the request ExpressionAttributeNames = new Dictionary <string, string>() { { "#d", ClasstimeAsString.day } }, FilterExpression = ClasstimeAsString.building + " = " + variableBuildingLetter + " and " + ClasstimeAsString.roomNumber + " = " + variableRoomNumber + " and " + "#d" + " = " + variableDay }; ScanResponse scanResponse = await dynamodbClient.ScanAsync(scanRequest); Console.WriteLine("Number of Classtimes Found For classroom {0}: {1}", bcSearchParams.buildingLetter + bcSearchParams.roomNumber, scanResponse.Count); List <Classtime> classtimes = new List <Classtime>(); foreach (Dictionary <string, AttributeValue> values in scanResponse.Items) { Classtime classtime = new Classtime() { id = values[ClasstimeAsString.id].S, building = values[ClasstimeAsString.building].S, roomNumber = values[ClasstimeAsString.roomNumber].S, day = values[ClasstimeAsString.day].S, startTime = Int32.Parse(values[ClasstimeAsString.startTime].N), endTime = Int32.Parse(values[ClasstimeAsString.endTime].N), classCode = values[ClasstimeAsString.classCode].S }; classtimes.Add(classtime); } return(classtimes); }