@@ -125,60 +125,45 @@ public string GetReportFile(string reportDocumentId)
125125
126126 private string GetFile ( ReportDocument reportDocument )
127127 {
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 ;
135130
131+ if ( reportDocument . CompressionAlgorithm is ReportDocument . CompressionAlgorithmEnum . GZIP )
132+ isCompressionFile = true ;
136133
137134 var client = new System . Net . WebClient ( ) ;
138135 string fileName = Guid . NewGuid ( ) . ToString ( ) ;
139-
140136
141- if ( IsCompressionFile )
137+ if ( isCompressionFile )
142138 {
143139 client . Headers [ System . Net . HttpRequestHeader . AcceptEncoding ] = "gzip" ;
144140 fileName += ".gz" ;
145- } else fileName += ".txt" ;
141+ }
142+ else fileName += ".txt" ;
146143
147144 string tempFilePath = Path . Combine ( Path . GetTempPath ( ) + fileName ) ;
148145
149-
150-
151- if ( IsEncryptedFile )
146+ if ( isEncryptedFile )
152147 {
153148 //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 ) ;
160154 }
161155 else
162156 {
163-
164157 var stream = client . OpenRead ( reportDocument . Url ) ;
165- //var responseStream = new System.IO.Compression.GZipStream(rawData, System.IO.Compression.CompressionMode.Decompress);
166158 using ( Stream s = File . Create ( tempFilePath ) )
167159 {
168- stream . CopyTo ( s ) ;
160+ stream ? . CopyTo ( s ) ;
169161 }
170-
171- return FileTransform . Decompress ( tempFilePath ) ;
172- //SaveStreamToFile(tempFilePath, responseStream);
173-
174162 }
175163
176-
164+ return isCompressionFile ? FileTransform . Decompress ( tempFilePath ) : tempFilePath ;
177165 }
178166
179-
180-
181-
182167 public void SaveStreamToFile ( string fileFullPath , Stream stream )
183168 {
184169 if ( stream . Length == 0 ) return ;
0 commit comments