@@ -94,10 +94,109 @@ public override List<CatalogItem> GetItems(string folderName, ItemTypeEnum type,
9494 _items . Add ( catalogItem ) ;
9595 }
9696 }
97+ else if ( type == ItemTypeEnum . File )
98+ {
99+ var dataSourceProvider = new Microsoft . Extensions . FileProviders . PhysicalFileProvider ( Path . Combine ( targetFolder , "Files" ) ) ;
100+ foreach ( var file in dataSourceProvider . GetDirectoryContents ( "" ) . Where ( f => ! f . IsDirectory ) )
101+ {
102+ CatalogItem catalogItem = new CatalogItem ( ) ;
103+ catalogItem . Name = Path . GetFileNameWithoutExtension ( file . Name ) ;
104+ catalogItem . Type = ItemTypeEnum . File ;
105+ catalogItem . Id = Regex . Replace ( catalogItem . Name , @"[^0-9a-zA-Z]+" , "_" ) ;
106+ catalogItem . Extension = Path . GetExtension ( file . Name ) ;
107+ _items . Add ( catalogItem ) ;
108+ }
109+ }
97110
98111 return _items ;
99112 }
100113
114+ public override BoldReports . RDL . DOM . Server . ItemDefinition GetItemDefinition ( string itemName )
115+ {
116+ try
117+ {
118+ if ( string . IsNullOrWhiteSpace ( Path . GetFileNameWithoutExtension ( itemName ) ) )
119+ return null ;
120+
121+ BoldReports . RDL . DOM . Server . ItemDefinition itemDefinition = new BoldReports . RDL . DOM . Server . ItemDefinition ( ) ;
122+ itemDefinition . FileContent = this . GetFileContent ( itemName ) ;
123+ itemDefinition . FilePassword = this . GetFilePassword ( itemName ) ;
124+ itemDefinition . Extension = Path . GetExtension ( itemName ) ;
125+
126+ return itemDefinition ;
127+ }
128+ catch ( Exception ex )
129+ {
130+ throw new InvalidOperationException ( $ "Unable to load the report resource '{ itemName } '. Please check the resource name and ensure the file exists", ex ) ;
131+ }
132+
133+ return null ;
134+ }
135+
136+ private string GetFilePassword ( string itemName )
137+ {
138+ if ( itemName . EndsWith ( ".pfx" , StringComparison . OrdinalIgnoreCase ) )
139+ {
140+ string passwordFile = Path . Combine ( this . basePath , "resources" , "Files" , "CertificateCredentials.xml" ) ;
141+
142+ if ( File . Exists ( passwordFile ) )
143+ {
144+ XmlDocument xml = new XmlDocument ( ) ;
145+ xml . Load ( passwordFile ) ;
146+
147+ foreach ( XmlNode certNode in xml . SelectNodes ( "//CertificateCredentials/Certificate" ) )
148+ {
149+ if ( certNode == null )
150+ continue ;
151+
152+ string name = certNode . SelectSingleNode ( "name" ) ? . InnerText ? . Trim ( ) ?? string . Empty ;
153+ string password = certNode . SelectSingleNode ( "password" ) ? . InnerText ? . Trim ( ) ;
154+
155+ if ( ! name . Equals ( Path . GetFileNameWithoutExtension ( itemName ) , StringComparison . OrdinalIgnoreCase ) )
156+ continue ;
157+ if ( ! string . IsNullOrEmpty ( password ) )
158+ {
159+ return password ;
160+ }
161+
162+ break ;
163+ }
164+ }
165+ }
166+
167+ return null ;
168+ }
169+
170+ private byte [ ] GetFileContent ( string itemName )
171+ {
172+ string imagePath = Path . Combine ( this . basePath , "resources" , itemName ) ;
173+ string [ ] fileExtensions = { ".pfx" , ".pdf" , ".html" } ;
174+
175+ if ( fileExtensions . Any ( extension => itemName . EndsWith ( extension , StringComparison . OrdinalIgnoreCase ) ) )
176+ {
177+ imagePath = Path . Combine ( this . basePath , "resources" , "Files" , itemName ) ;
178+ }
179+ if ( File . Exists ( imagePath ) )
180+ {
181+ using ( Stream stream = this . ReadFiles ( imagePath ) )
182+ {
183+ if ( stream == null )
184+ return null ;
185+
186+ using ( MemoryStream memoryStream = new MemoryStream ( ) )
187+ {
188+ stream . CopyTo ( memoryStream ) ;
189+ if ( memoryStream . Length == 0 )
190+ return null ;
191+
192+ return memoryStream . ToArray ( ) ;
193+ }
194+ }
195+ }
196+
197+ return null ;
198+ }
199+
101200 public override bool CreateReport ( string reportName , string folderName , byte [ ] reportdata , out string exception )
102201 {
103202 return base . CreateReport ( reportName , folderName , reportdata , out exception ) ;
0 commit comments