private void btnSaveMatrix_Click(object sender, EventArgs e) { if (this.dlgSaveModel.ShowDialog() == DialogResult.OK) { try { string filePath = dlgSaveModel.FileName; if (filePath.EndsWith(ExcelExporter.ExcelFileExtension, StringComparison.InvariantCultureIgnoreCase)) { ExcelExporter excelExporter = new ExcelExporter(new ExcelExporterSettings() { ExportWhat = ExportableData.Experiments | ExportableData.ValidExperiments, FilePath = filePath }); excelExporter.Export(this._model); } else { modelProvider.Save(this._model, filePath); } } catch (Exception ex) { MessageBoxHelper.ShowError("Невозможно выполнить сохранение по указанному пути\nОригинальное сообщение: " + ex.Message); return; } this.dlgSaveModel.FileName = string.Empty; } }
public static void Main(string[] args) { Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; CommandLineOptions options = CommandLineOptions.Parse(args); if (options != null) { Model model = modelProvider.Load(options.ModelFilePath); ExcelPackage excel = new ExcelPackage(new FileInfo(options.ExcelFilePath)); ExcelWorksheet dataSheet = excel.Workbook.Worksheets["Single-objective points"]; for (int i = 1; i <= 60; i++) { Experiment e = new Experiment(model.Experiments.GetFreeConsequentId(), i + 100); for (int col = 1; col <= 11; col++) { e.ParameterValues.Add(col - 1, Convert.ToDouble(dataSheet.Cells[i, col].Value)); } model.Experiments.Add(e.Id, e); } modelProvider.Save(model, options.ModelFilePath); } }
private void btnSaveMatrix_Click(object sender, EventArgs e) { if (this.dlgSaveModel.ShowDialog() == DialogResult.OK) { try { modelProvider.Save(this._model, this.dlgSaveModel.FileName); } catch (Exception ex) { MessageBoxHelper.ShowError("Невозможно выполнить сохранение по указанному пути\nОригинальное сообщение: " + ex.Message); return; } this.dlgSaveModel.FileName = string.Empty; } }
public void ProcessModel(object data) { CancellationToken cancellationToken; if (data == null) { cancellationToken = new CancellationToken(false); } else { cancellationToken = (CancellationToken)data; } if (cancellationToken.IsCancellationRequested) { OnProcessingComplete(new EventArgs()); return; } model = modelProvider.Load(optFile); if (cancellationToken.IsCancellationRequested) { OnProcessingComplete(new EventArgs()); return; } int maxProgress = model.Experiments.Count; OnProgressChanged(new ProgressChangedEventArgs(0, maxProgress, 0, "Initialized")); int exp = 0; foreach (Experiment experiment in model.Experiments.Values) { if (cancellationToken.IsCancellationRequested) { break; } ProcessExperiment(experiment); OnProgressChanged(new ProgressChangedEventArgs(0, maxProgress, ++exp, "Processed experiment #" + experiment.Number.ToString())); } if (cancellationToken.IsCancellationRequested) { OnProcessingComplete(new EventArgs()); return; } modelProvider.Save(model, optFile); OnProcessingComplete(new EventArgs()); }
private static bool UseExternalApplication( Model initModel, string externalAppPath, string dataFilePath) { // Запишем файл модели try { modelProvider.Save(initModel, dataFilePath); } catch (Exception ex) { MessageBoxHelper.ShowError("Не удалось создать файл для обмена данными по указанному пути\nОригинальное сообщение: " + ex.Message); return(false); } // Дождемся, пока будет создан файл bool fileExists = false; while (!fileExists) { if (System.IO.File.Exists(dataFilePath)) { fileExists = true; } else { Thread.Sleep(500); } } // Запуск внешней проги и ожидание расчета ProcessStartInfo midPrgInfo = new ProcessStartInfo(); midPrgInfo.FileName = externalAppPath; midPrgInfo.Arguments = "\"" + dataFilePath + "\""; midPrgInfo.UseShellExecute = false; Process extAppProc = Process.Start(midPrgInfo); extAppProc.EnableRaisingEvents = true; // Дождемся, пока внешний процесс не завершится while (!extAppProc.HasExited) { Thread.Sleep(500); } return(true); }
private string CreateExchangeFile(Model optModel, BionicSolverSettings settings) { string exchangeFilePath = Path.Combine(Path.GetDirectoryName(settings.CalcApplicationPath), "temp.xml"); modelProvider.Save(optModel, exchangeFilePath); // Wait for the file to be created and written to disk // TODO: Looks like a dirty hack. Maybe there is more elegant solution... while (true) { if (File.Exists(exchangeFilePath)) { break; } Thread.Sleep(500); } return(exchangeFilePath); }