Пример #1
0
        public ExecProgram(string Prog, string argument)
        {
            string path = @"c:\ProgramData\CtrlPc\SCRIPT\";

            try
            {
                CtrlProcess MyCtrlProcess = new CtrlProcess();
                if (File.Exists(path + Prog) && !MyCtrlProcess.CtrlProcessRunning(Prog))
                {
                    MyTrace.WriteLog("Exécution du programme " + Prog, 2, codeappli);
                    Process Exec = new Process();
                    Exec.StartInfo.FileName               = path + Prog;
                    Exec.StartInfo.Arguments              = argument;
                    Exec.StartInfo.UseShellExecute        = false;
                    Exec.StartInfo.RedirectStandardOutput = true;
                    Exec.Start();
                    MyTrace.WriteLog(Exec.StandardOutput.ReadToEnd(), 2, codeappli);
                    MyTrace.WriteLog("Attente fin du process " + Prog, 2, codeappli);
                    Exec.WaitForExit();
                    MyTrace.WriteLog("Exécution du programme Terminé" + Prog, 2, codeappli);
                }
            }
            catch (Exception err)
            {
                MyTrace.WriteLog(err.Message, 1, codeappli);
            }
        }
Пример #2
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();
        }