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