예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
 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);
     }
 }
예제 #4
0
        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));
        }
예제 #5
0
        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)));
        }
예제 #6
0
        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);
        }
예제 #7
0
        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);
        }
예제 #8
0
        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);
        }
예제 #9
0
        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);
        }
예제 #10
0
        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);
        }
예제 #11
0
        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));
        }
예제 #12
0
        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);
        }
예제 #13
0
        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));
        }
예제 #14
0
        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;
        }
예제 #15
0
        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);
            }
        }
예제 #16
0
        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));
            }
        }
예제 #17
0
        public string GetStringFromBinaryDataBuffer(BinaryDataBuffer buffer, IValue encoding = null)
        {
            var enc = (encoding != null) ? TextEncodingEnum.GetEncoding(encoding) : Encoding.UTF8;

            return(enc.GetString(buffer.Bytes));
        }
예제 #18
0
        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)));
        }
예제 #19
0
        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;
        }