private BplDocumentFormatter _invokeFormatter(BplFormat format, BplObject input) { BplDocumentFormatter formatter = null; switch (format) { case BplFormat.Xml: formatter = new BplXmlFormatter { PrettyPrint = true }; break; case BplFormat.Json: formatter = new BplJsonFormatter { PrettyPrint = true, StronglyTyped = false }; break; case BplFormat.Json_t: formatter = new BplJsonFormatter { PrettyPrint = true, StronglyTyped = true }; break; case BplFormat.Binary: formatter = new BplHexFormatter { }; break; default: return null; } if (formatter != null) { formatter.Format(input); } return formatter; }
private void _openFile(string path) { if (path.IsEmpty()) { _input.Text = null; _output.Text = null; InputFile = null; } else { try { _input.Text = File.ReadAllText(path); InputFormat = _detectFormat(_input.Text); if (InputFormat == BplFormat.Unknown) { var buffer = File.ReadAllBytes(path); var reader = new BplBinaryReader(buffer); var formatter = new BplHexFormatter(); formatter.Format(reader.Deserialize()); _input.Text = formatter.Output; InputFormat = BplFormat.Binary; } _reformat(); InputFile = path; } catch (Exception e2) { MessageBox.Show("Failed to read '{0}' file. {1}".Substitute(path, e2.Message)); } } IsDirty = false; }