Files
DP44/Common/DTS.Common.Import/.svn/pristine/eb/ebd330f7c0fcf8d81d9dd4bd5ae4c509427adbf2.svn-base

83 lines
2.3 KiB
Plaintext
Raw Normal View History

2026-04-17 14:55:32 -04:00
using DTS.Common.Import.ImportOptions;
using Microsoft.VisualBasic.FileIO;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DTS.Common.Import
{
public class CSVFile
{
private readonly string _filename;
public CSVFile(string filename)
{
_filename = filename;
}
public bool IsInUse()
{
if (!string.IsNullOrEmpty(_filename))
{
try
{
_ = File.ReadAllLines(_filename);
return false;
}
catch (IOException)
{
return true;
}
catch (Exception)
{
//We can supress this exception since we are interested in IOException only
}
}
return true;
}
//FB 40598 check the format of csv and determine if is test setup or not
public static bool IsCSVFileForTestSetupImport(string filename, CsvImportOptions csvImportOptions)
{
using (var parser = new TextFieldParser(filename, Encoding.GetEncoding(csvImportOptions.Encoding), true))
{
parser.TextFieldType = FieldType.Delimited;
parser.SetDelimiters(csvImportOptions.FieldSeparator);
var tokens = parser.ReadFields();
if (tokens != null && tokens[0] == "Version")
{
return true;
}
}
return false;
}
public int LineCount
{
get
{
var count = 0;
if (!string.IsNullOrEmpty(_filename))
{
string[] lines;
try
{
lines = File.ReadAllLines(_filename);
return lines.Count();
}
catch (Exception)
{
return count;
}
}
return count;
}
}
}
}