diff --git a/Services/DataVisService.cs b/Services/DataVisService.cs index 235c52a..0552767 100644 --- a/Services/DataVisService.cs +++ b/Services/DataVisService.cs @@ -1,59 +1,62 @@ -using ExpressBase.Common; +using DocumentFormat.OpenXml; +using DocumentFormat.OpenXml.Drawing; +using DocumentFormat.OpenXml.Packaging; +using DocumentFormat.OpenXml.Spreadsheet; +using ExpressBase.Common; using ExpressBase.Common.Constants; using ExpressBase.Common.Data; +using ExpressBase.Common.EbServiceStack.ReqNRes; +using ExpressBase.Common.Extensions; +using ExpressBase.Common.Helpers; +using ExpressBase.Common.LocationNSolution; using ExpressBase.Common.Objects; +using ExpressBase.Common.ServiceClients; +using ExpressBase.Common.Singletons; using ExpressBase.Common.Structures; +using ExpressBase.Common.WebApi.RequestNResponse; +using ExpressBase.CoreBase.Globals; using ExpressBase.Data; using ExpressBase.Objects; +using ExpressBase.Objects.Helpers; using ExpressBase.Objects.Objects; using ExpressBase.Objects.Objects.DVRelated; using ExpressBase.Objects.ServiceStack_Artifacts; +using ExpressBase.Objects.WebFormRelated; using ExpressBase.Security; +using ExpressBase.ServiceStack.MQServices; +using ExpressBase.ServiceStack.Services; +using Microsoft.AspNetCore.Hosting; +using Microsoft.AspNetCore.Mvc; using Microsoft.CodeAnalysis.CSharp.Scripting; using Microsoft.CodeAnalysis.Scripting; +using Microsoft.Extensions.Hosting; +using Newtonsoft.Json; +using OfficeOpenXml; using ServiceStack; using ServiceStack.Logging; using ServiceStack.Redis; using System; using System.Collections.Generic; using System.Data; +using System.Drawing; +using System.Drawing.Imaging; +using System.Dynamic; using System.Globalization; using System.IdentityModel.Tokens.Jwt; +using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; -using OfficeOpenXml; -using System.IO; -using Newtonsoft.Json; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Hosting; using System.Threading.Tasks; -using ExpressBase.Common.Extensions; -using ExpressBase.Common.Singletons; -using ExpressBase.Common.Helpers; -using ExpressBase.Common.LocationNSolution; -using System.Dynamic; -using ExpressBase.ServiceStack.Services; -using ExpressBase.Common.EbServiceStack.ReqNRes; -using System.Drawing; -using ExpressBase.Common.ServiceClients; -using ExpressBase.Objects.Helpers; -using DocumentFormat.OpenXml.Packaging; -using DocumentFormat.OpenXml; -using DocumentFormat.OpenXml.Drawing; -using DocumentFormat.OpenXml.Spreadsheet; using A = DocumentFormat.OpenXml.Drawing; -using Xdr = DocumentFormat.OpenXml.Drawing.Spreadsheet; using A14 = DocumentFormat.OpenXml.Office2010.Drawing; -using System.Drawing.Imaging; +using Color = DocumentFormat.OpenXml.Spreadsheet.Color; +using Fill = DocumentFormat.OpenXml.Spreadsheet.Fill; using Font = DocumentFormat.OpenXml.Spreadsheet.Font; using Fonts = DocumentFormat.OpenXml.Spreadsheet.Fonts; -using Fill = DocumentFormat.OpenXml.Spreadsheet.Fill; -using Color = DocumentFormat.OpenXml.Spreadsheet.Color; -using ExpressBase.Objects.WebFormRelated; -using ExpressBase.CoreBase.Globals; -using ExpressBase.ServiceStack.MQServices; +using ImageQuality = ExpressBase.Common.ImageQuality; +using ResponseStatus = ServiceStack.ResponseStatus; +using Xdr = DocumentFormat.OpenXml.Drawing.Spreadsheet; namespace ExpressBase.ServiceStack { @@ -1592,7 +1595,7 @@ public void ProcessDataRow4Excel(EbDataRow row, EbDataVisualization _dv, Culture workRow.CustomHeight = true; if (imgid > 0) { - Stream imageStream = GetImageStream(imgid); + Stream imageStream = GetImageStream(imgid, _user); if (imageStream != null) InsertImage(worksheetPart1, rowIndex - 1, ExcelColIndex - 1, imageStream); } @@ -2603,7 +2606,7 @@ public void DataTable2FormatedTable(EbDataRow row, EbDataVisualization _dv, Cult { Log.Info("dprefid----" + imgid); //byte[] bytea = GetImage(imgid); - Stream imageStream = GetImageStream(imgid); + Stream imageStream = GetImageStream(imgid, _user); if (imageStream != null) InsertImage(worksheetPart1, rowIndex - 1, ExcelColIndex - 1, imageStream); //if (bytea.Length > 0) @@ -2907,7 +2910,7 @@ public void DataTable2FormatedTable4Excel(EbDataRow row, EbDataVisualization _dv workRow.CustomHeight = true; if (imgid > 0) { - Stream imageStream = GetImageStream(imgid); + Stream imageStream = GetImageStream(imgid, _user); if (imageStream != null) InsertImage(worksheetPart1, rowIndex - 1, ExcelColIndex - 1, imageStream); } @@ -3113,12 +3116,23 @@ private int GetNextRelationShipID() return nextId; } - private byte[] GetImage(int refId) + private byte[] GetImage(int refId, User currentUser) { - DownloadFileResponse dfs; - byte[] fileByte = new byte[0]; - dfs = FileClient.Get + + if (this._ebSolution.SolutionSettings.EnableNewFileServer) + { + DownloadFileResponse2 response = this.FileClient2.DownloadFile(new ImageMeta + { + FileRefId = refId, + FileCategory = Common.Enums.EbFileCategory.Images + }, "/download/image", this._ebSolution.SolutionID, 0, null, ImageQuality.original, true); + + fileByte = response?.FileBytes; + } + else + { + DownloadFileResponse dfs = FileClient.Get (new DownloadImageByIdRequest { ImageInfo = new ImageMeta @@ -3127,19 +3141,30 @@ private byte[] GetImage(int refId) FileCategory = Common.Enums.EbFileCategory.Images } }); - if (dfs.StreamWrapper != null) - { - dfs.StreamWrapper.Memorystream.Position = 0; - fileByte = dfs.StreamWrapper.Memorystream.ToBytes(); + if (dfs.StreamWrapper != null) + { + dfs.StreamWrapper.Memorystream.Position = 0; + fileByte = dfs.StreamWrapper.Memorystream.ToBytes(); + } } - return fileByte; } - private Stream GetImageStream(int refId) + private Stream GetImageStream(int refId, User currentUser) { - DownloadFileResponse dfs; - dfs = FileClient.Get + if (this._ebSolution.SolutionSettings.EnableNewFileServer) + { + DownloadFileResponse2 response = this.FileClient2.DownloadFile(new ImageMeta + { + FileRefId = refId, + FileCategory = Common.Enums.EbFileCategory.Images + }, "/download/image", this._ebSolution.SolutionID, 0, null, ImageQuality.original, true); + + return new MemoryStream(response?.FileBytes); + } + else + { + DownloadFileResponse dfs = FileClient.Get (new DownloadImageByIdRequest { ImageInfo = new ImageMeta @@ -3148,12 +3173,12 @@ private Stream GetImageStream(int refId) FileCategory = Common.Enums.EbFileCategory.Images } }); - if (dfs.StreamWrapper != null) - { - dfs.StreamWrapper.Memorystream.Position = 0; - return dfs.StreamWrapper.Memorystream; + if (dfs.StreamWrapper != null) + { + dfs.StreamWrapper.Memorystream.Position = 0; + return dfs.StreamWrapper.Memorystream; + } } - return null; } diff --git a/Services/MobileServices.cs b/Services/MobileServices.cs index 3f2be74..814fc9b 100644 --- a/Services/MobileServices.cs +++ b/Services/MobileServices.cs @@ -1,25 +1,28 @@ -using ExpressBase.Common; +using DocumentFormat.OpenXml.Vml; +using ExpressBase.Common; +using ExpressBase.Common.Application; using ExpressBase.Common.Constants; using ExpressBase.Common.Data; +using ExpressBase.Common.EbServiceStack.ReqNRes; +using ExpressBase.Common.Extensions; +using ExpressBase.Common.LocationNSolution; using ExpressBase.Common.Objects; +using ExpressBase.Common.ServiceClients; using ExpressBase.Common.Structures; +using ExpressBase.Common.WebApi.RequestNResponse; using ExpressBase.Objects; +using ExpressBase.Objects.Helpers; using ExpressBase.Objects.ServiceStack_Artifacts; +using ExpressBase.Objects.WebFormRelated; +using ExpressBase.Security; +using Newtonsoft.Json; +using ServiceStack; using ServiceStack.Messaging; using System; using System.Collections.Generic; -using System.Linq; -using ExpressBase.Security; -using ExpressBase.Common.Extensions; using System.Data.Common; -using ExpressBase.Common.Application; -using Newtonsoft.Json; -using ServiceStack; -using ExpressBase.Objects.Helpers; -using ExpressBase.Common.LocationNSolution; -using ExpressBase.Common.ServiceClients; -using ExpressBase.Common.EbServiceStack.ReqNRes; -using ExpressBase.Objects.WebFormRelated; +using System.IO; +using System.Linq; using System.Text.RegularExpressions; namespace ExpressBase.ServiceStack.Services @@ -29,6 +32,9 @@ public class MobileServices : EbBaseService { const string EBPARAM_LOCID = "eb_loc_id"; + private Eb_Solution CurrentSolution = null; + private User CurrentUser = null; + public MobileServices(IEbConnectionFactory _dbf, IEbStaticFileClient _sfc, IMessageProducer _mqp) : base(_dbf, _sfc, _mqp) { } Dictionary Images = new Dictionary(); @@ -270,8 +276,8 @@ private T GetEbObject(string ebRefId) public EbMobileSolutionData Post(MobileSolutionDataRequestV2 request) { EbMobileSolutionData data = new EbMobileSolutionData(); - data.CurrentUser = this.GetUserObject(request.UserAuthId); - data.CurrentSolution = this.GetSolutionObject(request.SolnId); + this.CurrentUser = data.CurrentUser = this.GetUserObject(request.UserAuthId); + this.CurrentSolution = data.CurrentSolution = this.GetSolutionObject(request.SolnId); Dictionary metaData = JsonConvert.DeserializeObject>(request.MetaData); DateTime date = metaData.ContainsKey("last_sync_ts") ? Convert.ToDateTime(metaData["last_sync_ts"]) : DateTime.MinValue; @@ -467,24 +473,35 @@ public void FetchImages(List fields) public byte[] GetImage(int refId) { - DownloadFileResponse dfs = null; - byte[] fileByte = new byte[0]; - dfs = FileClient.Get - (new DownloadImageByIdRequest - { - ImageInfo = new ImageMeta - { - FileRefId = refId, - FileCategory = Common.Enums.EbFileCategory.Images - } - }); - if (dfs.StreamWrapper != null) + + if (this.CurrentSolution.SolutionSettings.EnableNewFileServer) { - dfs.StreamWrapper.Memorystream.Position = 0; - fileByte = dfs.StreamWrapper.Memorystream.ToBytes(); - } + DownloadFileResponse2 response = this.FileClient2.DownloadFile(new ImageMeta + { + FileRefId = refId, + FileCategory = Common.Enums.EbFileCategory.Images + }, "/download/image", this.CurrentSolution.SolutionID, 0, null, ImageQuality.original, true); + fileByte = response?.FileBytes; + } + else + { + DownloadFileResponse dfs = FileClient.Get + (new DownloadImageByIdRequest + { + ImageInfo = new ImageMeta + { + FileRefId = refId, + FileCategory = Common.Enums.EbFileCategory.Images + } + }); + if (dfs.StreamWrapper != null) + { + dfs.StreamWrapper.Memorystream.Position = 0; + fileByte = dfs.StreamWrapper.Memorystream.ToBytes(); + } + } return fileByte; } diff --git a/Services/ReportService.cs b/Services/ReportService.cs index 524c31c..baff420 100644 --- a/Services/ReportService.cs +++ b/Services/ReportService.cs @@ -32,7 +32,7 @@ namespace ExpressBase.ServiceStack public class ReportService : EbBaseService { //private iTextSharp.text.Font f = FontFactory.GetFont(FontFactory.HELVETICA, 12); - public ReportService(IEbConnectionFactory _dbf, IEbStaticFileClient _sfc, IMessageProducer _mqp, IMessageQueueClient _mqc, PooledRedisClientManager pooledRedisManager) : base(_dbf, _sfc, _mqp, _mqc, pooledRedisManager) { } + public ReportService(IEbConnectionFactory _dbf, IEbStaticFileClient _sfc, IMessageProducer _mqp, IMessageQueueClient _mqc, PooledRedisClientManager pooledRedisManager, EbStaticFileClient2 _sfc2) : base(_dbf, _sfc, _mqp, _mqc, pooledRedisManager, _sfc2) { } public MemoryStream Ms1 = null; @@ -61,6 +61,7 @@ public ReportRenderResponse Get(ReportRenderRequest request) Report.Redis = this.Redis; Report.pooledRedisManager = this.PooledRedisManager; Report.FileClient = this.FileClient; + Report.FileClient2 = this.FileClient2; Report.Solution = GetSolutionObject(request.SolnId); Report.ReadingUser = GetUserObject(request.ReadingUserAuthId); Report.RenderingUser = GetUserObject(request.RenderingUserAuthId); @@ -128,6 +129,7 @@ public ReportRenderMultipleSyncResponse Get(ReportRenderMultipleSyncRequest requ reportObject.ObjectsDB = this.EbConnectionFactory.ObjectsDB; reportObject.Redis = this.Redis; reportObject.FileClient = this.FileClient; + reportObject.FileClient2 = this.FileClient2; reportObject.Solution = GetSolutionObject(request.SolnId); reportObject.ReadingUser = GetUserObject(request.RenderingUserAuthId); reportObject.RenderingUser = reportObject.ReadingUser; diff --git a/Startup.cs b/Startup.cs index a261ecc..be46e72 100644 --- a/Startup.cs +++ b/Startup.cs @@ -249,6 +249,7 @@ public override void Configure(Container container) container.Register(c => new EbServerEventClient()).ReusedWithin(ReuseScope.Request); container.Register(c => new EbMqClient()).ReusedWithin(ReuseScope.Request); container.Register(c => new EbStaticFileClient()).ReusedWithin(ReuseScope.Request); + container.Register(c => new EbStaticFileClient2(new HttpClient())); //Plugins.Add(new RedisServiceDiscoveryFeature());