Example #1
0
        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();
        }