跳過到頁腳內容
.NET幫助

Azure Tables(對開發者如何理解的工作)

在雲端運算的廣闊領域中,資料儲存扮演了形塑現代應用程式架構和擴展性的關鍵角色。 Azure Table Storage是由Microsoft Azure提供的全託管NoSQL資料儲存,不但為開發者提供了一個靈活的解決方案,用於雲端中儲存結構化的資料。 讓我們踏上一段探索Azure Table Storage功能、使用案例和優點的旅程。

了解Azure Table Storage

Azure Table Storage是一個基於雲的NoSQL數據庫服務,提供了無架構儲存的結構化資料。 Azure Tables提供一個基於鍵值對的數據模型,每個實體都由分區鍵和列鍵唯一識別。 此設計可提高數據查詢和檢索效率,特別適合需要快速訪問大型數據集的場景。

如果您正在決定要在Azure Table Storage和關係數據庫之間選擇來管理您的結構化數據,Azure Table Storage處理大型數據集的能力和與Azure生態系統的整合使得Azure Table Storage在開發者工具箱中成為一個方便的工具。

關鍵功能和能力

  1. 無架構設計: 與傳統的關係數據庫不同,Azure Table Storage不對數據執行結構要求。 這種靈活性允許開發者在同一張表中存儲不同結構的實體,促進敏捷開發並滿足隨著數據需求不斷演變的情況。

  2. 可擴展性和性能: Azure Table Storage為可擴展性而設計,能夠輕鬆處理大量數據。 它會自動調整以適應不斷增長的工作負載,並提供預測性性能,使其適合高吞吐量應用和需要低延遲數據訪問的場景。

  3. 分區和負載平衡: Azure Table Storage中的數據根據分區鍵分區,允許數據在多個儲存節點之間有效分配。 此分區策略實現了橫向擴展和負載平衡,確保最佳的性能和資源利用。

  4. 二級索引: 雖然Azure Table Storage主要使用分區鍵和行鍵來檢索資料,但它也支援透過複合鍵和查詢投影來建立二級索引。 此功能使開發人員能夠執行有效的範圍查詢和基於次級屬性的數據過濾,增強了數據訪問模式的靈活性。

  5. 與Azure生態系統整合: Azure Table Storage與其他Azure服務無縫整合,如Azure Functions、Azure Cosmos DB和Azure Logic Apps,讓開發者能夠輕鬆構建端到端解決方案。 無論是使用無伺服器功能來處理數據流,還是使用高級分析工具來分析數據,Azure Table Storage都是構建可擴展且具韌性的應用程式的基礎組件。

使用案例

Azure Table Storage滿足了各行各業廣泛的使用案例,包括:

  1. 物聯網(IoT): Azure Table Storage非常適合存儲來自IoT設備的遙測數據,使實時數據攝取、分析和可視化成為可能。 其可擴展性和性能使其成為處理IoT部署所產生的大量數據的理想選擇。

  2. 內容管理: 對於需要結構化儲存的內容元數據應用,例如博客、文章和用戶生成內容,Azure Table Storage 提供了一個具成本效益且可擴展的解決方案。 其無結構設計允許靈活的結構演變,適應內容結構隨時間變化的情況。

  3. 會話狀態管理: Azure Table Storage可以用來存儲Web應用的會話狀態資料,提供一個分散且可擴展的會話管理解決方案。 透過將會話狀態移交給Azure Table Storage,開發者可以在負載均衡環境中實現改進的可伸縮性、容錯能力和會話親和性。

  4. 分布式系統: 在分布式系統架構中,Azure Table Storage充當維持組件間共享狀態和協調的基礎數據存储庫。 其分區和擴展功能使其非常適合需要分散式緩存、配置管理和微服務間協調的場景。

介紹 IronPDF

Azure Tables(適用於開發者的工作原理):圖1

