ActiveReports使用教程:如何将 表存储与ASP.NET Core中的 表后端分离

ActiveReports允许您将 表存储与服务分离。在更新或修改 告后,您无需重建它,并且分离为 告管理提供了更大的自由度。对于显示 告的应用程序和Web设计器使用相同的存储。

ActiveReports最新试用版

以下教程介绍了如何设置 告服务应用程序,以便它从Azure文件获取 告。

注意:为了简单起见,本教程使用Monolith应用程序,但是相同的代码可以与单独的Reporting Service应用程序一起使用。

  1. 创建Azure存储帐户和文件共享或使用现有的帐户
  2. 将页面 告上载到共享的根目录中,记下该 告的名称
  3. 在Visual Studio 2019中,创建一个新的“ ActiveReports 14 JS Viewer Core MVC”应用程序
  4. 将以下软件包安装到新创建的项目中:

            Microsoft.Azure.Storage.Blob
            Microsoft.Azure.Storage.Common
            Microsoft.Azure.Storage.File

            GrapeCity.ActiveReports

        5.将appsettings.json文件添加到项目中

        6.替换以下内容:
             myaccount和您的存储帐户名
             StorageAccountKeyEndingIn ==与您的存储帐户密钥
             使用您的共享名的myshare

{ "connectionString": "DefaultEndpointsProtocol=https;AccountName=myaccount;AccountKey=StorageAccountKeyEndingIn==;EndpointSuffix=core.windows.net", "share": "myshare" }

         7.将AzureReportsStorage.cs文件添加到项目中
         8.复制并粘贴以下类声明:
(此类封装了从Azure文件存储获取的 告内容)

public class AzureReportsStorage {          private Microsoft.Azure.Storage.File.CloudFileShare _share;          public AzureReportsStorage(string connString, string shareName)          {                  var storageAccount = Microsoft.Azure.Storage.CloudStorageAccount.Parse(connString);                  // Create a CloudFileClient object for credentialed access to Azure Files.                  var fileClient = storageAccount.CreateCloudFileClient();                  // Get a reference to the file share we created previously.                  this._share = fileClient.GetShareReference(shareName);          }         public GrapeCity.ActiveReports.PageReportModel.Report GetReport(string fileName)         {             if (this._share.Exists())             {                 // Get a reference to the root directory for the share.                 Microsoft.Azure.Storage.File.CloudFileDirectory rootDir = _share.GetRootDirectoryReference();                // Ensure that the directory exists.                 if (rootDir.Exists())                 {                     // Get a reference to the file we created previously.                     Microsoft.Azure.Storage.File.CloudFile file = rootDir.GetFileReference(fileName);                    // Ensure that the file exists.                     if (file.Exists())                     {                         var ms = new System.IO.MemoryStream();                         file.DownloadToStream(ms);                         ms.Position = 0;                         using (var reader = new System.IO.StreamReader(ms))                         {                             var rep =  new GrapeCity.ActiveReports.PageReport(reader);                             return rep.Report;                         }                     }                     else                     {                         return null;                     }                 }                 else                 {                     return null;                 }            }             else             {                 return null;             }         }}

         9.在Startup.cs文件中修改Startup构造函数,以便它接受IConfiguration实例并通过传递从appsettings.json中读取连接字符串和共享名来初始化AzureReportsStorage类的实例:

private AzureReportsStorage _storage; public Startup(IConfiguration configuration) {         _storage = new AzureReportsStorage(configuration["connectionString"], configuration["share"]); }

           10.修改Startup.Configure方法的代码,以便 告服务从云存储获取 告
 UseCustomStore方法使您可以设置任何类型的 告存储。此代码调用  AzureReportsStorage.getReport:

app.UseReporting(settings => {     // settings.UseEmbeddedTemplates(EmbeddedReportsPrefix, Assembly.GetAssembly(GetType()));     settings.UseCustomStore((reportName) =>     {            return this._storage.GetReport(reportName);     });     settings.UseCompression = true; });

         11.打开wwwroot index.html文件
         12.替换viewer.openReport(“ RdlReport1.rdlx”)行中的“ Report1.rdlx”; 在第二步中将 告名称上传到云文件共享中
         13.运行项目,并确保正确显示 告内容

如果你对我们的产品感兴趣或者有任何疑问,欢迎咨询在线客服>>

标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年6月10日
下一篇 2020年6月10日

相关推荐

发表回复

登录后才能评论