public async Task <bool> SetConnectionRecordStateAsync(ConnectionRecord record, ConnectionState state, CancellationToken cancellationToken = default) { try { await DynamoDbClient.UpdateItemAsync(new UpdateItemRequest { TableName = TableName, Key = new Dictionary <string, AttributeValue> { ["PK"] = new AttributeValue(CONNECTION_PREFIX + record.ConnectionId), ["SK"] = new AttributeValue(INFO) }, UpdateExpression = "SET #State = :state, #Modified = :modified", ExpressionAttributeNames = { ["#State"] = nameof(record.State), ["#Modified"] = "_Modified" }, ExpressionAttributeValues = { [":state"] = new AttributeValue(state.ToString()), [":modified"] = new AttributeValue { N = DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString() } } }); record.State = state; return(true); } catch (ConditionalCheckFailedException) { return(false); } }
private async Task DeleteAllTablesAsync() { if (DynamoDbClient != null) { var tables = await DynamoDbClient.ListTablesAsync(); foreach (var tableName in tables.TableNames) { await DynamoDbClient.DeleteTableAsync(tableName); } } }
/// <summary> /// Method to run Health Check for Dynamo DB Repository /// </summary> /// <param name="serviceKey"></param> /// <param name="value"></param> /// <returns></returns> public override LightHealth.HealthCheck HealthCheck(string serviceKey, string value) { try { var c = DynamoDbClient.ListTablesAsync(); return(LightHealth.HealthCheck.Healthy); } catch { return(LightHealth.HealthCheck.Unhealthy); } }
/// <summary> /// Clean the database and fullfill with inicialdata /// (only if is develop, integration and testing environment) /// </summary> /// <param name="query">name of file separetd with ','</param> /// <returns>Result from the operation in a message</returns> public override bool ResetData(string query) { DynamoDbClient.ListTablesAsync().Result.TableNames.ForEach(async x => { var request = new DeleteTableRequest { TableName = x }; await DynamoDbClient.DeleteTableAsync(request); }); return(true); }
private async Task CreateExampleTableAsync() { if (DynamoDbClient != null) { await DynamoDbClient.CreateTableAsync(new CreateTableRequest { TableName = "Example", AttributeDefinitions = new List <AttributeDefinition> { new AttributeDefinition { AttributeName = "Id", AttributeType = "S" }, new AttributeDefinition { AttributeName = "CreatedDate", AttributeType = "S" } }, KeySchema = new List <KeySchemaElement> { new KeySchemaElement { AttributeName = "Id", KeyType = "HASH" }, new KeySchemaElement { AttributeName = "CreatedDate", KeyType = "RANGE" } }, ProvisionedThroughput = new ProvisionedThroughput { ReadCapacityUnits = 10, WriteCapacityUnits = 5 } }); } }
public void SetSymbolQuotes() { var stocks = GetTickerSymbols(INSTRUMENT_TYPE_STOCK); var token = Environment.GetEnvironmentVariable("IEX_Cloud_Secret_Key"); var client = new HttpClient { BaseAddress = new Uri("https://cloud.iexapis.com/") }; var awsClient = new DynamoDbClient <Quote>(DynamoDbClient, new Logger(Output)); foreach (var stock in stocks) { var url = $"beta/stock/{stock.Symbol.ToLower()}/quote?token={token}"; string quote = string.Empty; try { var request = client.GetAsync(url).Result; if (request.StatusCode == HttpStatusCode.NotFound) { Output.WriteLine($"{stock.Symbol} not found"); continue; } request.EnsureSuccessStatusCode(); quote = request.Content.ReadAsStringAsync().Result; var quoteEntity = JsonConvert.DeserializeObject <Quote>(quote); quoteEntity.InstrumentType = INSTRUMENT_TYPE_STOCK; Output.WriteLine(quoteEntity.Symbol); awsClient.Insert(quoteEntity).Wait(); System.Threading.Thread.Sleep(250); } catch (Exception) { Output.WriteLine(url); Output.WriteLine(JsonConvert.SerializeObject(stock, Formatting.Indented)); Output.WriteLine(quote); throw; } } }
public UserService() { client = DynamoDbClient.CreateClient(); }
public MusicController(DynamoDbClient client) { _client = client; }
public void GetDowJonesIndustrialAverage() { var awsClient = new DynamoDbClient <Quote>(DynamoDbClient, new Logger(Output)); var quotes = awsClient.Get(new List <Quote>() { new Quote { Symbol = "MMM" }, new Quote { Symbol = "AXP" }, new Quote { Symbol = "AAPL" }, new Quote { Symbol = "BA" }, new Quote { Symbol = "CAT" }, new Quote { Symbol = "CVX" }, new Quote { Symbol = "CSCO" }, new Quote { Symbol = "KO" }, new Quote { Symbol = "DIS" }, new Quote { Symbol = "DOW" }, new Quote { Symbol = "XOM" }, new Quote { Symbol = "GS" }, new Quote { Symbol = "HD" }, new Quote { Symbol = "IBM" }, new Quote { Symbol = "INTC" }, new Quote { Symbol = "JNJ" }, new Quote { Symbol = "JPM" }, new Quote { Symbol = "MCD" }, new Quote { Symbol = "MRK" }, new Quote { Symbol = "MSFT" }, new Quote { Symbol = "NKE" }, new Quote { Symbol = "PFE" }, new Quote { Symbol = "PG" }, new Quote { Symbol = "TRV" }, new Quote { Symbol = "UTX" }, new Quote { Symbol = "UNH" }, new Quote { Symbol = "VZ" }, new Quote { Symbol = "V" }, new Quote { Symbol = "WMT" }, new Quote { Symbol = "WBA" } }).Result; Assert.Equal(30, quotes.Count); var sumPrice = quotes.Sum(x => x.LatestPrice); var divisor = 0.14744568353097m; var djia = sumPrice / divisor; Output.WriteLine(djia.ToString()); }