IronPDF是一個 C# PDF 程式庫,可以在 .NET 項目中生成、管理和提取 PDF 文檔中的內容。 以下是一些關鍵特性:

  1. HTML 轉 PDF:

    • 將 HTML、CSS 和 JavaScript 內容轉換為 PDF 文檔。
    • 使用 Chrome 渲染引擎生成完美像素的 PDF。
    • 從URL、HTML文件或HTML字符串作為輸入生成PDF。
  2. 影像和內容轉換:

    • 將圖像轉換為PDF或從PDF中提取圖像。
    • 從現有PDF文檔中提取文字和圖片。
    • 支持多種圖像格式,如JPG、PNG等。
  3. 編輯和操作:

    • 設定PDF的屬性、安全性和權限。
    • 添加數位簽名。
    • 編輯元數據和修訂歷史記錄。
  4. 跨平台支援:
    • 支持.NET Core(8、7、6、5和3.1+)、.NET Standard(2.0+)和.NET Framework(4.6.2+)。
    • 與Windows、Linux和macOS兼容。
    • 可在NuGet上獲取,便於安裝。

使用 IronPDF 和 Azure Tables 生成 PDF 文檔

首先,使用 Visual Studio 創建一個控制台應用程序,如下所示:

Azure Tables(適用於開發者的工作原理):圖2

提供項目名稱:

Azure Tables(適用於開發者的工作原理):圖3

提供 .NET 版本:

Azure Tables(適用於開發者的工作原理):圖4

從 NuGet 包管理器安裝 IronPDF 包:

Azure Tables(適用於開發者的工作原理):圖5

為了訪問 Azure Tables 程式庫,我們將使用 Azure Tables 客戶端程式庫 Azure.Data.Tables,可以在NuGet包管理器中找到。 Azure Table 服務客戶端提供了與 Azure Table Storage 交互的功能。

Azure Tables(適用於開發者的工作原理):圖6

建立一個Azure存儲帳戶以開始使用Azure Tables:

Azure Tables(適用於開發者的工作原理):圖7

單擊審查和創建。 在程式中輸入以下代碼,以使用 Azure Tables 生成 PDF 文檔。

using Azure;
using Azure.Data.Tables;
using Azure.Data.Tables.Models;
using IronPdf;
using System;
using System.Linq;
using System.Threading.Tasks;

