210 lines
8.4 KiB
C#
210 lines
8.4 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using MergeCMInpro.Business;
|
|
using MergeCMInpro.Data;
|
|
using NLog;
|
|
using Sentry;
|
|
using static System.Net.WebRequestMethods;
|
|
|
|
|
|
namespace MergeCMInpro
|
|
{
|
|
static class Program
|
|
{
|
|
private static readonly Logger _logger = NLog.LogManager.GetCurrentClassLogger();
|
|
|
|
static string csvPath = String.Empty;
|
|
|
|
static void Main(string[] args)
|
|
{
|
|
try
|
|
{
|
|
CallSentry();
|
|
Console.ForegroundColor = ConsoleColor.White;
|
|
|
|
//productive
|
|
//csvPath = Path.Combine(Directory.GetFiles(Environment.CurrentDirectory, "*.csv").FirstOrDefault());
|
|
|
|
//testing
|
|
//csvPath = Path.Combine(Directory.GetFiles(@"\\fsdeg002\DatenStA61_S\Bauvorhaben\0_SAGA\839.867 - 843.817 SAGA HD 27 2023_11_08", "*.csv").FirstOrDefault());
|
|
//csvPath = Path.Combine(Directory.GetFiles(@"C:\Testing\MergeInpro", "*.csv").FirstOrDefault());
|
|
//csvPath = Path.Combine(Directory.GetFiles(@"C:\TEMP\SAGA\839.867 - 843.817 SAGA HD 27 2023_11_08", "*.csv").FirstOrDefault());
|
|
//csvPath = Path.Combine(Directory.GetFiles(@"C:\TEMP\SAGA\843.818 - 847.187 SAGA HD 28 2023_12_18", "*.csv").FirstOrDefault());
|
|
csvPath = Path.Combine(Directory.GetFiles(@"E:\TestData\MergeCMInpro", "*.csv").FirstOrDefault());
|
|
|
|
|
|
string pathOutputFileCM = Path.Combine(Directory.GetParent(csvPath).FullName, "outputCM.csv");
|
|
string pathOutputFileInpro = Path.Combine(Directory.GetParent(csvPath).FullName, "outputInpro.csv");
|
|
string pathOutputFileStandort = Path.Combine(Directory.GetParent(csvPath).FullName, "outputStandort.csv");
|
|
|
|
if (CheckFileExist())
|
|
{
|
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
|
Console.WriteLine("WARNING: import files already exist.");
|
|
Console.ResetColor();
|
|
return;
|
|
}
|
|
|
|
|
|
if(!CheckFolderStructure(csvPath))
|
|
{
|
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
|
Console.WriteLine("WARNING: folder structure wrong. Please note folder with name '{0}' has to contain all pdf files.", Path.GetFileNameWithoutExtension(csvPath));
|
|
Console.ResetColor();
|
|
return;
|
|
}
|
|
|
|
var config = System.IO.File.ReadLines(@".\config.txt").ToArray();
|
|
DataOperations.conString = config[0];
|
|
DataOperations.kanalAktePath = config[2];
|
|
DataOperations.csvPath = csvPath;
|
|
|
|
if (!System.IO.File.Exists(DataOperations.kanalAktePath))
|
|
throw new FileNotFoundException("Kanalaktendatei nicht gefunden.");
|
|
|
|
//Testing
|
|
string archivNetPath = Path.Combine(@"E:\TestData\ArchivPath");
|
|
|
|
//productive
|
|
//string archivNetPath = Path.Combine(config[1]);
|
|
|
|
Console.WriteLine("Working, please wait... or get yourself a tea.");
|
|
|
|
FileOperations.SplitRow(csvPath, archivNetPath);
|
|
|
|
//CM
|
|
using (StreamWriter sw = new StreamWriter(pathOutputFileCM))
|
|
{
|
|
foreach (var item in DataOperations.vorgängeCM)
|
|
{
|
|
sw.WriteLine(item.ToString());
|
|
}
|
|
}
|
|
|
|
//Inpro
|
|
using (StreamWriter sw = new StreamWriter(pathOutputFileInpro))
|
|
{
|
|
foreach (var item in DataOperations.vorgängeInpro)
|
|
{
|
|
sw.WriteLine(item.ToString());
|
|
}
|
|
}
|
|
|
|
//Standort
|
|
using (StreamWriter sw = new StreamWriter(pathOutputFileStandort))
|
|
{
|
|
foreach (var item in DataOperations.vorgängeStandort.Distinct())
|
|
{
|
|
sw.WriteLine(item.ToString());
|
|
}
|
|
}
|
|
|
|
|
|
Console.ForegroundColor = ConsoleColor.Green;
|
|
Console.WriteLine("{0} created.", pathOutputFileCM);
|
|
|
|
FileInfo fi = new FileInfo(pathOutputFileInpro);
|
|
if(fi.Length!=0)
|
|
{
|
|
Console.WriteLine("{0} created.", pathOutputFileInpro);
|
|
Console.WriteLine("{0} created.", pathOutputFileStandort);
|
|
}
|
|
|
|
Console.ResetColor();
|
|
|
|
//#region Backup JPM-Files
|
|
//Console.WriteLine("Start copying jpm-files, please wait...");
|
|
//FileInfo fi = new FileInfo(csvPath);
|
|
//FileOperations.CopyJPMFilesToDestination(fi.Directory.FullName, archivNetPath);
|
|
//Console.WriteLine("");
|
|
//Console.ForegroundColor = ConsoleColor.Green;
|
|
//Console.WriteLine("Done. You may close this window now.");
|
|
//#endregion
|
|
|
|
Console.ReadLine();
|
|
|
|
}
|
|
catch (DirectoryNotFoundException)
|
|
{
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
|
Console.WriteLine("ERROR: source directory not found.");
|
|
Console.ReadLine();
|
|
}
|
|
catch (FileNotFoundException ex)
|
|
{
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
|
Console.WriteLine("ERROR: " + ex.Message);
|
|
Console.ReadLine();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.ForegroundColor = ConsoleColor.Red;
|
|
Console.WriteLine("ERROR: unknown error occured. Maybe no csv-File? Please check!\r\n{0}", ex.InnerException);
|
|
Console.ReadLine();
|
|
}
|
|
}
|
|
|
|
static string CallSentry()
|
|
{
|
|
try
|
|
{
|
|
var res = SentrySdk.Init(options =>
|
|
{
|
|
// A Sentry Data Source Name (DSN) is required.
|
|
// See https://docs.sentry.io/product/sentry-basics/dsn-explainer/
|
|
// You can set it in the SENTRY_DSN environment variable, or you can set it in code here.
|
|
options.Dsn = "https://73fd45bffc79360f9de9b7a7a622d96f@sentry.katyes.dynv6.net/3";
|
|
|
|
// When debug is enabled, the Sentry client will emit detailed debugging information to the console.
|
|
// This might be helpful, or might interfere with the normal operation of your application.
|
|
// We enable it here for demonstration purposes when first trying Sentry.
|
|
// You shouldn't do this in your applications unless you're troubleshooting issues with Sentry.
|
|
options.Debug = true;
|
|
|
|
// This option is recommended. It enables Sentry's "Release Health" feature.
|
|
options.AutoSessionTracking = true;
|
|
});
|
|
return res.ToString();
|
|
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
SentrySdk.CaptureMessage("Something went wrong");
|
|
return ex.Message;
|
|
}
|
|
}
|
|
|
|
private static bool CheckFolderStructure(string csvName)
|
|
{
|
|
string fileName = Path.GetFileNameWithoutExtension(csvName);
|
|
bool result = false;
|
|
string dir = Path.GetDirectoryName(csvName);
|
|
DirectoryInfo di = new DirectoryInfo(dir);
|
|
if(di.GetFiles("*.pdf").Length > 0)
|
|
{
|
|
return result;
|
|
}
|
|
if (Directory.Exists(Path.Combine(dir, fileName)))
|
|
{
|
|
result = true;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
public static bool CheckFileExist()
|
|
{
|
|
FileInfo fi = new FileInfo(Path.Combine(Directory.GetParent(csvPath).FullName, "outputInpro.csv"));
|
|
|
|
if ((System.IO.File.Exists(Path.Combine(Directory.GetParent(csvPath).FullName, "outputInpro.csv")) && fi.Length!=0) || System.IO.File.Exists(Path.Combine(Directory.GetParent(csvPath).FullName, "outputCM.csv")))
|
|
{
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|