public static void LoadCfg(string path)
        {
            ClearInfo();
            Directory.CreateDirectory(WorkingDirectory);
            //AppList = new List<Application>();
            string[] strings;
            try {
                strings = File.ReadAllLines(path);
            }
            catch {
                strings = new string[0];
                WriteInfo(String.Format("Cannot read the file: {0}", path));
                RefrashConsoleNow();
                return;
            }

            var existAppsIndex = 0;
            try {
                for (int i = 0; i < strings.Count(); i++) {
                    const char separator = ';';
                    var splt = strings[i].Split(separator);

                    var execPatch = splt.Any() ? splt[0] : strings[i];
                    var delay = splt.Count() > 1 ? Int32.Parse(splt[1]) : 0;

                    if (File.Exists(execPatch)) {
                        //AppList.Add(new Application());
                        //AppList[AppList.Count - 1].FileName = execPatch;
                        //AppList[AppList.Count - 1].WorkingDirectory = WorkingDirectory;
                        //AppList[AppList.Count - 1].NumberApp = AppList.Count - 1;
                        //AppList[AppList.Count - 1].DelayAfterExecute = delay;
                        var appDescr = new Application();
                        appDescr.FileName = execPatch;
                        appDescr.WorkingDirectory = WorkingDirectory;
                        appDescr.DelayAfterExecute = delay;
                        InsertApp(appDescr, existAppsIndex++);
                        WriteInfo(String.Format("Application added, path = {0}", strings[i]));
                    }
                    else {
                        WriteInfo(String.Format("###Application not found: {0}", strings[i]));
                        RefrashConsoleNow();
                    }
                }
            }
            catch (Exception e) {
                WriteInfo(String.Format("###Cannot read the file: {0}, bad format call exeption: {1}", path,
                                        e.ToString()));
                RefrashConsoleNow();
                throw e;
            }
            RemoveExcessApps(existAppsIndex);
            PrintInfo(InfoBuffer);
        }
 private static bool VeryByExec(Application application, int verifyTreshold, int verifyDelay)
 {
     var verifyTry = 0;
     while (!application.ProcessIsRun()) {
         if (verifyTry > verifyTreshold)
             return false;
         else {
             verifyTry++;
             Thread.Sleep(verifyDelay);
         }
     }
     return true;
 }
예제 #3
0
 public static void InsertApp(Application appDescription, int line)
 {
     if (AppList.Count > line) {
         if (AppDescComparison(AppList[line], appDescription))
             AppList[line].DelayAfterExecute = appDescription.DelayAfterExecute;
         else {
             AppList[line].KillProc();
             AppList[line] = appDescription;
         }
     }
     else
         AppList.Add(appDescription);
     AppList[AppList.Count - 1].NumberApp = AppList.Count - 1;
 }
예제 #4
0
 public static bool AppDescComparison(Application appDescription1, Application appDescription2)
 {
     return (appDescription1.FileName == appDescription2.FileName); // &&
     //(appDescription1.DelayAfterExecute == appDescription2.DelayAfterExecute);
 }