namespace CodeSample
{
    public static class AzureTableDemo
    {
        public static async Task Execute()
        {
            var tableName = "IronDemo";
            var connectionString = "DefaultEndpointsProtocol=https;AccountName=irondemo;AccountKey=9Pe6LJlkjA721VgWvSuRCMk+WJR5/kFoyPtR1ewjRsNbGJNJOmWYhCB32fakANmWeAcfyIg++iHl+AStDNYlGw==;EndpointSuffix=core.windows.net";
            Console.WriteLine("Demo IronPDF with Azure.Data.Tables");

            // Enable web security for PDF rendering
            Installation.EnableWebSecurity = true;

            // Instantiate PDF renderer
            var renderer = new ChromePdfRenderer();

            // HTML content for the PDF
            var content = "<h1>Demo IronPDF with Azure.Data.Tables</h1>";

            // Create a TableServiceClient using the connection string
            content += "<h2>Create TableServiceClient</h2>";
            var serviceClient = new TableServiceClient(connectionString);
            content += "<p>var serviceClient = new TableServiceClient(connectionString);</p>";

            // Create the table if it does not exist
            content += "<h2>Create Table</h2>";
            TableItem table = await serviceClient.CreateTableIfNotExistsAsync(tableName);
            Console.WriteLine($"Created table: {table.Name}.");
            content += $"<p>Created table: {table.Name}.</p>";

            // Placeholder for delete table logic
            content += "<h2>Deletes If Required</h2>";
            // serviceClient.DeleteTable(tableName);
            content += "<p>serviceClient.DeleteTable(tableName);</p>";

            // Get a client reference to interact with the table
            content += "<h2>Get Table Client</h2>";
            var tableClient = serviceClient.GetTableClient(tableName);
            content += "<p>var tableClient = serviceClient.GetTableClient(tableName);</p>";

            // Define and add a new entity to the table
            content += "<h2>Add Table Entity</h2>";
            var tableEntity = new TableEntity { { "Book", "Awesome IronPDF Package" }, { "Price", 5.00 }, { "Quantity", 21 } };
            tableEntity.PartitionKey = tableEntity["Book"].ToString();
            tableEntity.RowKey = tableEntity["Price"].ToString();
            content += "<p>new TableEntity() { { \"Book\", \"Awesome IronPDF Package\" }, { \"Price\", 5.00 }, { \"Quantity\", 21 } }</p>";

            content += $"<p>tableEntity.PartitionKey = {tableEntity["Book"]}</p>";
            content += $"<p>tableEntity.RowKey = {tableEntity["Price"]}</p>";

            Console.WriteLine($"{tableEntity.RowKey}: {tableEntity["Book"]} costs ${tableEntity.GetDouble("Price")}.");
            content += $"<p>{tableEntity.RowKey}: {tableEntity["Book"]} costs ${tableEntity.GetDouble("Price")}</p>";

            // Add the entity to the table
            tableClient.AddEntity(tableEntity);
            content += "<p>Entity added.</p>";

            // Query the table
            content += "<h2>Query Table</h2>";
            Pageable<TableEntity> queryResultsFilter = tableClient.Query<TableEntity>(filter: $"PartitionKey eq '{tableEntity.PartitionKey}'");
            content += "<p>Using tableClient.Query<TableEntity></p>";

            // Iterate and display queried entities
            foreach (TableEntity qEntity in queryResultsFilter)
            {
                content += $"<p>{qEntity.GetString("Book")}: {qEntity.GetDouble("Price")}</p>";
                Console.WriteLine($"{qEntity.GetString("Book")}: {qEntity.GetDouble("Price")}");
            }
            Console.WriteLine($"The query returned {queryResultsFilter.Count()} entities.");
            content += $"<p>The query returned {queryResultsFilter.Count()} entities.</p>";

            // Render HTML content as PDF
            var pdf = renderer.RenderHtmlAsPdf(content);

            // Save the PDF to a file
            pdf.SaveAs("AwesomeAzureDataTables.pdf");
        }
    }
}
using Azure;
using Azure.Data.Tables;
using Azure.Data.Tables.Models;
using IronPdf;
using System;
using System.Linq;
using System.Threading.Tasks;

