1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
| internal class LogParse
{
public DateTime Datation { get; set; }
public string Identificateur { get; set; }
public string Module { get; set; }
public string Type { get; set; }
public string Info { get; set; }
public string Details { get; set; }
public static LogParse Parse(string lignes, string nomFichier)
{
if (nomFichier.StartsWith("Logis"))
{
string[] ligneArray = lignes.Split('\t'); //sépare les chaînes à partir
Match m = Regex.Match(lignes, @"(?<mois>\d\d?)?/(?<jour>\d\d?)?/(?<annee>\d{4})?\s+(?<heure>\d\d?)?:(?<minute>\d\d?)?:(?<seconde>\d\d?)?\s+(?<ampm>[AP]M)?:(?<ms>\d{1,3})?");
if (m.Success)
{
int jour = int.Parse(m.Groups["jour"].Value);
int mois = int.Parse(m.Groups["mois"].Value);
int annee = int.Parse(m.Groups["annee"].Value);
int heure = int.Parse(m.Groups["heure"].Value);
int minute = int.Parse(m.Groups["minute"].Value);
int secondes = int.Parse(m.Groups["seconde"].Value);
string MS = m.Groups["ms"].Value;
int ms = 0;
if (!string.IsNullOrWhiteSpace(MS))
{
ms = int.Parse(MS);
if (MS.Length == 1)
ms *= 100;
else if (MS.Length == 2)
ms *= 10;
}
DateTime date = new DateTime(annee, mois, jour, heure, minute, secondes, ms);
if (m.Groups["ampm"].Value == "PM")
date = date.AddHours(12);
return new LogParse
{
Datation = date,
Identificateur = "LogisticCore",
Module = ligneArray[1],
Type = ligneArray[2],
Info = ligneArray[3],
Details = ligneArray[4],
};
}
return null;
}
else if (nomFichier.StartsWith("traff"))
{
string[] ligneArray = lignes.Split(']');
Match m = Regex.Match(lignes, @"(?<annee>\d{4})-(?<mois>(\d\d))-(?<jour>(\d\d))\s(?<heure>(\d\d)):(?<minute>(\d\d)):(?<seconde>(\d\d)).(?<ms>(\d{3}))");
if (m.Success)
{
int jour = int.Parse(m.Groups["jour"].Value);
int mois = int.Parse(m.Groups["mois"].Value);
int annee = int.Parse(m.Groups["annee"].Value);
int heure = int.Parse(m.Groups["heure"].Value);
int minute = int.Parse(m.Groups["minute"].Value);
int secondes = int.Parse(m.Groups["seconde"].Value);
DateTime date = new DateTime(annee, mois, jour, heure, minute, secondes);
MessageBox.Show(date.ToString());
foreach (string ligne in ligneArray)
{
for (int i = 0; i < 5; i++)
ligneArray[i] = ligneArray[i].Replace("[", "");
}
return new LogParse
{
Datation = date,
Identificateur = "Traffic",
Module = ligneArray[1],
Type = ligneArray[2],
Info = ligneArray[3],
Details = ligneArray[4],
};
}
return null;
}
return null;
}
} |
Partager