public LectureFileExecProgram()
        {
            //recup sur ftp toutes les 15 min du flag arr.flg

            MyTrace.WriteLog("Contrôle Exécution programme", 2, codeappli);
            try
            {
                string pathExecProg = @"c:\ProgramData\CtrlPc\SCRIPT\ExecProgram.csv";
                if (File.Exists(pathExecProg))
                {
                    string[] prog = File.ReadAllLines(pathExecProg);
                    if (prog.Length > 0)
                    {
                        foreach (string progLigne in prog)
                        {
                            if (progLigne.Length > 0)
                            {
                                string[] Colonne = progLigne.Split(';');
                                MyTrace.WriteLog("Demande Exécution : " + Colonne[0] + " Avec arguments : " + Colonne[1], 2, codeappli);
                                ExecProgram MyExecProgram = new ExecProgram(Colonne[0], Colonne[1]);
                            }
                        }
                    }
                }
            }
            catch (Exception err)
            {
                MyTrace.WriteLog(err.Message, 2, codeappli);
            }
        }
Exemple #2
0
        protected override void OnStart(string[] args)
        {
            EventLog.WriteEntry("Démarrage du service");
            // Update the service state to Start Pending.
            ServiceStatus serviceStatus = new ServiceStatus();

            serviceStatus.dwCurrentState = ServiceState.SERVICE_START_PENDING;
            serviceStatus.dwWaitHint     = 100000;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);

            // Update the service state to Running.
            serviceStatus.dwCurrentState = ServiceState.SERVICE_RUNNING;
            SetServiceStatus(this.ServiceHandle, ref serviceStatus);

            // Set up a timer to trigger every minute.
            //TMroutine1 = new System.Timers.Timer();
            TMroutine1.Interval = 900000; // 15 min
            TMroutine1.Elapsed += new System.Timers.ElapsedEventHandler(this.Routine1);
            TMroutine1.Start();

            //TMroutine2 = new System.Timers.Timer();
            TMroutine2.Interval = 120000; // 2 min
            TMroutine2.Elapsed += new System.Timers.ElapsedEventHandler(this.Routine2);
            TMroutine2.Start();

            //TMroutine3 = new System.Timers.Timer();
            TMroutine3.Interval = 60000; //  1 min
            TMroutine3.Elapsed += new System.Timers.ElapsedEventHandler(this.Routine3);
            TMroutine3.Start();

            EventLog.WriteEntry("Ecriture journal.log");
            try
            {
                MyTrace.WriteLog("START : Démarage du service ServiceCtrlPc", 2, codeappli);
                string path = @"c:\ProgramData\CtrlPc\";
                MyTrace.WriteLog("START : Récupération de fichiers à télécharger", 2, codeappli);
                try
                {
                    ReferenceWSCtrlPc.WSCtrlPc ws = new ReferenceWSCtrlPc.WSCtrlPc();
                    Object Guid = null;
                    EventLog.WriteEntry("Récupération fichier de maj");
                    Guid = Registry.GetValue(@"HKEY_USERS\.DEFAULT\Software\CtrlPc\Version", "GUID", null);
                    MyTrace.WriteLog("START : Appel du WS --> GetDownloadFile(" + Guid.ToString() + "," + DateTime.Now + ")", 2, codeappli);
                    string FileDownload = ws.GetDownloadFile(Guid.ToString(), DateTime.Now);
                    if (FileDownload.Length > 0)
                    {
                        string[] LstFileDownload = FileDownload.Split('\r');
                        foreach (string ligne in LstFileDownload)
                        {
                            MyTrace.WriteLog("START : Téléchargement de " + ligne, 2, codeappli);
                            string      argument      = ligne.Replace(";", " ");
                            ExecProgram MyExecProgram = new ExecProgram("DownloadFile.exe", argument);
                            MyTrace.WriteLog("START : Téléchargement terminé de " + ligne, 2, codeappli);
                            //mise a jour de la bdd via ws
                            string[] colonne = ligne.Split(new Char[] { ';' });
                            MyTrace.WriteLog("START : Appel du WS --> SetDownloadFile(" + Guid.ToString() + "," + DateTime.Now + "," + colonne[0] + "," + colonne[1] + ")", 2, codeappli);
                            ws.SetDownloadFile(Guid.ToString(), DateTime.Now, colonne[0], colonne[1]);
                        }
                    }
                    else
                    {
                        MyTrace.WriteLog("START : Aucun fichier à télécharger ", 2, codeappli);
                    }
                }
                catch (Exception err)
                {
                    MyTrace.WriteLog(err.Message, 1, codeappli);
                }
                EventLog.WriteEntry("fin récupération fichier de maj");
                EventLog.WriteEntry("Génération des fichiers de paramètrage");
                try
                {
                    MyTrace.WriteLog("START : Génération des fichiers de paramètrage", 2, codeappli);
                    ExecProgram MyExecProgram = new ExecProgram("GeneFileParam.exe", "0");
                }
                catch (Exception err)
                {
                    MyTrace.WriteLog("START : Génération des fichier ko --> " + err.Message, 1, codeappli);
                }

                MyTrace.WriteLog("START : Contrôle du flag arr.flg", 2, codeappli);
                LectureFlag MyLectureFlag = new LectureFlag();
                MyLectureFlag.LectureFlagArr(path + @"FLAG\");
            }

            catch (Exception err)
            {
                EventLog.WriteEntry(err.Message);
            }
        }