namespace CodeSample
{
    public static class AzureTableDemo
    {
        public static async Task Execute()
        {
            var tableName = "IronDemo";
            var connectionString = "DefaultEndpointsProtocol=https;AccountName=irondemo;AccountKey=9Pe6LJlkjA721VgWvSuRCMk+WJR5/kFoyPtR1ewjRsNbGJNJOmWYhCB32fakANmWeAcfyIg++iHl+AStDNYlGw==;EndpointSuffix=core.windows.net";
            Console.WriteLine("Demo IronPDF with Azure.Data.Tables");

            // Enable web security for PDF rendering
            Installation.EnableWebSecurity = true;

            // Instantiate PDF renderer
            var renderer = new ChromePdfRenderer();

            // HTML content for the PDF
            var content = "<h1>Demo IronPDF with Azure.Data.Tables</h1>";

            // Create a TableServiceClient using the connection string
            content += "<h2>Create TableServiceClient</h2>";
            var serviceClient = new TableServiceClient(connectionString);
            content += "<p>var serviceClient = new TableServiceClient(connectionString);</p>";

            // Create the table if it does not exist
            content += "<h2>Create Table</h2>";
            TableItem table = await serviceClient.CreateTableIfNotExistsAsync(tableName);
            Console.WriteLine($"Created table: {table.Name}.");
            content += $"<p>Created table: {table.Name}.</p>";

            // Placeholder for delete table logic
            content += "<h2>Deletes If Required</h2>";
            // serviceClient.DeleteTable(tableName);
            content += "<p>serviceClient.DeleteTable(tableName);</p>";

            // Get a client reference to interact with the table
            content += "<h2>Get Table Client</h2>";
            var tableClient = serviceClient.GetTableClient(tableName);
            content += "<p>var tableClient = serviceClient.GetTableClient(tableName);</p>";

            // Define and add a new entity to the table
            content += "<h2>Add Table Entity</h2>";
            var tableEntity = new TableEntity { { "Book", "Awesome IronPDF Package" }, { "Price", 5.00 }, { "Quantity", 21 } };
            tableEntity.PartitionKey = tableEntity["Book"].ToString();
            tableEntity.RowKey = tableEntity["Price"].ToString();
            content += "<p>new TableEntity() { { \"Book\", \"Awesome IronPDF Package\" }, { \"Price\", 5.00 }, { \"Quantity\", 21 } }</p>";

            content += $"<p>tableEntity.PartitionKey = {tableEntity["Book"]}</p>";
            content += $"<p>tableEntity.RowKey = {tableEntity["Price"]}</p>";

            Console.WriteLine($"{tableEntity.RowKey}: {tableEntity["Book"]} costs ${tableEntity.GetDouble("Price")}.");
            content += $"<p>{tableEntity.RowKey}: {tableEntity["Book"]} costs ${tableEntity.GetDouble("Price")}</p>";

            // Add the entity to the table
            tableClient.AddEntity(tableEntity);
            content += "<p>Entity added.</p>";

            // Query the table
            content += "<h2>Query Table</h2>";
            Pageable<TableEntity> queryResultsFilter = tableClient.Query<TableEntity>(filter: $"PartitionKey eq '{tableEntity.PartitionKey}'");
            content += "<p>Using tableClient.Query<TableEntity></p>";

            // Iterate and display queried entities
            foreach (TableEntity qEntity in queryResultsFilter)
            {
                content += $"<p>{qEntity.GetString("Book")}: {qEntity.GetDouble("Price")}</p>";
                Console.WriteLine($"{qEntity.GetString("Book")}: {qEntity.GetDouble("Price")}");
            }
            Console.WriteLine($"The query returned {queryResultsFilter.Count()} entities.");
            content += $"<p>The query returned {queryResultsFilter.Count()} entities.</p>";

            // Render HTML content as PDF
            var pdf = renderer.RenderHtmlAsPdf(content);

            // Save the PDF to a file
            pdf.SaveAs("AwesomeAzureDataTables.pdf");
        }
    }
}
$vbLabelText   $csharpLabel

代碼解釋

代碼演示了如何與Azure Table Storage交互並使用IronPDF生成PDF:

  1. Azure Table Storage交互:

    • 使用 Azure SDK for .NET(Azure.Data.Tables)連接到 Azure Table Storage。
    • 然後檢查是否存在名為"IronDemo"的表; 如果不存在,就創建它。
    • 向表添加一個新的實體(類似於資料庫行),指定"Book"、"Price"和"Quantity"等屬性。
    • 查詢表以根據過濾條件檢索實體。
  2. 使用 IronPDF 生成 PDF:
    • 使用 IronPDF 的 ChromePdfRenderer 將 HTML 內容渲染成 PDF 文件。
    • 從包含 Azure Table Storage 操作詳細信息的動態 HTML 內容生成 PDF。

Azure Tables(適用於開發者的工作原理):圖8

IronPDF 授權

IronPDF包需要授權才能運行。 在應用程序開始處,包訪問之前添加下面的代碼

IronPdf.License.LicenseKey = "IRONPDF-KEY";
IronPdf.License.LicenseKey = "IRONPDF-KEY";
$vbLabelText   $csharpLabel

試用授權可以這裡獲得。

結論

Azure Table Storage 是微軟致力於為開發者提供在雲中具可擴展性、靈活且具成本效益的數據儲存解決方案的見證。 憑藉其無結構設計、橫向擴展性以及與Azure生態系統的無縫整合,Azure Table Storage使開發者能夠建立具韌性和敏捷的應用,這些應用可以應對現代商業環境中的動態需求。

