private void Monitor_OnStreamUpdate(object sender, OnStreamUpdateArgs e) { var snapshot = new StreamSnapshot(e.Stream, API); tableClient.AddEntity(snapshot); Console.WriteLine($"Stored Snapshop {snapshot.RowKey}"); }
public static HelpMetaData CalculateMetaData(TableClient client, ILogger log) { log.LogInformation("Calculating meta data on HelpTable"); string filter = TableServiceClient.CreateQueryFilter($"PartitionKey eq {CommandHelpPartitionKey}"); var select = new string[] { "CommandName", "ModuleName" }; var entities = client.Query <HelpEntity>(filter: filter, select: select); var numAbout = entities .Where(r => r .CommandName .StartsWith("about_", StringComparison.OrdinalIgnoreCase)) .Count(); var moduleNames = entities .Select(r => r.ModuleName) .Where(moduleName => !string.IsNullOrEmpty(moduleName)) .Distinct(); var helpMetaData = new HelpMetaData() { PartitionKey = MetaDataPartitionKey, RowKey = MetaDataRowKey, NumberOfAboutArticles = numAbout, NumberOfCommands = entities.Count() - numAbout, NumberOfModules = moduleNames.Count(), ModuleNames = string.Join(',', moduleNames), LastPublished = Helpers.GetBuildDate(Assembly.GetExecutingAssembly()).ToLongDateString() }; var metaDataEntity = new HelpMetaData(); try { metaDataEntity = client.GetEntity <HelpMetaData>(MetaDataPartitionKey, MetaDataRowKey); _ = client.UpsertEntity(helpMetaData); } catch (RequestFailedException) { _ = client.AddEntity(helpMetaData); } return(helpMetaData); }
public void CreateDeleteEntity() { string storageUri = StorageUri; string accountName = StorageAccountName; string storageAccountKey = PrimaryStorageAccountKey; string tableName = "OfficeSupplies2p1"; string partitionKey = "Stationery"; string rowKey = "A1"; string rowKeyStrong = "B1"; #region Snippet:TablesSample2CreateTableWithTableClient // Construct a new <see cref="TableClient" /> using a <see cref="TableSharedKeyCredential" />. var tableClient = new TableClient( tableName, new Uri(storageUri), new TableSharedKeyCredential(accountName, storageAccountKey)); // Create the table in the service. tableClient.Create(); #endregion #region Snippet:TablesSample2CreateDictionaryEntity // Make a dictionary entity by defining a <see cref="TableEntity">. var entity = new TableEntity(partitionKey, rowKey) { { "Product", "Marker Set" }, { "Price", 5.00 }, { "Quantity", 21 } }; Console.WriteLine($"{entity.RowKey}: {entity["Product"]} costs ${entity.GetDouble("Price")}."); #endregion #region Snippet:TablesSample2AddEntity // Add the newly created entity. tableClient.AddEntity(entity); #endregion #region Snippet:TablesSample2CreateStronglyTypedEntity // Create an instance of the strongly-typed entity and set their properties. var strongEntity = new OfficeSupplyEntity { PartitionKey = partitionKey, RowKey = rowKeyStrong, Product = "Notebook", Price = 3.00, Quantity = 50 }; Console.WriteLine($"{entity.RowKey}: {strongEntity.Product} costs ${strongEntity.Price}."); #endregion // Add the newly created entity. tableClient.AddEntity(strongEntity); #region Snippet:TablesSample2DeleteEntity // Delete the entity given the partition and row key. tableClient.DeleteEntity(partitionKey, rowKey); #endregion #region Snippet:TablesSample2DeleteTableWithTableClient tableClient.Delete(); #endregion }
public async Task <IActionResult> PostAsync([FromForm] SendFileRequestBody body) { if (body.File == null && body.Image == null) { return(BadRequest("Invalid file")); } if (string.IsNullOrWhiteSpace(body.FileName)) { return(BadRequest("Invalid file name")); } // TODO: Verify that user is allowed to upload files for this chat/call // bool isUserInThread = await this.VerifyUserInThread(chatClient, body.ThreadId); // if (!isUserInThread) // { // return this.Unauthorized(); // } // Prepare Blob Storage clients and container string blobName = Guid.NewGuid().ToString(); BlobContainerClient containerClient = new BlobContainerClient(_storageAccountConnectionString, _blobContainerName); containerClient.CreateIfNotExists(); BlobClient blob = containerClient.GetBlobClient(blobName); Azure.Response <BlobContentInfo> uploadResponse; if (body.File != null) { Console.WriteLine($"Got file length: {body.File.Length}"); uploadResponse = await blob.UploadAsync(body.File.OpenReadStream()); } else { Console.WriteLine($"Got image length: {body.Image.Length}"); var bytes = Convert.FromBase64String(body.Image); using (var stream = new MemoryStream(bytes)) { uploadResponse = await blob.UploadAsync(stream); } } Console.WriteLine($"Uploaded blob: {blobName}"); // Store file info in Table Storage TableServiceClient tableServiceClient = new TableServiceClient(_storageAccountConnectionString); TableClient tableClient = tableServiceClient.GetTableClient(_tableName); tableClient.CreateIfNotExists(); var entity = new TableEntity(blobName, blobName) { { "FileId", blobName }, { "FileName", body.FileName }, { "UploadDateTime", DateTimeOffset.UtcNow } }; tableClient.AddEntity(entity); Console.WriteLine("Added file data to table"); return(this.Ok()); }
public Response Create(T entity) => _tableClient.AddEntity(entity);
static void Main(string[] args) { Console.WriteLine(hiMessage); try { // Get the connection string from app settings string connectionString = ConfigurationManager.AppSettings[storageConnectionString]; // Instantiate a QueueClient which will be used to create and manipulate the queue var queueClient = new QueueClient(connectionString, Names.QueueName); // Create the queue queueClient.CreateIfNotExists(); if (!queueClient.Exists()) { Console.WriteLine("Cannot create Queue. Make sure the storage emulator running and try again."); } // Instantiate a TableClient which will be used to create and manipulate the table var tableClient = new TableClient(connectionString, Names.TableName); // Create the table tableClient.CreateIfNotExists(); for (;;) { // Get the next message QueueMessage retrievedMessage = queueClient.ReceiveMessage(); if (null == retrievedMessage) { Thread.Sleep(numberOfMilliseconds); continue; } var order = JsonSerializer.Deserialize <Order>(retrievedMessage.MessageText); if (order.RandomNumber == magicNumber) { Console.WriteLine(numberFoundMessage); break; } // Process the message Console.WriteLine(receivedOrderMessage, order.OrderId); var confirmation = new Confirmation() { OrderId = order.OrderId, AgentId = agentId, OrderStatus = orderStatusProcessed, RowKey = order.OrderId.ToString(), PartitionKey = agentId.ToString() }; tableClient.AddEntity(confirmation); // Delete the message queueClient.DeleteMessage(retrievedMessage.MessageId, retrievedMessage.PopReceipt); } Console.ReadLine(); } catch (Exception ex) { Console.WriteLine($"Exception: {ex.Message}\n\n"); Console.WriteLine("Make sure the storage emulator running and try again."); } }
public void SaveRecord(string container, TableEntity entity) { TableClient tableClient = new TableClient(_connectionString, container); tableClient.AddEntity(entity); }