public void Open(string path, IValue encoding = null, string lineDelimiter = "\n", string eolDelimiter = null, bool?monopoly = null) { Close(); TextReader imReader; var shareMode = (monopoly ?? true) ? FileShare.None : FileShare.ReadWrite; if (encoding == null) { imReader = Environment.FileOpener.OpenReader(path, shareMode); } else { var enc = TextEncodingEnum.GetEncoding(encoding); imReader = Environment.FileOpener.OpenReader(path, shareMode, enc); } _lineDelimiter = lineDelimiter ?? "\n"; if (eolDelimiter != null) { _reader = new CustomLineFeedStreamReader(imReader, eolDelimiter, AnalyzeDefaultLineFeed); } else { _reader = new CustomLineFeedStreamReader(imReader, "\r\n", AnalyzeDefaultLineFeed); } }
public static ProcessContext Create(string cmdLine, string currentDir = null, bool redirectOutput = false, bool redirectInput = false, IValue encoding = null) { var sInfo = PrepareProcessStartupInfo(cmdLine, currentDir); sInfo.UseShellExecute = false; if (redirectInput) sInfo.RedirectStandardInput = true; if (redirectOutput) { sInfo.RedirectStandardOutput = true; sInfo.RedirectStandardError = true; } if (encoding != null) { var enc = TextEncodingEnum.GetEncoding(encoding); sInfo.StandardOutputEncoding = enc; sInfo.StandardErrorEncoding = enc; } var p = new System.Diagnostics.Process(); p.StartInfo = sInfo; return new ProcessContext(p, encoding); }
public void Open(string path, IValue encoding = null) { if (encoding == null) { _reader = Environment.FileOpener.OpenReader(path); } else { var enc = TextEncodingEnum.GetEncoding(encoding); _reader = Environment.FileOpener.OpenReader(path, enc); } }
public string GetStringFromBinaryData(BinaryDataContext data, IValue encoding = null) { // Получаем кодировку // Из синтаксис помощника если кодировка не задана используем UTF8 System.Text.Encoding enc = System.Text.Encoding.UTF8; if (encoding != null) { enc = TextEncodingEnum.GetEncoding(encoding); } return(enc.GetString(data.Buffer)); }
public BinaryDataContext GetBinaryDataFromString(string str, IValue encoding = null, bool addBOM = false) { // Получаем кодировку // Из синтаксис помощника если кодировка не задана используем UTF8 System.Text.Encoding enc = System.Text.Encoding.UTF8; if (encoding != null) { enc = TextEncodingEnum.GetEncoding(encoding, addBOM); } return(new BinaryDataContext(enc.GetBytes(str))); }
public static TextEncodingEnum CreateInstance() { TextEncodingEnum instance; TypeDescriptor enumType; TypeDescriptor enumValType; EnumContextHelper.RegisterEnumType <TextEncodingEnum>(out enumType, out enumValType); instance = new TextEncodingEnum(enumType, enumValType); EnumContextHelper.RegisterValues <TextEncodingEnum>(instance); return(instance); }
private StreamWriter GetDefaultWriter(string path, IValue encoding) { StreamWriter writer; if (encoding == null) { writer = Environment.FileOpener.OpenWriter(path, new UTF8Encoding(true)); } else { writer = Environment.FileOpener.OpenWriter(path, TextEncodingEnum.GetEncoding(encoding)); } return(writer); }
private void OpenStream(IStreamWrapper streamObj, IValue encoding = null, string lineDelimiter = "\n", string eolDelimiter = null) { TextReader imReader; if (encoding == null) { imReader = Environment.FileOpener.OpenReader(streamObj.GetUnderlyingStream(), Encoding.Default); } else { var enc = TextEncodingEnum.GetEncoding(encoding); imReader = Environment.FileOpener.OpenReader(streamObj.GetUnderlyingStream(), enc); } _reader = GetCustomLineFeedReader(imReader, lineDelimiter, eolDelimiter, AnalyzeDefaultLineFeed); }
private StreamReader GetDefaultReader(string path, IValue encoding) { StreamReader reader; if (encoding == null) { reader = Environment.FileOpener.OpenReader(path); } else { reader = Environment.FileOpener.OpenReader(path, TextEncodingEnum.GetEncoding(encoding)); } return(reader); }
private void OpenFile(string path, IValue encoding = null, string lineDelimiter = "\n", string eolDelimiter = null, bool?monopoly = null) { TextReader imReader; var shareMode = (monopoly ?? true) ? FileShare.None : FileShare.ReadWrite; if (encoding == null) { imReader = Environment.FileOpener.OpenReader(path, shareMode); } else { var enc = TextEncodingEnum.GetEncoding(encoding); imReader = Environment.FileOpener.OpenReader(path, shareMode, enc); } _reader = GetCustomLineFeedReader(imReader, lineDelimiter, eolDelimiter, AnalyzeDefaultLineFeed); }
public static ProcessContext Create(string cmdLine, string currentDir = null, bool redirectOutput = false, bool redirectInput = false, IValue encoding = null, MapImpl env = null) { var sInfo = PrepareProcessStartupInfo(cmdLine, currentDir); sInfo.UseShellExecute = false; if (redirectInput) { sInfo.RedirectStandardInput = true; } if (redirectOutput) { sInfo.RedirectStandardOutput = true; sInfo.RedirectStandardError = true; } if (encoding != null) { var enc = TextEncodingEnum.GetEncoding(encoding); sInfo.StandardOutputEncoding = enc; sInfo.StandardErrorEncoding = enc; } if (env != null) { var source = env.Select(x => new { Key = x.Key.AsString(), Value = x.Value.AsString() }).Where(x => !string.IsNullOrWhiteSpace(x.Key)); foreach (var kv in source) { sInfo.EnvironmentVariables[kv.Key] = kv.Value; } } var p = new System.Diagnostics.Process(); p.StartInfo = sInfo; return(new ProcessContext(p, encoding)); }
public void Open(string path, IValue encoding = null, string lineDelimiter = null, bool append = false) { Encoding enc; if (encoding == null) { enc = new UTF8Encoding(true); } else { enc = TextEncodingEnum.GetEncoding(encoding); if (enc.WebName == "utf-8" && append == true) { enc = new UTF8Encoding(false); } } _writer = new StreamWriter(path, append, enc); }
public static ProcessContext Create(string cmdLine, string currentDir = null, bool redirectOutput = false, bool redirectInput = false, IValue encoding = null, MapImpl env = null) { var sInfo = PrepareProcessStartupInfo(cmdLine, currentDir); sInfo.UseShellExecute = false; if (redirectInput) { sInfo.RedirectStandardInput = true; } if (redirectOutput) { sInfo.RedirectStandardOutput = true; sInfo.RedirectStandardError = true; } if (encoding != null) { var enc = TextEncodingEnum.GetEncoding(encoding); sInfo.StandardOutputEncoding = enc; sInfo.StandardErrorEncoding = enc; } if (env != null) { foreach (var kv in env) { sInfo.EnvironmentVariables.Remove(kv.Key.AsString()); sInfo.EnvironmentVariables[kv.Key.AsString()] = kv.Value.AsString(); } } var p = new System.Diagnostics.Process(); p.StartInfo = sInfo; return(new ProcessContext(p, encoding)); }
public void Open(string path, IValue encoding = null, string lineDelimiter = null, bool append = false, string eolReplacement = null) { _lineDelimiter = lineDelimiter ?? "\n"; _eolReplacement = eolReplacement ?? "\r\n"; Encoding enc; if (encoding == null) { enc = new UTF8Encoding(true); } else { enc = TextEncodingEnum.GetEncoding(encoding); if (enc.WebName == "utf-8" && append == true) { enc = new UTF8Encoding(false); } } _writer = new StreamWriter(path, append, enc); _writer.AutoFlush = true; }
public void Open(string path, IValue encoding = null, string lineDelimiter = "\n", string eolDelimiter = null) { TextReader imReader; if (encoding == null) { imReader = Environment.FileOpener.OpenReader(path); } else { var enc = TextEncodingEnum.GetEncoding(encoding); imReader = Environment.FileOpener.OpenReader(path, enc); } _lineDelimiter = lineDelimiter ?? "\n"; if (eolDelimiter != null) { _reader = new CustomLineFeedStreamReader(imReader, eolDelimiter, AnalyzeDefaultLineFeed); } else { _reader = new CustomLineFeedStreamReader(imReader, "\r\n", AnalyzeDefaultLineFeed); } }
public string EncodeString(string sourceString, SelfAwareEnumValue <StringEncodingMethodEnum> codeType, IValue encoding = null) { var encMethod = GlobalsManager.GetEnum <StringEncodingMethodEnum>(); Encoding enc; if (encoding != null) { enc = TextEncodingEnum.GetEncoding(encoding); } else { enc = Encoding.UTF8; } if (codeType == encMethod.URLEncoding) { return(EncodeStringImpl(sourceString, enc, false)); } else { return(EncodeStringImpl(sourceString, enc, true)); } }
public string GetStringFromBinaryDataBuffer(BinaryDataBuffer buffer, IValue encoding = null) { var enc = (encoding != null) ? TextEncodingEnum.GetEncoding(encoding) : Encoding.UTF8; return(enc.GetString(buffer.Bytes)); }
public BinaryDataBuffer GetBinaryDataBufferFromString(string str, IValue encoding = null, bool addBOM = false) { var enc = (encoding != null)? TextEncodingEnum.GetEncoding(encoding, addBOM) : Encoding.UTF8; return(new BinaryDataBuffer(enc.GetBytes(str))); }
public static TextEncodingEnum CreateInstance() { TextEncodingEnum instance; TypeDescriptor enumType; TypeDescriptor enumValType; EnumContextHelper.RegisterEnumType<TextEncodingEnum>(out enumType, out enumValType); instance = new TextEncodingEnum(enumType, enumValType); EnumContextHelper.RegisterValues<TextEncodingEnum>(instance); return instance; }