無論是管理物聯網資料流、儲存內容元數據,還是協調分布式系統,Azure Table Storage提供了一個釋放雲原生應用潛能的平台。 隨著組織繼續接受數位轉型計劃並遷移到雲端,Azure Table Storage仍是現代資料存儲架構的基石,推動創新並使企業能夠在一個日益以數據為驅動的世界中繁榮發展。

IronPDF 是一個.NET程式庫,用於以程式化方式創建和操作 PDF 文檔。 它允許開發者將HTML、ASPX頁面、圖像和文本轉換為 PDF 文件。 主要功能包括 HTML 到 PDF 的轉換、PDF 編輯能力以及對各種 .NET 環境的支持,使其成為在 .NET 應用程式中生成和處理 PDF 文檔的多功能工具。

常見問題解答

如何使用 C# 將 HTML 內容轉換為 PDF?

您可以使用 IronPDF 庫在 C# 中將 HTML 內容轉換為 PDF。該庫提供了如 RenderHtmlAsPdf 這樣的方法以將 HTML 字串或文件轉換為 PDF 文件。

在 Azure Table Storage 中分區扮演什麼角色?

Azure Table Storage 中的分區有助於將數據分佈在不同的節點上,提高負載平衡和可擴展性。它使用分區鍵來在儲存叢集內高效地管理資料。

我能否將 Azure Table Storage 與 C# PDF 庫集成以生成文件?

是的,您可以將 Azure Table Storage 與像 IronPDF 這樣的 C# PDF 庫集成來生成文件。這種整合允許從 Azure Table Storage 提取數據並使用 IronPDF 將其呈現為 PDF 格式。

在雲端數據庫使用無架構儲存的好處是什麼?

Azure Table Storage 提供的無架構儲存,為數據設計提供了靈活性。它允許在同一表內使用不同的數據結構,這便於敏捷開發及適應不斷變化的數據模型。

Azure Table Storage 如何支持 IoT 資料管理?

Azure Table Storage 通過為遙測數據提供可擴展和高效的儲存來支持 IoT 資料管理。其無架構的設計和可擴展性使其成為管理大量 IoT 資料的理想選擇。

在生產環境中使用 C# PDF 庫需要許可嗎?

是的,在生產環境中使用像 IronPDF 這樣的 C# PDF 庫需要許可。為了評估目的,有提供試用許可,允許開發者在購買前探索其功能。

Azure Table Storage 如何確保數據查詢的高效性?

Azure Table Storage 使用包含分區鍵和行鍵的鍵值對模型,優化數據查詢和檢索。這種設計允許高效地訪問大型數據集。

Azure Table Storage 的常見應用是什麼?

Azure Table Storage 常見的應用包括存儲內容管理的元資料、管理 Web 應用中的會話狀態,以及在分佈式系統中協調共享狀態。

Jacob Mellor, Team Iron 首席技術官
首席技術官

Jacob Mellor是Iron Software的首席技術官,也是開創C# PDF技術的前瞻性工程師。作為Iron Software核心代碼庫的原始開發者,他自公司成立以來就塑造了公司的產品架構,並與CEO Cameron Rimington將公司轉型為服務NASA、Tesla以及全球政府機構的50多人公司。

Jacob擁有曼徹斯特大學土木工程一級榮譽學士學位(1998年–2001年)。他於1999年在倫敦開立首家軟體公司,並於2005年建立了他的第一個.NET組件,專注於解決Microsoft生態系統中的複雜問題。

他的旗艦作品IronPDF和Iron Suite .NET程式庫全球已獲得超過3000萬次NuGet安裝,他的基礎代碼不斷在全球各地驅動開發者工具。擁有25年以上的商業經驗和41年的編碼專業知識,Jacob仍然專注於推動企業級C#、Java和Python PDF技術的創新,同時指導下一代技術領導者。

Iron Support Team

We're online 24 hours, 5 days a week.
Chat
Email
Call Me