private Delegate _UpdateRichTextBox; // Delegate (for invoking the method which update the RTB). #endregion Fields #region Constructors public Launcher(Config config, Boolean preProcess, Boolean process, Boolean control, Boolean headerConsistency, List<String> listInputFiles, String logsPath, Delegate del, Delegate del2, Delegate del3, Delegate del4) { _Config = config; _PreProcess = preProcess; _Process = process; _Control = control; _HeaderConsistency = headerConsistency; _HasTxt2Xml = false; _Progress = 0; _ID = 0; _NumberOfProcesses = 0; foreach (Process p in _Config.Get_ProcessList()) { if ((p.Get_OrderId() < 0 && _PreProcess) || ((p.Get_OrderId() > 0 & p.Get_OrderId() < 100) && _Process) || ((p.Get_OrderId() > 100 && _Control))) _NumberOfProcesses++; } _Logs = null; _InputFiles = new List<String>(); _InputFiles = listInputFiles; _OutputFiles = new List<String>(); _TabData = new List<String>(); _FileCounter = 0; _LogsPath = logsPath; _DatamodPath = null; _CurrentFile = null; _UpdateProgressBar = del; _UpdateRichTextBox = del2; _AddLogsGridView = del3; _DisplayConfigProcessTime = del4; }
private void LaunchBatchMulti(Batch batch) { foreach (KeyValuePair<Tuple<string,string>, List<Tuple<string, string>>> element in batch.Get_BatchElementsMulti()) { int configCounter = 1; // Define paths (input, logs) DirectoryInfo targetPath = new DirectoryInfo(element.Key.Item1); FileInfo[] inputFiles = targetPath.GetFiles(); _InputFiles.Clear(); foreach (FileInfo file in inputFiles) _InputFiles.Add(file.FullName); // Create Config/Instanciate launcher for each config of each batch element foreach (Tuple<string, string> config in element.Value) { // Copy all inputs in a separated directory if (!Directory.Exists(targetPath + "\\" + configCounter.ToString())) Directory.CreateDirectory(targetPath + "\\" + configCounter.ToString()); foreach (String input in _InputFiles) File.Copy(input, targetPath + "\\" + configCounter.ToString() + "\\" + Path.GetFileName(input), true); // Redefine paths DirectoryInfo specificTargetPath = new DirectoryInfo(targetPath + "\\" + configCounter.ToString()); FileInfo[] specificInputFiles = specificTargetPath.GetFiles(); List<string> specificInputs = new List<string>(); string specificLogPath = specificTargetPath.FullName; foreach (FileInfo file in specificInputFiles) specificInputs.Add(file.FullName); // Create a new config Config specificConfig = new Config(config.Item1, config.Item2); // Create launcher and associated UC. _LaunchersList.Add(new Launcher(specificConfig, PreProcessButton.Checked, ProcessButton.Checked, ControlsButton.Checked, HCButton.Checked, new List<String>(specificInputs), specificLogPath, _UpdateProgressBarDel, _UpdateRichTextBoxDel, _AddLogsGridViewDel, _DisplayConfigProcessTimeDel)); _ProgressBarsList.Add(new ProgressBar(specificConfig.Get_Name(), _ProgressBarsList.Count, _AbortThreadDel)); _Navigator.ProgressGroupBox.Panel.Controls.Add(_ProgressBarsList[_ProgressBarsList.Count - 1]); _LogsList.Add(new Log(specificConfig.Get_Name(), specificConfig.Get_TargetsNumber(), PreProcessButton.Checked, ProcessButton.Checked, ControlsButton.Checked)); _Navigator.LogsNavigator.Pages.Insert(0, _LogsList[_LogsList.Count - 1].Get_NavigatorTab()); _Navigator.LogsNavigator.SelectedIndex = 0; _LogsList[_LogsList.Count - 1].Get_NavigatorTab().ButtonSpecs[0].Click += new EventHandler(_Navigator.CloseLogsNavigatorTab); _PoolThreads.Add(new Thread(() => _LaunchersList[_LaunchersList.Count - 1].Run(_LaunchersList.Count - 1))); _PoolThreads[_PoolThreads.Count - 1].IsBackground = true; _PoolThreads[_PoolThreads.Count - 1].Start(); configCounter++; } } }
private void LaunchBatchSingle(Batch batch) { foreach (KeyValuePair<string, Tuple<string, string, string>> element in batch.Get_BatchElements()) { /* Define paths (input, logs) */ DirectoryInfo targetPath = new DirectoryInfo(element.Key); FileInfo[] inputFiles = targetPath.GetFiles(); _InputFiles.Clear(); foreach (FileInfo file in inputFiles) { _InputFiles.Add(file.FullName); _LogsPath = file.Directory.FullName; } /* Create a new config */ Config config = new Config(element.Value.Item1, element.Value.Item2); /* Create launcher and associated UC. */ _LaunchersList.Add(new Launcher(config, PreProcessButton.Checked, ProcessButton.Checked, ControlsButton.Checked, HCButton.Checked, new List<String>(_InputFiles), _LogsPath, _UpdateProgressBarDel, _UpdateRichTextBoxDel, _AddLogsGridViewDel, _DisplayConfigProcessTimeDel)); _ProgressBarsList.Add(new ProgressBar(config.Get_Name(), _ProgressBarsList.Count, _AbortThreadDel)); _Navigator.ProgressGroupBox.Panel.Controls.Add(_ProgressBarsList[_ProgressBarsList.Count - 1]); _LogsList.Add(new Log(config.Get_Name(), config.Get_TargetsNumber(), PreProcessButton.Checked, ProcessButton.Checked, ControlsButton.Checked)); _Navigator.LogsNavigator.Pages.Insert(0, _LogsList[_LogsList.Count - 1].Get_NavigatorTab()); _Navigator.LogsNavigator.SelectedIndex = 0; _LogsList[_LogsList.Count - 1].Get_NavigatorTab().ButtonSpecs[0].Click += new EventHandler(_Navigator.CloseLogsNavigatorTab); _PoolThreads.Add(new Thread(() => _LaunchersList[_LaunchersList.Count - 1].Run(_LaunchersList.Count - 1))); _PoolThreads[_PoolThreads.Count - 1].IsBackground = true; _PoolThreads[_PoolThreads.Count - 1].Start(); } }
/********************\ * Clone the object * \********************/ public Config Clone() { Config clonedConfig = new Config(); BinaryFormatter formatter = new BinaryFormatter(); MemoryStream stream = new MemoryStream(); clonedConfig._Name = this._Name; clonedConfig._Path = this._Path; clonedConfig._Warning = this._Warning; clonedConfig._XmlEncoding = this._XmlEncoding; clonedConfig._XmlDocument = this._XmlDocument; formatter.Serialize(stream, _ProcessList); stream.Position = 0; clonedConfig._ProcessList = (List<Process>)formatter.Deserialize(stream); clonedConfig._DataSeparator = this._DataSeparator; clonedConfig._OutputSeparator = this._OutputSeparator; clonedConfig._DecimalSeparator = this._DecimalSeparator; clonedConfig._Headerlines = this._Headerlines; clonedConfig._TargetsNumber = this._TargetsNumber; clonedConfig._EncodingInput = this._EncodingInput; clonedConfig._EncodingOutput = this._EncodingOutput; clonedConfig._CountryCode = this._CountryCode; clonedConfig._ConfigType = this._ConfigType; return clonedConfig; }