Example #1
0
        public static void JsonSerialize(string path, object target, Encoding encoding = null)
        {
            ChoGuard.ArgumentNotNullOrEmpty(path, "Path");
            ChoGuard.ArgumentNotNull(target, "Target");

            Directory.CreateDirectory(Path.GetDirectoryName(ChoPath.GetFullPath(path)));

            File.WriteAllText(path, JsonSerialize(target, encoding));
        }
Example #2
0
        private string GetFullPath(string path)
        {
            if (Path.IsPathRooted(path))
            {
                return(path);
            }

            path = ChoPath.GetFullPath(path, ChoETLFrxBootstrap.ConfigDirectory);
            return(Path.Combine(Path.Combine(Path.GetDirectoryName(path), "Config"), Path.GetFileName(path)));
        }
Example #3
0
        protected override string Write(IEnumerable <T> run)
        {
            var file = ChoPath.GetTempFileName();

            using (var writer = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None))
            {
                new BinaryFormatter().Serialize(writer, run.ToArray());
            }
            return(file);
        }
Example #4
0
        public ChoFixedLengthReader(string filePath, ChoFixedLengthRecordConfiguration configuration = null)
        {
            ChoGuard.ArgumentNotNullOrEmpty(filePath, "FilePath");

            Configuration = configuration;

            Init();

            _textReader           = new StreamReader(ChoPath.GetFullPath(filePath), Configuration.GetEncoding(filePath), false, Configuration.BufferSize);
            _closeStreamOnDispose = true;
        }
Example #5
0
        public ChoCSVWriter(string filePath, ChoCSVRecordConfiguration configuration = null)
        {
            ChoGuard.ArgumentNotNullOrEmpty(filePath, "FilePath");

            Configuration = configuration;

            Init();

            _textWriter           = new StreamWriter(ChoPath.GetFullPath(filePath), false, Configuration.Encoding, Configuration.BufferSize);
            _closeStreamOnDispose = true;
        }
Example #6
0
        public ChoJSONReader <T> Load(string filePath)
        {
            ChoGuard.ArgumentNotNullOrEmpty(filePath, "FilePath");

            Close();
            Init();
            _JSONReader           = new JsonTextReader(new StreamReader(ChoPath.GetFullPath(filePath), Configuration.GetEncoding(filePath), false, Configuration.BufferSize));
            _closeStreamOnDispose = true;

            return(this);
        }
Example #7
0
        public ChoXmlReader(string filePath, ChoXmlRecordConfiguration configuration = null)
        {
            ChoGuard.ArgumentNotNullOrEmpty(filePath, "FilePath");

            Configuration = configuration;

            Init();

            _xmlReader = XmlReader.Create(new StreamReader(ChoPath.GetFullPath(filePath), Configuration.GetEncoding(filePath), false, Configuration.BufferSize),
                                          new XmlReaderSettings(), new XmlParserContext(null, Configuration.NamespaceManager, null, XmlSpace.None));
            _closeStreamOnDispose = true;
        }
Example #8
0
        public ChoCSVReader(string filePath, ChoCSVRecordConfiguration configuration = null)
        {
            ChoGuard.ArgumentNotNullOrEmpty(filePath, "FilePath");

            TraceSwitch   = ChoETLFramework.TraceSwitch;
            Configuration = configuration;

            Init();

            _streamReader         = new StreamReader(ChoPath.GetFullPath(filePath), Configuration.Encoding, false, Configuration.BufferSize);
            _closeStreamOnDispose = true;
        }
Example #9
0
        public ChoXmlReader(string filePath, string defaultNamespace, ChoXmlRecordConfiguration configuration = null)
        {
            ChoGuard.ArgumentNotNullOrEmpty(filePath, "FilePath");

            Configuration = configuration;
            Init();
            if (!defaultNamespace.IsNullOrWhiteSpace())
            {
                Configuration.NamespaceManager.AddNamespace("", defaultNamespace);
            }


            _sr = new StreamReader(ChoPath.GetFullPath(filePath), Configuration.GetEncoding(filePath), false, Configuration.BufferSize);
            //InitXml();
            _closeStreamOnDispose = true;
        }
Example #10
0
        public static string[] ReadAllLines(string filePath)
        {
            ChoGuard.ArgumentNotNullOrEmpty(filePath, "FilePath");
            filePath = ChoPath.GetFullPath(filePath);

            if (File.Exists(filePath))
            {
                return(File.ReadAllLines(filePath));
            }
            else
            {
                try
                {
                    File.CreateText(filePath);
                }
                catch { }
                return(new string[] {});
            }
        }
Example #11
0
        public ChoXmlReader(string filePath, string defaultNamespace)
        {
            ChoGuard.ArgumentNotNullOrEmpty(filePath, "FilePath");

            Configuration = new ChoXmlRecordConfiguration();
            if (!defaultNamespace.IsNullOrWhiteSpace())
            {
                Configuration.NamespaceManager.AddNamespace("", defaultNamespace);
            }

            Init();

            _sr        = new StreamReader(ChoPath.GetFullPath(filePath), Configuration.GetEncoding(filePath), false, Configuration.BufferSize);
            _xmlReader = XmlReader.Create(_sr,
                                          new XmlReaderSettings()
            {
                DtdProcessing = DtdProcessing.Ignore, XmlResolver = null
            }, new XmlParserContext(null, Configuration.NamespaceManager, null, XmlSpace.None));
            _closeStreamOnDispose = true;
        }