public void LoadAsUtf8SaveToUtf8(string subFilePath) { var filePath = TestContext.CurrentContext.WorkDirectory + subFilePath .Replace('/', Path.DirectorySeparatorChar); using var tmpFile = new TempFile(); var text = FileEncoding.ReadAllText(filePath, Encoding.UTF8); FileEncoding.WriteAllText(tmpFile.Path, text, Encoding.UTF8); var expectedResultPath = TestContext.CurrentContext.WorkDirectory + "/TestFiles/LargeFiles/L_UTF-8-BOM.txt" .Replace('/', Path.DirectorySeparatorChar); Assert.IsTrue(IOTools.FileCompare(expectedResultPath, tmpFile.Path)); }
public void LoadAsUnicodeSaveToISO_8859_1(string subFilePath) { var filePath = TestContext.CurrentContext.WorkDirectory + subFilePath .Replace('/', Path.DirectorySeparatorChar); using var tmpFile = new TempFile(); var text = FileEncoding.ReadAllText(filePath, Encoding.Unicode); FileEncoding.WriteAllText(tmpFile.Path, text, AdditionalEncoding.ISO_8859_1); var expectedResultPath = TestContext.CurrentContext.WorkDirectory + "/TestFiles/LargeFiles/L_ISO-8859-1.txt" .Replace('/', Path.DirectorySeparatorChar); Assert.IsTrue(IOTools.FileCompare(expectedResultPath, tmpFile.Path)); }
/// <summary> /// Saves information from the card to the file with specified file name. /// </summary> /// <param name="fileName">Name of the file.</param> /// <param name="format">The format.</param> /// <param name="encoding">The encoding.</param> /// <returns></returns> public bool Save(string fileName, ExportFormat format, FileEncoding encoding) { switch (encoding) { case FileEncoding.Ansi: switch (format) { case ExportFormat.Csv: return(NativeMethods.SavePersonToCsvExAnsi(reader.Index, fileName)); case ExportFormat.Xml: return(NativeMethods.SaveCardToXmlExAnsi(reader.Index, fileName)); default: return(false); } case FileEncoding.Utf16: switch (format) { case ExportFormat.Csv: return(NativeMethods.SavePersonToCsvEx(reader.Index, fileName)); case ExportFormat.Xml: return(NativeMethods.SaveCardToXmlEx(reader.Index, fileName)); default: return(false); } case FileEncoding.Utf8: switch (format) { case ExportFormat.Csv: return(SavePersonToCsvExUtf8(fileName)); case ExportFormat.Xml: return(SaveCardToXmlExUtf8(fileName)); default: return(false); } default: return(false); } }
public bool Load() { if (!File.Exists(FileName)) { return(false); } try { Sections.Clear(); using (var fileData = new StreamReader(FileName, FileEncoding, true)) { string firstLine = null; while (string.IsNullOrEmpty(firstLine) && !fileData.EndOfStream) { firstLine = fileData.ReadLine(); } if (!FileEncoding.Equals(Encoding.Unicode) && !FileEncoding.Equals(Encoding.BigEndianUnicode) && EncodingDetector.IsUnicode(firstLine)) { FileEncoding = Encoding.Unicode; } else { FileEncoding = fileData.CurrentEncoding; } fileData.Close(); } using (var fileData = new StreamReader(FileName, FileEncoding, true)) { LoadContent(fileData); fileData.Close(); } return(true); } catch (IOException ex) { System.Diagnostics.Trace.TraceError(ex.Message); return(false); } }
private void IndexFile(string filePath, IFileVersion version) { try { _eventReactor.React(EngineEvent.FileIndexingStarted, filePath); var encoding = FileEncoding.DetectFileEncoding(filePath); var words = _parserProvider.Provide(filePath).Parse(version, encoding); _index.Add(version, words); _eventReactor.React(EngineEvent.FileIndexingEnded, filePath); } catch (Exception exception) { _eventReactor.React(EngineEvent.FileIndexingEnded, filePath, exception); } }
public static void ToBigEndian32(Stream source, Stream output, FileEncoding sourceEncoding) { Endian.Order sourceEndian; Endian.Order outEndian; switch (sourceEncoding) { case FileEncoding.BigEndian32: sourceEndian = Endian.Order.Big32; outEndian = Endian.Order.Big32; break; case FileEncoding.HalfwordSwap: sourceEndian = Endian.Order.Big16; outEndian = Endian.Order.Big32; break; case FileEncoding.LittleEndian16: sourceEndian = Endian.Order.Little16; outEndian = Endian.Order.Big16; break; case FileEncoding.LittleEndian32: sourceEndian = Endian.Order.Little32; outEndian = Endian.Order.Big32; break; default: throw new ArgumentOutOfRangeException(); } ConvertData(source, sourceEndian, output, outEndian); }
static void AppendLine(FileEncoding encoding, LineEndingsMode mode, byte[] new_bytes, ref int new_bytes_index) { switch (mode) { case LineEndingsMode.LineFeed: if (encoding == FileEncoding.Utf16BigEndian) { new_bytes[new_bytes_index++] = 0; new_bytes[new_bytes_index++] = ByteLineFeed; } else if (encoding == FileEncoding.Utf16LittleEndian) { new_bytes[new_bytes_index++] = ByteLineFeed; new_bytes[new_bytes_index++] = 0; } else { new_bytes[new_bytes_index++] = ByteLineFeed; } break; case LineEndingsMode.CarriageReturnLineFeed: if (encoding == FileEncoding.Utf16BigEndian) { new_bytes[new_bytes_index++] = 0; new_bytes[new_bytes_index++] = ByteCarriageReturn; new_bytes[new_bytes_index++] = 0; new_bytes[new_bytes_index++] = ByteLineFeed; } else if (encoding == FileEncoding.Utf16LittleEndian) { new_bytes[new_bytes_index++] = ByteCarriageReturn; new_bytes[new_bytes_index++] = 0; new_bytes[new_bytes_index++] = ByteLineFeed; new_bytes[new_bytes_index++] = 0; } else { new_bytes[new_bytes_index++] = ByteCarriageReturn; new_bytes[new_bytes_index++] = ByteLineFeed; } break; } }
private void SaveFileEncodings() { string encodings = string.Empty; if (lstFiles.Items.Count > 0) { var fileEncodings = new List <FileEncoding>(); foreach (ListViewItem item in lstFiles.Items) { var encoding = item.Tag as FileEncoding; encoding.Enabled = item.Checked; fileEncodings.Add(encoding); } encodings = FileEncoding.ConvertFileEncodingsToString(fileEncodings); } GeneralSettings.FileEncodings = encodings; }
public override bool Search(string searchString) { var bytes = System.IO.File.ReadAllBytes(Path); var pattern = FileEncoding.GetBytes(searchString); var index1 = SearchHelper.SearchPattern(bytes, pattern, 0); var index2 = -1; if (HasChanges) { bytes = System.IO.File.ReadAllBytes(ChangesFile); pattern = Encoding.Unicode.GetBytes(searchString); index2 = SearchHelper.SearchPattern(bytes, pattern, 0); } return(index1 != -1 || index2 != -1); }
private void LoadFileEncodings() { var fileEncodings = FileEncoding.ConvertStringToFileEncodings(GeneralSettings.FileEncodings); if (fileEncodings != null && fileEncodings.Count > 0) { lstFiles.BeginUpdate(); foreach (var file in fileEncodings) { var item = GetFileEncodingListViewItem(file); lstFiles.Items.Add(item); } lstFiles.EndUpdate(); } SetFileEncodingButtonState(); }
public EditorIniData Read(FileEncoding encoding, int templateFileIndex) { #if DEBUG Stopwatch st = new Stopwatch(); st.Start(); #endif List <IniBlock> iniData; // read basic file structure if (encoding == FileEncoding.Automatic || encoding == FileEncoding.Bini) { this.IsBini = true; BiniManager biniManager = new BiniManager(this.File); if (biniManager.Read()) { iniData = biniManager.Data; } else { if (encoding == FileEncoding.Automatic) { iniData = this.ReadIni(); } else { return(null); } } } else { iniData = this.ReadIni(); } #if DEBUG st.Stop(); Debug.WriteLine("load data: " + st.ElapsedMilliseconds + "ms"); #endif return(GetEditorData(iniData, templateFileIndex)); }
public override bool Search(string searchString) { var encryptedBytes = File.ReadAllBytes(Path); var bytes = EncryptionManager.DecryptData(encryptedBytes); var pattern = FileEncoding.GetBytes(searchString.ToFullWidthChars()); var index1 = SearchHelper.SearchPattern(bytes, pattern, 0); var index2 = -1; if (HasChanges) { bytes = File.ReadAllBytes(ChangesFile); pattern = System.Text.Encoding.Unicode.GetBytes(searchString); index2 = SearchHelper.SearchPattern(bytes, pattern, 0); } return(index1 != -1 || index2 != -1); }
/// <summary> /// CSV转换成DataTable(文件流方式) /// </summary> /// <param name="csvPath">csv文件路径</param> /// <returns></returns> public static DataTable CsvToDataTableByStreamReader(string csvPath) { var csvdt = new DataTable("csv"); var intColCount = 0; var blnFlag = true; DataColumn column; DataRow row; string strline = null; string[] aryline; using (var reader = new StreamReader(csvPath, FileEncoding.GetEncoding(csvPath))) { while (!string.IsNullOrEmpty((strline = reader.ReadLine()))) { aryline = strline.Split(new char[] { ',' }); if (blnFlag) { blnFlag = false; intColCount = aryline.Length; for (var i = 0; i < aryline.Length; i++) { column = new DataColumn(aryline[i]); csvdt.Columns.Add(column); } continue; } row = csvdt.NewRow(); for (var i = 0; i < intColCount; i++) { row[i] = aryline[i]; } csvdt.Rows.Add(row); } } return(csvdt); }
private async Task <List <ConvertFile> > GetAllFiles(string[] fileOrDirectories) { var files = new List <ConvertFile>(); foreach (var fileOrDirectory in fileOrDirectories) { var fileAttributes = File.GetAttributes(fileOrDirectory); if ((fileAttributes & FileAttributes.Directory) == FileAttributes.Directory) { var subFiles = Directory.GetFiles(fileOrDirectory); files.AddRange(await GetAllFiles(subFiles)); } else { var fileInfo = new FileInfo(fileOrDirectory); byte[] buffer = new byte[fileInfo.Length > DetectSize ? DetectSize : fileInfo.Length]; using (var fileStream = new FileStream(fileOrDirectory, FileMode.Open)) { await fileStream.ReadAsync(buffer, 0, buffer.Length); } var checkForTextualData = FileEncoding.CheckForTextualData(buffer); if (!checkForTextualData) { Console.WriteLine("not text"); } else { var detectFileEncoding = FileEncoding.DetectFileEncoding(buffer, 0, buffer.Length); var convertFile = new ConvertFile { Encoding = detectFileEncoding, FileInfo = fileInfo }; files.Add(convertFile); } } } return(files); }
/// <summary> /// Verify the interface values are valid. /// </summary> /// <returns>FileEncoding object based on inputs, null if not valid (displays message to user)</returns> /// <history> /// [Curtis_Beard] 02/09/2015 CHG: 92, support for specific file encodings /// </history> private FileEncoding VerifyInterface() { if (string.IsNullOrEmpty(txtFile.Text) || !System.IO.File.Exists(txtFile.Text)) { MessageBox.Show(this, "Please select a valid file.", ProductInformation.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(null); } if (cboEncodings.SelectedItem == null) { MessageBox.Show(this, "Please select an encoding.", ProductInformation.ApplicationName, MessageBoxButtons.OK, MessageBoxIcon.Exclamation); return(null); } FileEncoding file = new FileEncoding(); file.Enabled = true; file.FilePath = txtFile.Text; file.Encoding = Encoding.GetEncoding((int)cboEncodings.SelectedValue); return(file); }
public VmdHeader(BinaryReader reader) { byte[] buf; buf = reader.ReadBytes(26); headerString = FileEncoding.GetString(buf, 0, Array.IndexOf(buf, (byte)0)); padding = reader.ReadBytes(4); if (headerString == "Vocaloid Motion Data file") { pmdModelNameLength = 10; } else { pmdModelNameLength = 20; } buf = reader.ReadBytes(pmdModelNameLength); pmdModelName = FileEncoding.GetString(buf, 0, Array.IndexOf(buf, (byte)0)); pmdModelName = NameDictionary.ToEnglish(pmdModelName); }
public override bool Search(string searchString, string path = "") { if (string.IsNullOrEmpty(path)) { path = Path; } var encryptedBytes = File.ReadAllBytes(path); var bytes = EncryptionManager.DecryptData(encryptedBytes); var pattern = FileEncoding.GetBytes(searchString.ToFullWidthChars()); var encodedPattern = new byte[pattern.Length]; using (var ms = new MemoryStream(pattern)) using (var br = new BinaryReader(ms)) using (var ms2 = new MemoryStream(encodedPattern)) using (var bw = new BinaryWriter(ms2)) { while (br.BaseStream.Position < br.BaseStream.Length) { var chr = br.ReadUInt16(); bw.Write((ushort)(chr + 128)); } } var searchHelper = new SearchHelper(encodedPattern); var index1 = searchHelper.Search(bytes); var index2 = -1; if (HasChanges) { bytes = File.ReadAllBytes(ChangesFile); pattern = System.Text.Encoding.Unicode.GetBytes(searchString); searchHelper = new SearchHelper(pattern); index2 = searchHelper.Search(bytes); } return(index1 != -1 || index2 != -1); }
private static void SwapRom(string[] args) { string inRom; string outRom; string swap; FileEncoding fileEncoding = FileEncoding.Error; if (args.Length != 3) { return; } inRom = args[0]; outRom = args[1]; swap = args[2]; if (!FileExists(inRom)) { return; } switch (swap.ToLower()) { case "little16": fileEncoding = FileEncoding.LittleEndian16; break; case "little32": fileEncoding = FileEncoding.LittleEndian32; break; //case "": default: return; } using (FileStream fs = new FileStream(inRom, FileMode.Open, FileAccess.Read)) { using (FileStream fw = new FileStream(outRom, FileMode.Create)) { FileOrder.ToBigEndian32(fs, fw, fileEncoding); } } }
public VmdBoneFrame(BinaryReader reader) { byte[] buf = reader.ReadBytes(15); boneName = FileEncoding.GetString(buf, 0, Array.IndexOf(buf, (byte)0)); boneName = NameDictionary.ToEnglish(boneName); frameNumber = reader.ReadInt32(); float x, y, z, w; x = reader.ReadSingle(); y = reader.ReadSingle(); z = reader.ReadSingle(); position = new Vector3D(x, y, z); x = reader.ReadSingle(); y = reader.ReadSingle(); z = reader.ReadSingle(); w = reader.ReadSingle(); orientation = new Quaternion(x, y, z, w); padding = reader.ReadBytes(64); }
/// <summary> /// Returns Encoding /// </summary> /// <param name="optionsFileEncoding"></param> /// <param name="optionsEnableBom"></param> /// <param name="optionsEncodingInString"></param> /// <returns></returns> public static Encoding GetEncoding(FileEncoding optionsFileEncoding, bool optionsEnableBom, string optionsEncodingInString) { switch (optionsFileEncoding) { case FileEncoding.Other: return(Encoding.GetEncoding(optionsEncodingInString)); case FileEncoding.ASCII: return(Encoding.ASCII); case FileEncoding.ANSI: return(Encoding.Default); case FileEncoding.UTF8: return(optionsEnableBom ? new UTF8Encoding(true) : new UTF8Encoding(false)); case FileEncoding.Unicode: return(Encoding.Unicode); default: throw new ArgumentOutOfRangeException(optionsFileEncoding.ToString()); } }
//Dosya seçme ekranını açar ve sonrasında seçilen dosyayı uygulamaya aktarır. public void editorDosyaAc() { try { using (OpenFileDialog openFileDialog = new OpenFileDialog()) { openFileDialog.Title = "Bir Belge Aç"; openFileDialog.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Personal); openFileDialog.Filter = "Tüm Dosyalar (*.*)|*.*|Yaygın Belge Formatları|*.txt;*.rtf;*.log;*.c;*.cs;*.cpp;*.vb;*.java;*.js;*.jar;*.py;*.html;*.htm;*.xhtml;*.php;*.xml;*.xaml;*.ini;*.cmd;*.bat;*.v;*.sh"; openFileDialog.FilterIndex = 2; openFileDialog.RestoreDirectory = true; if (openFileDialog.ShowDialog() == DialogResult.OK) { //dosyanın dizinini evrensel bir değişkene ata dosyaDizinEvrensel = openFileDialog.FileName; //seçilen dosyanın uzantısını bul ve ona göre kodlama renklendirmesi uygula. dosyauzanti = Path.GetExtension(openFileDialog.FileName); //uzantıyı aldık örn: .txt | .xml editorDosyaTurBelirle(); //uzantıya göre dosyanın türünü belirle //seçilen dosyanın kodlanmasını bul (örn: UTF8 vs...) var encoding = FileEncoding.DetectFileEncoding(openFileDialog.FileName); //editör kısmına seçilen dosyadaki verileri yaz. scintilla1.Text = File.ReadAllText(openFileDialog.FileName, encoding); karakterkodlamaLabel.Text = encoding.BodyName.ToUpper(); //dosya içeriğini program belleğine yaz ve kaydetme durumu için karşılaştırmak üzere beklet dosyaKaydetOrj = scintilla1.Text; dosyaKaydetDurum = true; dosyaKaydetİlkDefaDurum = false; //editör imleç en sondaki harfa gitsin scintilla1.SelectionStart = scintilla1.Text.Length; } } } catch { MessageBox.Show("Dosya açılırken bir hata oluştu!", "Hata!", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public PmdBone(BinaryReader reader) { byte[] buf = reader.ReadBytes(20); name = FileEncoding.GetString(buf, 0, Array.IndexOf(buf, (byte)0)); name = NameDictionary.ToEnglish(name); for (int i = 0; i < data.Length; i++) { int v = reader.ReadUInt16(); if (v == UInt16.MaxValue) { v = -1; } data[i] = v; } kind = reader.ReadByte(); knum = reader.ReadUInt16(); for (int i = 0; i < pos.Length; i++) { pos[i] = reader.ReadSingle(); } }
private static bool ValidateBOM(FileEncoding value, byte[] data, int bomLength) { if (value == FileEncoding.UTF8_BOM) { return(PossiblyUTF8(data, bomLength)); } else if (value == FileEncoding.UTF16_LE_BOM) { return(PossiblyUTF16(data, bomLength, false)); } else if (value == FileEncoding.UTF16_BE_BOM) { return(PossiblyUTF16(data, bomLength, true)); } else if (value == FileEncoding.UCS4_LE_BOM) { return(PossiblyUCS4(data, bomLength, false)); } else if (value == FileEncoding.UCS4_BE_BOM) { return(PossiblyUCS4(data, bomLength, true)); } return(true); }
public File() { this.encodingField = FileEncoding.binary; }
public DetachedTimeStamp() { this.encodingField = FileEncoding.binary; }
public static UProject Load(string file, Encoding encoding = null) { var currentNoteIndex = 0; var version = UstVersion.Early; var currentBlock = UstBlock.None; string[] lines; try { if (encoding == null) { lines = File.ReadAllLines(file, FileEncoding.DetectFileEncoding(file)); } else { lines = File.ReadAllLines(file, encoding); } } catch (Exception e) { DocManager.Inst.ExecuteCmd(new UserMessageNotification(e.GetType().ToString() + "\n" + e.Message)); return(null); } var project = new UProject() { Resolution = 480, FilePath = file, Saved = false }; project.RegisterExpression(new IntExpression(null, "velocity", "VEL") { Data = 100, Min = 0, Max = 200 }); project.RegisterExpression(new IntExpression(null, "volume", "VOL") { Data = 100, Min = 0, Max = 200 }); project.RegisterExpression(new IntExpression(null, "gender", "GEN") { Data = 0, Min = -100, Max = 100 }); project.RegisterExpression(new IntExpression(null, "lowpass", "LPF") { Data = 0, Min = 0, Max = 100 }); project.RegisterExpression(new IntExpression(null, "highpass", "HPF") { Data = 0, Min = 0, Max = 100 }); project.RegisterExpression(new IntExpression(null, "accent", "ACC") { Data = 100, Min = 0, Max = 200 }); project.RegisterExpression(new IntExpression(null, "decay", "DEC") { Data = 0, Min = 0, Max = 100 }); var _track = new UTrack(); project.Tracks.Add(_track); _track.TrackNo = 0; var part = new UVoicePart() { TrackNo = 0, PosTick = 0 }; project.Parts.Add(part); var currentLines = new List <string>(); var currentTick = 0; UNote currentNote = null; foreach (var line in lines) { if (line.Trim().StartsWith(@"[#") && line.Trim().EndsWith(@"]")) { if (line.Equals(versionTag)) { currentBlock = UstBlock.Version; } else if (line.Equals(settingTag)) { currentBlock = UstBlock.Setting; } else { if (line.Equals(endTag)) { currentBlock = UstBlock.Trackend; } else { try { currentNoteIndex = int.Parse(line.Replace("[#", string.Empty).Replace("]", string.Empty)); } catch { DocManager.Inst.ExecuteCmd(new UserMessageNotification("Unknown ust format")); return(null); } currentBlock = UstBlock.Note; } if (currentLines.Count != 0) { currentNote = NoteFromUst(project.CreateNote(), currentLines, version); currentNote.PosTick = currentTick; if (!currentNote.Lyric.Replace("R", string.Empty).Replace("r", string.Empty).Equals(string.Empty)) { part.Notes.Add(currentNote); } currentTick += currentNote.DurTick; currentLines.Clear(); } } } else { if (currentBlock == UstBlock.Version) { if (line.StartsWith("UST Version")) { var v = line.Trim().Replace("UST Version", string.Empty); switch (v) { case "1.0": version = UstVersion.V1_0; break; case "1.1": version = UstVersion.V1_1; break; case "1.2": version = UstVersion.V1_2; break; default: version = UstVersion.Unknown; break; } } } if (currentBlock == UstBlock.Setting) { if (line.StartsWith("Tempo=")) { project.BPM = double.Parse(line.Trim().Replace("Tempo=", string.Empty)); if (project.BPM == 0) { project.BPM = 120; } } if (line.StartsWith("ProjectName=")) { project.Name = line.Trim().Replace("ProjectName=", string.Empty); } if (line.StartsWith("VoiceDir=")) { var singerpath = line.Trim().Replace("VoiceDir=", string.Empty); var singer = DocManager.Inst.GetSinger(singerpath); if (singer == null) { singer = new USinger() { Name = "", Path = singerpath }; } project.Singers.Add(singer); project.Tracks[0].Singer = singer; } } else if (currentBlock == UstBlock.Note) { currentLines.Add(line); } else if (currentBlock == UstBlock.Trackend) { break; } } } if (currentBlock != UstBlock.Trackend) { DocManager.Inst.ExecuteCmd(new UserMessageNotification("Unexpected ust file end")); } part.DurTick = currentTick; return(project); }
/// <summary> /// Writes a string as a byte array encoded in <see cref="MoIO.FileEncoding"/> with its length. /// </summary> /// <param name="value">The string to write</param> public void WriteVariableString(string value) { byte[] data = FileEncoding.GetBytes(value); _stream.Write((byte)data.Length); _stream.Write(data); }
/// <summary> /// Reads a byte array as a string encoded in <see cref="MoIO.FileEncoding"/>. /// </summary> /// <param name="bytesCount">The byte length to read</param> /// <returns>A string read and encoded in <see cref="MoIO.FileEncoding"/> from the stream</returns> public string ReadByteString(int bytesCount) { var b = _stream.ReadBytes(bytesCount); return(FileEncoding.GetString(b)); }
/// <summary> /// Initialized called by dotnet test. /// </summary> /// <param name="events">Test logger event.</param> /// <param name="parameters"> /// Dictionary of key value pairs provided by the user, semicolon delimited (i.e. 'key1=val1;key2=val2'). /// </param> public void Initialize(TestLoggerEvents events, Dictionary <string, string> parameters) { if (events == null) { throw new ArgumentNullException(nameof(events)); } if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } // Assist users with message when they entered invalid CLI options var knownKeys = new List <string>() { ResultDirectoryKey, LogFilePathKey, LogFileNameKey, MethodFormatKey, FailureBodyFormatKey }; parameters.Where(x => knownKeys.Contains(x.Key) == false).ToList() .ForEach(x => Console.WriteLine($"JunitXML Logger: The provided configuration item '{x.Key}' is not valid and will be ignored. Note, names are case sensitive.")); if (parameters.TryGetValue(LogFileNameKey, out string outputPathName) && parameters.TryGetValue(ResultDirectoryKey, out string outputFileDirectory)) { outputPathName = Path.Combine(outputFileDirectory, outputPathName); this.InitializeImpl(events, outputPathName); } else if (parameters.TryGetValue(LogFilePathKey, out string outputPath)) { this.InitializeImpl(events, outputPath); } else if (parameters.TryGetValue(DefaultLoggerParameterNames.TestRunDirectory, out string outputDir)) { this.Initialize(events, outputDir); } else { throw new ArgumentException($"JunitXML Logger: Expected {LogFilePathKey} or {DefaultLoggerParameterNames.TestRunDirectory} parameter", nameof(parameters)); } if (parameters.TryGetValue(MethodFormatKey, out string methodFormat)) { if (string.Equals(methodFormat.Trim(), "Class", StringComparison.OrdinalIgnoreCase)) { this.MethodFormatOption = MethodFormat.Class; } else if (string.Equals(methodFormat.Trim(), "Full", StringComparison.OrdinalIgnoreCase)) { this.MethodFormatOption = MethodFormat.Full; } else if (string.Equals(methodFormat.Trim(), "Default", StringComparison.OrdinalIgnoreCase)) { this.MethodFormatOption = MethodFormat.Default; } else { Console.WriteLine($"JunitXML Logger: The provided Method Format '{methodFormat}' is not a recognized option. Using default"); } } if (parameters.TryGetValue(FailureBodyFormatKey, out string failureFormat)) { if (string.Equals(failureFormat.Trim(), "Verbose", StringComparison.OrdinalIgnoreCase)) { this.FailureBodyFormatOption = FailureBodyFormat.Verbose; } else if (string.Equals(failureFormat.Trim(), "Default", StringComparison.OrdinalIgnoreCase)) { this.FailureBodyFormatOption = FailureBodyFormat.Default; } else { Console.WriteLine($"JunitXML Logger: The provided Failure Body Format '{failureFormat}' is not a recognized option. Using default"); } } if (parameters.TryGetValue(FileEncodingKey, out string fileEncoding)) { if (string.Equals(fileEncoding.Trim(), "UTF8Bom", StringComparison.OrdinalIgnoreCase)) { this.FileEncodingOption = FileEncoding.UTF8Bom; } else if (string.Equals(fileEncoding.Trim(), "UTF8", StringComparison.OrdinalIgnoreCase)) { this.FileEncodingOption = FileEncoding.UTF8; } else { Console.WriteLine($"JunitXML Logger: The provided File Encoding '{fileEncoding}' is not a recognized option. Using default"); } } }
/// <summary> /// Copy the attributes of the given Format object /// </summary> /// <param name="iFormat">Format object to copy attributes from</param> protected override void copyFrom(Format iFormat) { base.copyFrom(iFormat); LocationFormat = ((PlaylistFormat)iFormat).LocationFormat; Encoding = ((PlaylistFormat)iFormat).Encoding; }