Esempio n. 1
0
 private static bool SplitAndExec(string fileText)
 {
     try
     {
         bool          isOk      = true;
         List <string> queryList = SplitQuery(fileText);
         foreach (var query in queryList)
         {
             try
             {
                 ManagerDB.ExecCommand(query);
             }
             catch (Exception)
             {
                 isOk = false;
             }
         }
         return(isOk);
     }
     catch (Exception)
     {
         throw;
     }
 }
Esempio n. 2
0
        public static void ProgsToExec(ExecProgsType taskName)
        {
            try
            {
                _report = "Выполнение программ...\n\n";
                ReportUpdated?.Invoke(_report);
                if (QMediator.PathToProgDest != null)
                {
                    string str;
                    if (taskName == ExecProgsType.Oktel)
                    {
                        str = "\\post!\\oktel";
                        QMediator.CurrentTaskName = TaskName.Oktel;
                        DbNotification.ResultWaiter();
                    }
                    else
                    {
                        str = taskName == ExecProgsType.PredProgs ? "\\!pred" : "\\post!";
                    }

                    string path = QMediator.PathToProgDest + str;
                    if (!new DirectoryInfo(path).Exists)
                    {
                        Directory.CreateDirectory(path);
                        _report = "Нет программ для выполнения.";
                    }
                    else
                    {
                        List <string> filePathList = GetFilesForExec(path);
                        if (filePathList.Count < 1)
                        {
                            _report = "Нет программ для выполнения.";
                            ReportUpdated?.Invoke(_report);

                            if (taskName == ExecProgsType.PredProgs)
                            {
                                TaskFinished?.Invoke(TaskName.PredProgs);
                            }
                            else if (taskName == ExecProgsType.PostProgs)
                            {
                                TaskFinished?.Invoke(TaskName.PostProgs);
                            }
                            else
                            {
                                TaskFinished?.Invoke(TaskName.Oktel);
                            }

                            return;
                        }
                        foreach (var item in filePathList)
                        {
                            _report += Environment.NewLine + "Файл:\t\t" + item;
                            bool   isOk     = true;
                            string fileText = File.ReadAllText(item, Encoding.Default);
                            try
                            {
                                if (fileText.ToLower().Contains("begin"))
                                {
                                    ManagerDB.ExecCommand(fileText);
                                }
                                else
                                {
                                    isOk = SplitAndExec(fileText);
                                }
                            }
                            catch (Exception ex)
                            {
                                isOk = false;
                                ExceptionHandler("ProgsToExec()", ex.Message);
                            }
                            _report += ("\t" + (isOk == true ? "отработал нормально." : "отработал с ошибками.") + Environment.NewLine);
                        }
                    }
                }
                else
                {
                    _report = "Не определен путь к программам.";
                }

                ReportUpdated?.Invoke(_report);
                if (taskName == ExecProgsType.PredProgs)
                {
                    TaskFinished?.Invoke(TaskName.PredProgs);
                }
                else if (taskName == ExecProgsType.PostProgs)
                {
                    TaskFinished?.Invoke(TaskName.PostProgs);
                }
                else
                {
                    TaskFinished?.Invoke(TaskName.Oktel);
                }
            }
            catch (Exception ex)
            {
                ExceptionHandler("ProgsToExec()", ex.Message);
            }
        }