コード例 #1
0
        public TextFileReader(TextFileHandle fileHandle, FileReadOptions readType, TextCodepage codePage, long skipHeaderLines, long skipFooterLines)
        {
            System.Diagnostics.Debug.Assert(fileHandle != null);
            this.fileHandle = fileHandle;

            this.readType        = readType;
            this.codePage        = codePage;
            this.skipFooterLines = skipFooterLines;
            this.skipHeaderLines = skipHeaderLines;
        }
コード例 #2
0
 public TextFileHandle(string filePath, TextCodepage textCodePage = TextCodepage.Default) : base(filePath)
 {
     TextCodepage = textCodePage;
 }
コード例 #3
0
        private FunctionResult Execute(string filePath, DoesNotExistOptions fileDoesNotExist, ExistOptions fileExists, TextCodepage codepage = TextCodepage.Default, bool isText = true)
        {
            FunctionExecutor tester = (new FunctionTester <FileOpen.FileOpen>()).Compile(
                new PropertyValue(FileOpenShared.IsTextPropertyName, isText),
                new PropertyValue(FileOpenShared.CodepagePropertyName, codepage),
                new PropertyValue(FileOpenShared.FileDoesNotExistPropertyName, fileDoesNotExist),
                new PropertyValue(FileOpenShared.FileExistsPropertyName, fileExists));
            var result = tester.Execute(new ParameterValue(FileOpenShared.FilePathPropertyName, filePath));

            Assert.IsFalse(FileHelpers.IsFileLocked(filePath), "File must not open before the execution path is active.");
            return(result);
        }
コード例 #4
0
 public FileOpenX(string filePath, bool isText, TextCodepage codepage, DoesNotExistOptions fileDoesNotExist, ExistOptions fileExists, Action <string> logger)
 {
     FileHandle           = isText ? (FileHandle) new TextFileHandle(filePath, codepage) : (FileHandle) new BinaryFileHandle(filePath);
     FileHandle.LogEvent += message => logger(message);
     FileHandle.TryPrepareForWrite(fileDoesNotExist, fileExists);
 }
コード例 #5
0
        public static string WriteFile(TextFileHandle fileHandle, bool closeFileHandle, string contents, DoesNotExistOptions fileDoesNotExist, ExistOptions fileExist, TextCodepage destinationCodepage, Action <string> logger)
        {
            if (fileHandle.TryPrepareForWrite(fileDoesNotExist, fileExist))
            {
                fileHandle.TextCodepage = destinationCodepage;
            }

            StreamWriter writer = fileHandle.CreateStreamWriter();

            try
            {
                logger(string.Format("Writing <{0}>", contents));
                writer.Write(contents);
                writer.Flush();
            }
            finally
            {
                if (closeFileHandle)
                {
                    fileHandle.Close();
                }
            }

            return(fileHandle.FilePath);
        }
コード例 #6
0
        private FunctionResult Execute(string fileName, FileReadOptions readType, TextFileReaderFields fields, int skipHeaderLines = 0, int skipFooterLines = 0, TextCodepage codepage = TextCodepage.Default)
        {
            FunctionExecutor tester = (new FunctionTester <TextFileRead.TextFileRead>()).Compile(
                new PropertyValue(TextFileReadShared.CodepagePropertyName, codepage),
                new PropertyValue(TextFileReadShared.ReadTypePropertyName, readType),
                new PropertyValue(TextFileReadShared.FieldsPropertyName, fields),
                new PropertyValue(TextFileReadShared.SkipHeaderLinesPropertyName, skipHeaderLines),
                new PropertyValue(TextFileReadShared.SkipFooterLinesPropertyName, skipFooterLines));
            var result = tester.Execute(new ParameterValue(FileShared.FilePathPropertyName, fileName));

            Assert.IsFalse(FileHelpers.IsFileLocked(fileName));
            return(result);
        }