Exemple #3
0
        public void Routine3(object sender, System.Timers.ElapsedEventArgs args)
        {
            TMroutine3.Stop();
            if (bcl3 > 1000)
            {
                bcl3 = 0;
            }
            bcl3++;
            int id = bcl3;

            MyTrace.WriteLog("RT3 : " + id.ToString() + " : Début Routine 3", 2, codeappli);
            SynchroHeure MySynchroHeure = new SynchroHeure();

            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("RT3 : " + id.ToString() + " : Récupération heure serveur KO --> " + err.Message, 1, codeappli);
                dateTraitement = DateTime.Now;
            }
            try
            {
                MyTrace.WriteLog("RT3 : " + id.ToString() + " : Appel du WS --> GetExecProgram(" + Guid.ToString() + ", " + dateTraitement + ")", 2, codeappli);
                string ExecProgram = ws.GetExecProgram(Guid.ToString(), dateTraitement);
                if (ExecProgram.Length > 0 && !ExecProgram.Contains("0;0"))
                {
                    string[] ExecProgramLine = ExecProgram.Split(Environment.NewLine.ToCharArray());
                    foreach (string ligne in ExecProgramLine)
                    {
                        if (ligne.Length > 0 && ligne.Contains(";"))
                        {
                            MyTrace.WriteLog("RT3 : " + id.ToString() + " : Parse de la ligne suivante : " + ligne, 2, codeappli);
                            string[] colonne = ligne.Split(';');
                            try
                            {
                                string      path          = @"c:\ProgramData\CtrlPc\SCRIPT\";
                                CtrlProcess MyCtrlProcess = new CtrlProcess();
                                if (File.Exists(path + colonne[1]) && !MyCtrlProcess.CtrlProcessRunning(colonne[1]))
                                {
                                    MyTrace.WriteLog("RT3 : " + id.ToString() + " : Process non trouvé pour l'aplpication : " + colonne[1], 2, codeappli);
                                    dateTraitement = DateTime.Now;
                                    try
                                    {
                                        dateTraitement = MySynchroHeure.GetNetworkTime();
                                    }
                                    catch (Exception err)
                                    {
                                        MyTrace.WriteLog("RT3 : " + id.ToString() + " : Récupération heure serveur KO --> " + err.Message, 1, codeappli);
                                        dateTraitement = DateTime.Now;
                                    }
                                    MyTrace.WriteLog("RT3 : " + id.ToString() + " : Appel du WS --> SetExecProgram(" + Convert.ToInt32(colonne[0]) + "," + dateTraitement + ")", 2, codeappli);
                                    ws.SetExecProgram(Convert.ToInt32(colonne[0]), dateTraitement);
                                    ExecProgram MyExecProgram = new ExecProgram(colonne[1], "0");
                                }
                                else
                                {
                                    MyTrace.WriteLog("RT3 : " + id.ToString() + " : Le program n'est^pas présent : " + ligne, 1, codeappli);
                                }
                            }
                            catch (Exception err)
                            {
                                MyTrace.WriteLog("RT3 : " + id.ToString() + " : " + err.Message, 1, codeappli);
                            }
                        }
                    }
                }
                else
                {
                    MyTrace.WriteLog("RT3 : " + id.ToString() + " : Aucun program à exécuter", 2, codeappli);
                }
            }
            catch (Exception err)
            {
                MyTrace.WriteLog("RT3 : " + id.ToString() + " : ERREUR --> " + err.Message, 1, codeappli);
                MyTrace.WriteLog("RT3 : " + id.ToString() + " : Lecture du fichier d'exécution de program", 2, codeappli);
                try
                {
                    LectureFileExecProgram MyStartRoutine1 = new LectureFileExecProgram();
                }
                catch (Exception err2)
                {
                    MyTrace.WriteLog("RT3 : " + id.ToString() + " : Lecture du fichier csv --> " + err2.Message, 1, codeappli);
                }
            }

            MyTrace.WriteLog("RT3 : " + id.ToString() + " : Fin Routine 3", 2, codeappli);
            TMroutine3.Start();
        }
