private async void DumpButton_Click(object sender, EventArgs e) { if (outputPathTextBox.Text == "") { MessageBox.Show("You must specify an output file.", "No output file", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } if ((int)minCountInput.Value == 1) { var result = MessageBox.Show("Are you sure you want to dump ALL positions? This may take a lot of space.", "Confirm", MessageBoxButtons.YesNo); if (result == DialogResult.No) { return; } } var pgns = GetPgns(); if (pgns.Count == 0) { MessageBox.Show("You must specify at least one input file.", "No input files", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1); return; } DisableInput(); var filters = new EpdDumpFilters { MinCount = (int)minCountInput.Value, MaxPly = (int)maxPlyNumericUpDown.Value, MinPieces = (int)minPiecesNumericUpDown.Value }; await Task.Run(() => Dump( pgns, outputPathTextBox.Text, GetTempPaths(), filters, GetOutputElements() )); }
private void Dump(List <string> pgns, string outPath, List <string> tempPaths, EpdDumpFilters filters, List <EpdDumpOutputElement> elems) { try { database.Dump(pgns, outPath, tempPaths, filters, elems, ProgressCallback); MessageBox.Show( String.Format( "Finished.\nGames processed: {0}\nPositions processed: {1}\nPositions dumped: {2}", NumGames, NumPosIn, NumPosOut ) ); if (InvokeRequired) { Invoke(new Action(Close)); } else { Close(); } } catch (Exception ex) { MessageBox.Show("Finished with errors. " + ex.Message); if (InvokeRequired) { Invoke(new Action(EnableInput)); } else { EnableInput(); } } KeepFormAlive = false; }
public void Dump( List <string> pgns, string outPath, List <string> tempPaths, EpdDumpFilters filters, List <EpdDumpOutputElement> outputElements, Action <JsonValue> callback ) { if (outputElements.Count == 0) { throw new ArgumentException("No output elements specified."); } lock (Lock) { var stream = Client.GetStream(); var json = new JsonObject { { "command", "dump" }, { "output_path", outPath } }; json.Add("temporary_paths", new JsonArray(tempPaths.Select(t => { JsonValue s = t; return(s); }))); json.Add("min_count", filters.MinCount); json.Add("max_ply", filters.MaxPly); json.Add("min_pieces", filters.MinPieces); json.Add("report_progress", true); json.Add("output", new JsonArray(outputElements.Select(t => { JsonValue s = t.GetName(); return(s); }))); var pgnsJson = new JsonArray(); foreach (string pgn in pgns) { pgnsJson.Add(pgn); } json.Add("pgns", pgnsJson); SendMessage(stream, json.ToString()); while (true) { var response = ReceiveMessage(stream); var responseJson = JsonValue.Parse(response); if (responseJson.ContainsKey("error")) { throw new InvalidDataException(responseJson["error"].ToString()); } else if (responseJson.ContainsKey("operation")) { if (responseJson["operation"] == "import" || responseJson["operation"] == "dump") { callback.Invoke(responseJson); } if (responseJson["operation"] == "dump") { if (responseJson["finished"] == true) { break; } } } } } }