This commit is contained in:
2026-04-17 14:55:32 -04:00
commit bc3ac1d4c9
18017 changed files with 4371742 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
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;
}
}
}
}