Esempio n. 1
0
        public bool ExecuteBatchConnection(BatchConnection batchConn)
        {
            StopFlag = false;

            WriteToRDSLog(batchConn.FileNameLog, "Начат процесс чтения");

            tmpLogString = "";
            if (BatchFileExecutionStartEvent != null)
                BatchFileExecutionStartEvent.Invoke(null, new EventArgs());

            if (!batchConn.ExistsRDS)
                return false;

            // запускаем процесс
            psiOpt.FileName = "\"" + batchConn.FileNameRDSLib + "\"";
            psiOpt.Arguments = batchConn.ArgumentsForRDS;

            procCommand = Process.Start(psiOpt);
            procCommand.EnableRaisingEvents = true;

            //procCommand.Exited += new EventHandler(procCommand_Exited);
            procCommand.OutputDataReceived += new DataReceivedEventHandler(procCommand_OutputStreamDataReceived);
            procCommand.ErrorDataReceived += new DataReceivedEventHandler(procCommand_OutputStreamDataReceived);

            procCommand.BeginOutputReadLine();
            procCommand.BeginErrorReadLine();

            bool tmpRes = false;
            for (int t = 0; t < waitRDSTimeInSec; t++)
            {
                if (StopFlag)
                    break;

                if (procCommand.HasExited)
                {
                    if (IsDatFileAvailable(batchConn.FileNameDump))
                        tmpRes = true;
                    break;
                }

                Thread.Sleep(1000);

                if (BatchFileTickEvent != null)
                    BatchFileTickEvent.Invoke(null, new EventArgs());
            }

            if (!tmpRes)
            {
                WriteToRDSLog(batchConn.FileNameLog, "Не удалось прочитать данные");
            }

            if (BatchFileExecutionEndEvent != null)
                BatchFileExecutionEndEvent.Invoke(null, new EventArgs());

            if (tmpLogString.Length > 0)
                WriteToRDSLog(batchConn.FileNameLog, tmpLogString);

            try
            {
                procCommand.Close();
            }
            catch (Exception ex)
            {}

            return tmpRes;
        }
Esempio n. 2
0
        private bool CreateBatchConnectionList(List<FileInfo> fileInfoList, ref List<BatchConnection> batchConnectionList)
        {
            batchConnectionList = new List<BatchConnection>();

            for (int i = 0; i < fileInfoList.Count; i++)
            {
                try
                {
                    FileStream fs = new FileStream(fileInfoList[i].FullName, FileMode.Open);
                    StreamReader sr = new StreamReader(fs);
                    BatchConnection bConn = new BatchConnection(sr.ReadToEnd(), fileInfoList[i].FullName);

                    batchConnectionList.Add(bConn);
                    sr.Close();
                    fs.Close();
                }
                catch (Exception ex)
                {
                    return false;
                }
            }

            if (batchConnectionList.Count == 0)
                return false;

            return true;
        }