Exemple #4
0
        public void Routine1(object sender, System.Timers.ElapsedEventArgs args)
        {
            TMroutine1.Stop();
            if (bcl1 > 1000)
            {
                bcl1 = 0;
            }
            bcl1++;
            int id = bcl1;

            //Exécution des program et création des fichiers de param et téléchargement des maj
            //création fichier param
            MyTrace.WriteLog("RT1 : " + id.ToString() + " : Début routine 1", 2, codeappli);
            SynchroHeure MySynchroHeure = new SynchroHeure();

            try
            {
                ReferenceWSCtrlPc.WSCtrlPc ws = new ReferenceWSCtrlPc.WSCtrlPc();
                Object Guid = null;
                Guid = Registry.GetValue(@"HKEY_USERS\.DEFAULT\Software\CtrlPc\Version", "GUID", null);
                MyTrace.WriteLog("RT1 : " + id.ToString() + " : Création de fichiers de paramètrage", 2, codeappli);
                ExecProgram MyExecProgram = new ExecProgram("GeneFileParam.exe", "0");
            }
            catch (Exception err)
            {
                MyTrace.WriteLog("RT1 : " + id.ToString() + " : Erreur lors de la création des fichier de paramètrage --> " + err.Message, 1, codeappli);
            }
            //téléchargement des fichiers :
            try
            {
                ReferenceWSCtrlPc.WSCtrlPc ws = new ReferenceWSCtrlPc.WSCtrlPc();
                Object Guid = null;
                Guid = Registry.GetValue(@"HKEY_USERS\.DEFAULT\Software\CtrlPc\Version", "GUID", null);
                MyTrace.WriteLog("RT1 : " + id.ToString() + " : Controle des fichiers à télécharger", 2, codeappli);
                DateTime dateTraitement = DateTime.Now;
                try
                {
                    dateTraitement = MySynchroHeure.GetNetworkTime();
                }
                catch (Exception err)
                {
                    MyTrace.WriteLog("RT1 : " + id.ToString() + " : Récupération heure serveur KO --> " + err.Message, 1, codeappli);
                    dateTraitement = DateTime.Now;
                }
                string FileDownload = ws.GetDownloadFile(Guid.ToString(), dateTraitement);
                if (FileDownload.Length > 0)
                {
                    string[] LstFileDownload = FileDownload.Split(Environment.NewLine.ToCharArray());
                    foreach (string ligne in LstFileDownload)
                    {
                        string argument = ligne.Replace(";", " ");
                        if (argument.Length > 3)
                        {
                            MyTrace.WriteLog("RT1 : " + id.ToString() + " : Téléchargement de " + ligne, 2, codeappli);
                            ExecProgram MyExecProgram = new ExecProgram("DownloadFile.exe", argument);
                            MyTrace.WriteLog("RT1 : " + id.ToString() + " : Téléchargement terminé de " + ligne, 2, codeappli);
                            //mise a jour de la bdd via ws
                            string[] colonne = ligne.Split(new Char[] { ';' });
                            try
                            {
                                dateTraitement = MySynchroHeure.GetNetworkTime();
                            }
                            catch (Exception err)
                            {
                                MyTrace.WriteLog("RT1 : " + id.ToString() + " : Récupération heure serveur KO --> " + err.Message, 1, codeappli);
                                dateTraitement = DateTime.Now;
                            }
                            //Vérification si le fichier a bien été téléchargé
                            //string pathControle = ligne.Replace(";", @"\");
                            if (File.Exists(@"c:\ProgramData\CtrlPc\" + colonne[0] + @"\" + colonne[1]))
                            {
                                MyTrace.WriteLog("RT1 : " + id.ToString() + " :Téléchargement réussi : " + colonne[0] + @"\" + colonne[1], 2, codeappli);
                                MyTrace.WriteLog("RT1 : " + id.ToString() + " : Appel du WS --> SetDownloadFile(" + Guid.ToString() + "," + dateTraitement + "," + colonne[0] + "," + colonne[1] + ")", 2, codeappli);
                                ws.SetDownloadFile(Guid.ToString(), dateTraitement, colonne[0], colonne[1]);
                            }
                            else
                            {
                                MyTrace.WriteLog("RT1 : " + id.ToString() + " : Téléchargement KO : " + colonne[0] + @"\" + colonne[1], 1, codeappli);
                            }
                        }
                        else
                        {
                            MyTrace.WriteLog("RT1 : " + id.ToString() + " : Aucun fichier à télécharger ", 2, codeappli);
                        }
                    }
                }
                else
                {
                    MyTrace.WriteLog("RT1 : " + id.ToString() + " : Aucun fichier à télécharger ", 2, codeappli);
                }
            }
            catch (Exception err)
            {
                MyTrace.WriteLog("RT1 : " + id.ToString() + " : Erreur lors du téléchargement --> " + err.Message, 1, codeappli);
                MyTrace.WriteLog("RT1 : " + id.ToString() + " : Erreur lors du téléchargement détail--> " + err.StackTrace, 1, codeappli);
            }

            MyTrace.WriteLog("RT1 : " + id.ToString() + " : Fin routine 1", 2, codeappli);
            TMroutine1.Start();
        }