private bool TrySaveToFile(Stream result, string sourceFile, string destinationFile) { try { string contents; var encoding = TransformUtilities.GetEncoding(sourceFile); using (StreamReader reader = new StreamReader(result, true)) { // Get the contents of the result stram contents = reader.ReadToEnd(); } // Make sure to save it in the encoding of the result stream File.WriteAllText(destinationFile, contents, encoding); return(true); } catch (Exception ex) { this.logger.LogErrorFromException(ex); return(false); } }
/// <inheritdoc/> public void CreateTransformFile(string sourcePath, string transformPath, bool overwrite) { if (string.IsNullOrWhiteSpace(sourcePath)) { throw new ArgumentNullException(nameof(sourcePath)); } if (string.IsNullOrWhiteSpace(transformPath)) { throw new ArgumentNullException(nameof(transformPath)); } if (!File.Exists(sourcePath)) { throw new FileNotFoundException(Resources.Resources.ErrorMessage_SourceFileNotFound, sourcePath); } // If the file should be overwritten or if it doesn't exist, we create it if (overwrite || !File.Exists(transformPath)) { var encoding = TransformUtilities.GetEncoding(sourcePath); File.WriteAllText(transformPath, Resources.Resources.JsonTransform_TransformFileContents, encoding); } }