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
|
public static bool InitScheduler()
{
Semaphore _SemaErrorReport = new Semaphore(1, 1);
string StringError = "";
Parallel.Invoke(
() =>
{
CheckDossExist(Constantes.XmlFolder, ref StringError, ref _SemaErrorReport);
Parallel.Invoke(
() => CheckXmlExist(Constantes.XmlAsm, ref StringError, ref _SemaErrorReport),
() => CheckXmlExist(Constantes.XmlPlanPart, ref StringError, ref _SemaErrorReport));
},
() => CheckDossExist(Constantes.AsmFolder, ref StringError, ref _SemaErrorReport),
() => CheckDossExist(Constantes.QuarantaineFolder, ref StringError, ref _SemaErrorReport));
if (Settings.Default.B_DevMod)
WriteInLog.Add2log("Folder & Xml OK"); //Marche
if (StringError != "")
MessageBox.Show("Les éléments suivants n'ont pas été trouvés, ils ont donc été créés :\n\n" + StringError, "Création de dossiers et de fichiers", MessageBoxButtons.OK, MessageBoxIcon.Information);
_SemaErrorReport.Dispose();
if (CheckNotOpen())
{
string s = "Un fichier de la base est ouvert (PDF ou Xml).\n";
MessageBox.Show(s, "Le programme doit se fermer.", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
if (Settings.Default.B_DevMod)
WriteInLog.Add2log("A File is open, app close."); //Marche
return false;
}
if (Settings.Default.B_DevMod)
WriteInLog.Add2log("Accès fichiers OK"); //Marche
Parallel.Invoke(
() => {
Parallel.Invoke(
() => XmlClasses.OpenXmlAsm(),
() => XmlClasses.OpenXmlPart());
if (Settings.Default.B_DevMod)
WriteInLog.Add2log("Fin de lect des Xml part & asm."); //Marche
XERPClass.UpdateBesoin();
if (Settings.Default.B_DevMod)
WriteInLog.Add2log("Fin de calcul des besoins."); //Marche
},
() => {
XmlClasses.OpenXmlPDF();
if (Settings.Default.B_DevMod)
WriteInLog.Add2log("Fin de lect des Xml plan."); //Ne marche pas si à B_DevMod false
},
() => {
ScanDossierPlan(new DirectoryInfo(Settings.Default.Path + Constantes.PartFolder));
if (Settings.Default.B_DevMod)
WriteInLog.Add2log("Fin de lecture des PDF."); //Marche
XAnalysePDF.CompleteLectPDFS();
if (Settings.Default.B_DevMod)
WriteInLog.Add2log("Fin d'analyse des noms PDF."); //Marche
XMovePDF.RemoveDouble();
if (Settings.Default.B_DevMod)
WriteInLog.Add2log("Doublons en quarantaine."); //Marche
});
List<string> Have2Del = new List<string>();
using (Semaphore _SemaHave2Del = new Semaphore(1, 1))
{
Parallel.ForEach(Variables.Li_OldPDFSource, (PDFS) =>
{
string MotifSuppr = null;
if (Variables.Li_PDFSource.Exists(x => x.Ref == PDFS.Ref && x.Ind == PDFS.Ind && x.SHA1 != PDFS.SHA1))
MotifSuppr = "chgt sans prise d'indice.";
else if (!Variables.Li_PDFSource.Exists(x => x.Ref == PDFS.Ref && Convert.ToByte(x.Ind[0]) >= Convert.ToByte(PDFS.Ind[0])))
MotifSuppr = "suppr indice le + haut.";
if (MotifSuppr != null)
{
_SemaHave2Del.WaitOne();
if (!Have2Del.Exists(x => x == PDFS.Ref))
Have2Del.Add(PDFS.Ref);
_SemaHave2Del.Release();
WriteInLog.Add2log(string.Format("Tous {0} -> quarantaine : {1}", PDFS.Ref, MotifSuppr));
}
});
}
Parallel.ForEach(Have2Del, (suppr) =>
{
XMovePDF.PDFRefToQuarantaine(suppr);
});
if (Settings.Default.B_DevMod)
WriteInLog.Add2log("Fichier NOK en quarantaine.");
Parallel.Invoke(
() => {
XmlClasses.MaJPDFXml();
if (Settings.Default.B_DevMod)
WriteInLog.Add2log("Xml PDF à jour."); //Ne marche pas si à B_DevMod false
},
() => {
XAnalysePDF.GetTopIndice();
if (Settings.Default.B_DevMod)
WriteInLog.Add2log("Top indice définis.");
bool i = Settings.Default.B_DevMod; // Bizarrerie pour que ça marche avec B_DevMod à false.
});
XMovePDF.ErasePlanAsmNOK();
if (Settings.Default.B_DevMod)
WriteInLog.Add2log("Mise à jour des dossiers d'asm.");
return true;
}
} |
Partager