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 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
| using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.IO;
using System.Collections;
using System.Text.RegularExpressions;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
const int nbCompilationFiles = 6;
long nbFolderFiles = Directory.GetFiles(@"C: \Users\maxursin\Desktop\New folder", "LOG*.log").LongLength;
Hashtable dlls = new Hashtable();
TimeSpan ts;
int compteur = 0;
double globalDuration = 0;
int compteurF = 1;
double globalDurationFiles = 0;
int maxDuration = (int)globalDurationFiles / nbCompilationFiles;
string TemplateTwo = File.ReadAllText(@"C: \Users\maxursin\Desktop\New folder\Template\Template2.txt");
string LineReturn = "\r\n";
{
for (int nbFiles = 1; nbFiles < (nbFolderFiles + 1); nbFiles++)
{
string filePath = @"C: \Users\maxursin\Desktop\New folder\LOG" + nbFiles.ToString() + ".log";
string[] text = File.ReadAllLines(filePath);
string mot = "########## Duration";
for (int i = 0; i < text.Length; i++)
{
if (text[i].Contains(mot))
{
string[] tokens = text[i].Split('\t');
if (!dlls.ContainsKey(tokens[1]))
{
dlls.Add(tokens[1], TimeSpan.Parse(tokens[2]).TotalSeconds);
globalDurationFiles = globalDurationFiles + TimeSpan.Parse(tokens[2]).TotalSeconds;
}
else
{
double globalGenDllDuration = (double)dlls[tokens[1]];
globalGenDllDuration += TimeSpan.Parse(tokens[2]).TotalSeconds;
globalDurationFiles = globalDurationFiles + TimeSpan.Parse(tokens[2]).TotalSeconds;
dlls.Remove(tokens[1]);
dlls.Add(tokens[1], globalGenDllDuration);
}
}
}
}
maxDuration = (int)(Math.Ceiling(globalDurationFiles / nbCompilationFiles));
File.Delete(@"C: \Users\maxursin\Desktop\New folder\Template\__Compile_Sub_01.bat");
File.Delete(@"C: \Users\maxursin\Desktop\New folder\Template\__Compile_Sub_02.bat");
File.Delete(@"C: \Users\maxursin\Desktop\New folder\Template\__Compile_Sub_03.bat");
File.Delete(@"C: \Users\maxursin\Desktop\New folder\Template\__Compile_Sub_04.bat");
File.Delete(@"C: \Users\maxursin\Desktop\New folder\Template\__Compile_Sub_05.bat");
File.Delete(@"C: \Users\maxursin\Desktop\New folder\Template\__Compile_Sub_06.bat");
IDictionaryEnumerator iEnum = dlls.GetEnumerator();
string pathDlls = @"C: \Users\maxursin\Desktop\New folder\DllsDuration1.log";
StreamWriter result = new StreamWriter(@"C: \Users\maxursin\Desktop\New folder\ResultDlls.txt");
StreamWriter sw = new StreamWriter(pathDlls); //création du fichier )
string sourceFile = @"C: \Users\maxursin\Desktop\New folder\Template\Template.txt";
string destinationFile = @"C: \Users\maxursin\Desktop\New folder\Template\__Compile_Sub_0" + compteurF.ToString() + ".bat";
File.Copy(sourceFile, destinationFile);
result.WriteLine("Total DLLS " + dlls.Count.ToString() + " " + (globalDurationFiles - 1));
result.WriteLine("");
while (iEnum.MoveNext())
{
sw.WriteLine(iEnum.Key + " " + iEnum.Value);
File.AppendAllText(@"C: \Users\maxursin\Desktop\New folder\Template\__Compile_Sub_0" + compteurF.ToString() + ".bat", LineReturn);
File.AppendAllText(@"C: \Users\maxursin\Desktop\New folder\Template\__Compile_Sub_0" + compteurF.ToString() + ".bat", LineReturn);
File.AppendAllText(@"C: \Users\maxursin\Desktop\New folder\Template\__Compile_Sub_0" + compteurF.ToString() + ".bat", TemplateTwo);
string CPSName = File.ReadAllText(@"C: \Users\maxursin\Desktop\New folder\Template\__Compile_Sub_0" + compteurF.ToString() + ".bat");
CPSName = CPSName.Replace("CPS1800 ##########", (string)iEnum.Key + " ##########");
CPSName = CPSName.Replace("CPS1800", (string)iEnum.Key);
File.WriteAllText(@"C: \Users\maxursin\Desktop\New folder\Template\__Compile_Sub_0" + compteurF.ToString() + ".bat", CPSName);
compteur++;
globalDuration = globalDuration + (double)iEnum.Value;
if ((globalDuration > maxDuration) && (compteurF <= nbCompilationFiles))
{
sourceFile = @"C: \Users\maxursin\Desktop\New folder\Template\Template.txt";
destinationFile = @"C: \Users\maxursin\Desktop\New folder\Template\__Compile_Sub_0" + (compteurF + 1).ToString() + ".bat";
File.Copy(sourceFile, destinationFile);
string texttest = File.ReadAllText(@"C: \Users\maxursin\Desktop\New folder\Template\__Compile_Sub_0" + compteurF.ToString() + ".bat");
texttest = texttest.Replace("sp_StartSub 1", "sp_StartSub " + compteurF.ToString());
texttest = texttest.Replace("sp_EndSub 1", "sp_EndSub " + compteurF.ToString());
texttest = texttest.Replace("Compile Sub 1", "Compile Sub " + compteurF.ToString());
File.WriteAllText(@"C: \Users\maxursin\Desktop\New folder\Template\__Compile_Sub_0" + compteurF.ToString() + ".bat", texttest);
sw.WriteLine("");
sw.WriteLine(compteur.ToString() + " " + globalDuration.ToString());
sw.Close();
result.WriteLine("DllsDuration" + compteurF.ToString() + " " + compteur.ToString() + " " + globalDuration.ToString());
compteurF++;
pathDlls = @"C: \Users\maxursin\Desktop\New folder\DllsDuration" + compteurF.ToString() + ".log";
sw = new StreamWriter(pathDlls);
globalDuration = 0;
compteur = 0;
}
}
string LastCompilSub = File.ReadAllText(@"C: \Users\maxursin\Desktop\New folder\Template\__Compile_Sub_0" + compteurF.ToString() + ".bat");
LastCompilSub = LastCompilSub.Replace("sp_StartSub 1", "sp_StartSub " + compteurF.ToString());
LastCompilSub = LastCompilSub.Replace("sp_EndSub 1", "sp_EndSub " + compteurF.ToString());
LastCompilSub = LastCompilSub.Replace("Compile Sub 1", "Compile Sub " + compteurF.ToString());
File.WriteAllText(@"C: \Users\maxursin\Desktop\New folder\Template\__Compile_Sub_0" + compteurF.ToString() + ".bat", LastCompilSub);
sw.WriteLine("");
sw.WriteLine(compteur.ToString() + " " + globalDuration.ToString());
sw.Close();
result.WriteLine("DllsDuration" + compteurF.ToString() + " " + compteur.ToString() + " " + globalDuration.ToString());
result.Close();
}
}
}
} |
Partager