public ControleHoraireLocal() { string path = @"C:\ProgramData\CtrlPc\PLANNING\planning.csv"; if (File.Exists(path)) { string[] ligne = File.ReadAllLines(path); int count = 0; SynchroHeure MySynchroHeure = new SynchroHeure(); DateTime heureactuelle = DateTime.Now; try { heureactuelle = MySynchroHeure.GetNetworkTime(); } catch (Exception err) { MyTrace.WriteLog("Récupération heure serveur KO --> " + err.Message, 1, codeappli); heureactuelle = DateTime.Now; } foreach (string lignedetail in ligne) { if (lignedetail.Contains(";")) { string[] colonne = lignedetail.Split(new Char[] { ';' }); DateTime dateDebut = Convert.ToDateTime(colonne[0]); DateTime dateFin = Convert.ToDateTime(colonne[1]); if (heureactuelle >= dateDebut && heureactuelle <= dateFin) { count++; } } } if (count == 0) { MyTrace.WriteLog("La date n'est pas comprise parmis les plages locales", 2, codeappli); MyTrace.WriteLog("Appel de l'arrêt de l'ordinateur", 2, codeappli); Shutdown MyShutdown = new Shutdown(); } } else { MyTrace.WriteLog("Le planning n'est pas présent en locale", 2, codeappli); } }
public void LectureFlag(string path) { if (File.Exists(path + "arr.flg")) { string LectureFlg = File.ReadAllText(path + @"arr.flg"); if (LectureFlg.Contains("True")) { MyTrace.WriteLog("Demande d'arrêt de l'ordinateur", 2, codeappli); Shutdown MyShutDown = new Shutdown(); } else { MyTrace.WriteLog("Pas de demande d'arrêt", 2, codeappli); } } else { MyTrace.WriteLog("Le fichier arr.flg n'est pas présent", 2, codeappli); } }
public void ControlePlage(string[] plage) { MyTrace.WriteLog("Contrôle des plages horaires", 2, codeappli); DateTime datetime = DateTime.Now; try { MyTrace.WriteLog("Récupération de l'heure", 2, codeappli); SynchroHeure MySynchroHeure = new SynchroHeure(); datetime = MySynchroHeure.GetNetworkTime(); } catch (Exception err) { datetime = DateTime.Now; MyTrace.WriteLog(err.Message, 1, codeappli); } string jourSem = datetime.ToString("ddd"); MyTrace.WriteLog("Jour semaine : " + jourSem, 2, codeappli); int heureActuel = Int32.Parse(datetime.ToString("HHmm")); MyTrace.WriteLog("Heure : " + heureActuel, 2, codeappli); if ((jourSem.Contains("dim") && heureActuel > 1500) || jourSem.Contains("lun") || jourSem.Contains("mar") || jourSem.Contains("mer") || jourSem.Contains("jeu") || (jourSem.Contains("ven") && heureActuel < 1500)) { //lecture ligne S foreach (string ligne in plage) { if (ligne.Contains("S")) { MyTrace.WriteLog("plage : " + ligne, 2, codeappli); int heuredeb = Int32.Parse(ligne.Substring(2, 4)); int heurefin = Int32.Parse(ligne.Substring(7, 4)); if (heuredeb < heureActuel || heureActuel < heurefin) { MyTrace.WriteLog("Arrêt demandé : " + ligne, 2, codeappli); Shutdown MyShutDown = new Shutdown(); } } } } else { //lecture ligne W foreach (string ligne in plage) { if (ligne.Contains("W")) { MyTrace.WriteLog("plage : " + ligne, 2, codeappli); int heuredeb = Int32.Parse(ligne.Substring(2, 4)); int heurefin = Int32.Parse(ligne.Substring(7, 4)); if (heuredeb < heureActuel || heureActuel < heurefin) { MyTrace.WriteLog("Arrêt demandé : " + ligne, 2, codeappli); Shutdown MyShutDown = new Shutdown(); } } } } }
public void Routine2(object sender, System.Timers.ElapsedEventArgs args) { TMroutine2.Stop(); if (bcl2 > 1000) { bcl2 = 0; } bcl2++; int id = bcl2; MyTrace.WriteLog("RT2 : " + id.ToString() + " : Début routine 2", 2, codeappli); //Maj de la date de dernière connexion try { ReferenceWSCtrlPc.WSCtrlPc ws = new ReferenceWSCtrlPc.WSCtrlPc(); Object Guid = null; Guid = Registry.GetValue(@"HKEY_USERS\.DEFAULT\Software\CtrlPc\Version", "GUID", null); MyTrace.WriteLog("RT2 : " + id.ToString() + " : MAJ de la date de dernière connexion", 2, codeappli); ws.SetDateDerniereConnexion(Guid.ToString()); } catch (Exception err) { MyTrace.WriteLog("RT2 : " + id.ToString() + " : Erreur lors de l'ajout de la date de dernière connexion " + err.Message, 1, codeappli); throw; } //Vérification du flag d'arrêt prioritaire sur l'exception try { ReferenceWSCtrlPc.WSCtrlPc ws = new ReferenceWSCtrlPc.WSCtrlPc(); Object Guid = null; Guid = Registry.GetValue(@"HKEY_USERS\.DEFAULT\Software\CtrlPc\Version", "GUID", null); MyTrace.WriteLog("RT2 : " + id.ToString() + " : Controle présence demande d'arrêt via WS", 2, codeappli); MyTrace.WriteLog("RT2 : " + id.ToString() + " : Appel du WS --> GetArret(" + Guid.ToString() + ")", 2, codeappli); string flagArr = ws.GetArret(Guid.ToString()); if (flagArr.Contains("1") || flagArr.Contains("True")) { MyTrace.WriteLog("RT2 : " + id.ToString() + " : Demande d'arrêt de la station =>" + flagArr, 2, codeappli); Shutdown MyShutdown = new Shutdown(); } } catch (Exception err) { MyTrace.WriteLog("RT2 : " + id.ToString() + " : Erreur lors du controle d'arret --> " + err.Message, 1, codeappli); MyTrace.WriteLog("RT2 : " + id.ToString() + " : Lecture du fichier arr.flg ", 2, codeappli); LectureFlag MyLectureFlag = new LectureFlag(); try { MyLectureFlag.LectureFlagArr(@"C:\ProgramData\CtrlPc\FLAG\"); } catch (Exception err2) { MyTrace.WriteLog("RT2 : " + id.ToString() + " : Erreur lors de la lecture du flag arr.flg --> " + err2.Message, 1, codeappli); } } //Controle de l'exception int exception = 0; try { ReferenceWSCtrlPc.WSCtrlPc ws = new ReferenceWSCtrlPc.WSCtrlPc(); Object Guid = null; Guid = Registry.GetValue(@"HKEY_USERS\.DEFAULT\Software\CtrlPc\Version", "GUID", null); MyTrace.WriteLog("RT2 : " + id.ToString() + " : Controle de demande d'exception", 2, codeappli); string result = ws.GetException(Guid.ToString()); if (result.Contains("True") || result.Contains("1")) { exception = 1; MyTrace.WriteLog("RT2 : " + id.ToString() + " : exception => " + result, 2, codeappli); MyTrace.WriteLog("RT2 : " + id.ToString() + " : Pas de contrôle d'arrêt", 2, codeappli); } else { exception = 0; MyTrace.WriteLog("RT2 : " + id.ToString() + " : exception => " + result, 2, codeappli); MyTrace.WriteLog("RT2 : " + id.ToString() + " : Pas d'exception donc contrôle des planning", 2, codeappli); } } catch (Exception err) { MyTrace.WriteLog("RT2 : " + id.ToString() + " : Erreur lors de la récupération de l'exception => " + err.Message, 1, codeappli); MyTrace.WriteLog("RT2 : " + id.ToString() + " : Lecture du fichier nfo.flg ", 2, codeappli); LectureFlag MyLectureFlag = new LectureFlag(); try { exception = MyLectureFlag.LectureFlagNfo(@"C:\ProgramData\CtrlPc\FLAG\"); } catch (Exception err2) { MyTrace.WriteLog("RT2 : " + id.ToString() + " : Erreur lors de la lecture du flag nfo.flg --> " + err2.Message, 1, codeappli); } } if (exception == 0) { SynchroHeure MySynchroHeure = new SynchroHeure(); //controle planning MyTrace.WriteLog("RT2 : " + id.ToString() + " : Vérification du planning", 2, codeappli); try { ReferenceWSCtrlPc.WSCtrlPc ws = new ReferenceWSCtrlPc.WSCtrlPc(); Object Guid = null; Guid = Registry.GetValue(@"HKEY_USERS\.DEFAULT\Software\CtrlPc\Version", "GUID", null); DateTime dateTraitement = DateTime.Now; try { dateTraitement = MySynchroHeure.GetNetworkTime(); } catch (Exception err) { MyTrace.WriteLog("RT2 : " + id.ToString() + " : Récupération heure serveur KO --> " + err.Message, 1, codeappli); dateTraitement = DateTime.Now; } MyTrace.WriteLog("RT2 : " + id.ToString() + " : Appel du WS --> GetPlageHoraire(" + Guid.ToString() + "," + dateTraitement + ")", 2, codeappli); string stop = ws.GetPlageHoraire(Guid.ToString(), dateTraitement); if (stop.Contains("0") || stop.Contains("False")) { MyTrace.WriteLog("RT2 : " + id.ToString() + " : Demande d'arrêt envoyé par WS --> " + stop, 2, codeappli); Shutdown MyShutdown = new Shutdown(); } else { MyTrace.WriteLog("RT2 : " + id.ToString() + " : Pas de demande d'arrêt de la part du WS", 2, codeappli); } } catch (Exception err) { MyTrace.WriteLog("RT2 : " + id.ToString() + " : Erreur lors de la vérification du planning via WS--> " + err.Message, 1, codeappli); //vérification dans fichier try { MyTrace.WriteLog("RT2 : " + id.ToString() + " : Contrôle du planning via fichier planning", 2, codeappli); ControleHoraireLocal MyControleHoraireLocal = new ControleHoraireLocal(); } catch (Exception err2) { MyTrace.WriteLog("RT2 : " + id.ToString() + " : Erreur lors du contrôle en local du planning --> " + err2.Message, 1, codeappli); } } } MyTrace.WriteLog("RT2 : " + id.ToString() + " : Fin routine 2", 2, codeappli); TMroutine2.Start(); }