@@ -125,60 +125,45 @@ public string GetReportFile(string reportDocumentId)
125
125
126
126
private string GetFile ( ReportDocument reportDocument )
127
127
{
128
- bool IsCompressionFile = false ;
129
- bool IsEncryptedFile = false ;
130
-
131
- if ( reportDocument . EncryptionDetails != null )
132
- IsEncryptedFile = true ;
133
- if ( reportDocument . CompressionAlgorithm != null && reportDocument . CompressionAlgorithm . HasValue && reportDocument . CompressionAlgorithm . Value == ReportDocument . CompressionAlgorithmEnum . GZIP )
134
- IsCompressionFile = true ;
128
+ bool isCompressionFile = false ;
129
+ bool isEncryptedFile = reportDocument . EncryptionDetails != null ;
135
130
131
+ if ( reportDocument . CompressionAlgorithm is ReportDocument . CompressionAlgorithmEnum . GZIP )
132
+ isCompressionFile = true ;
136
133
137
134
var client = new System . Net . WebClient ( ) ;
138
135
string fileName = Guid . NewGuid ( ) . ToString ( ) ;
139
-
140
136
141
- if ( IsCompressionFile )
137
+ if ( isCompressionFile )
142
138
{
143
139
client . Headers [ System . Net . HttpRequestHeader . AcceptEncoding ] = "gzip" ;
144
140
fileName += ".gz" ;
145
- } else fileName += ".txt" ;
141
+ }
142
+ else fileName += ".txt" ;
146
143
147
144
string tempFilePath = Path . Combine ( Path . GetTempPath ( ) + fileName ) ;
148
145
149
-
150
-
151
- if ( IsEncryptedFile )
146
+ if ( isEncryptedFile )
152
147
{
153
148
//Later will check
154
- //byte[] rawData = client.DownloadData(reportDocument.Url);
155
- //byte[] key = Convert.FromBase64String(reportDocument.EncryptionDetails.Key);
156
- //byte[] iv = Convert.FromBase64String(reportDocument.EncryptionDetails.InitializationVector);
157
- //var reportData = FileTransform.DecryptString(key, iv, rawData);
158
- //File.WriteAllText(tempFilePath, reportData);
159
- return tempFilePath ;
149
+ byte [ ] rawData = client . DownloadData ( reportDocument . Url ) ;
150
+ byte [ ] key = Convert . FromBase64String ( reportDocument . EncryptionDetails . Key ) ;
151
+ byte [ ] iv = Convert . FromBase64String ( reportDocument . EncryptionDetails . InitializationVector ) ;
152
+ var reportData = FileTransform . DecryptString ( key , iv , rawData ) ;
153
+ File . WriteAllText ( tempFilePath , reportData ) ;
160
154
}
161
155
else
162
156
{
163
-
164
157
var stream = client . OpenRead ( reportDocument . Url ) ;
165
- //var responseStream = new System.IO.Compression.GZipStream(rawData, System.IO.Compression.CompressionMode.Decompress);
166
158
using ( Stream s = File . Create ( tempFilePath ) )
167
159
{
168
- stream . CopyTo ( s ) ;
160
+ stream ? . CopyTo ( s ) ;
169
161
}
170
-
171
- return FileTransform . Decompress ( tempFilePath ) ;
172
- //SaveStreamToFile(tempFilePath, responseStream);
173
-
174
162
}
175
163
176
-
164
+ return isCompressionFile ? FileTransform . Decompress ( tempFilePath ) : tempFilePath ;
177
165
}
178
166
179
-
180
-
181
-
182
167
public void SaveStreamToFile ( string fileFullPath , Stream stream )
183
168
{
184
169
if ( stream . Length == 0 ) return ;
0 commit comments