本文整理汇总了C#中Book.SaveBookToFile方法的典型用法代码示例。如果您正苦于以下问题:C# Book.SaveBookToFile方法的具体用法?C# Book.SaveBookToFile怎么用?C# Book.SaveBookToFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Book
的用法示例。
在下文中一共展示了Book.SaveBookToFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateBookFromFiles
/// <summary>
/// Create a book from files selected by the user
/// </summary>
public void CreateBookFromFiles()
{
OpenFileDialog openDlg;
SaveFileDialog saveDlg;
PgnParser parser;
Stream stream;
TextReader reader;
Book book;
string strText;
List<int[]> arrMoveList;
int iSkip;
int iTruncated;
int iTotalSkip = 0;
int iTotalTruncated = 0;
int iTotalFiles = 0;
int iBookEntries;
bool bAbort = false;
arrMoveList = new List<int[]>(8192);
book = new Book();
openDlg = new OpenFileDialog();
openDlg.AddExtension = true;
openDlg.CheckFileExists = true;
openDlg.CheckPathExists = true;
openDlg.DefaultExt = "pgn";
openDlg.Filter = "Chess PGN Files (*.pgn)|*.pgn";
openDlg.Multiselect = true;
if (openDlg.ShowDialog() == true) {
foreach (string strFileName in openDlg.FileNames) {
try {
stream = File.OpenRead(strFileName);
} catch(System.Exception) {
MessageBox.Show("Unable to open the file - " + strFileName);
stream = null;
}
if (stream != null) {
reader = new StreamReader(stream);
strText = reader.ReadToEnd();
parser = new PgnParser(false);
try {
parser.Parse(strText, arrMoveList, out iSkip, out iTruncated);
iTotalSkip += iSkip;
iTotalTruncated += iTruncated;
iTotalFiles++;
} catch(PgnParserException exc) {
MessageBox.Show("Error processing file '" + strFileName + "'\r\n" + exc.Message + "\r\n" + exc.CodeInError);
bAbort = true;
}
stream.Close();
}
if (bAbort) {
break;
}
}
if (!bAbort) {
iBookEntries = book.CreateBookList(arrMoveList, 30, 10);
MessageBox.Show(iTotalFiles.ToString() + " PNG file(s) read. " + arrMoveList.Count.ToString() + " games processed. " + iTotalTruncated.ToString() + " truncated. " + iTotalSkip.ToString() + " skipped. " + iBookEntries.ToString() + " book entries defined.");
saveDlg = new SaveFileDialog();
saveDlg.AddExtension = true;
saveDlg.CheckPathExists = true;
saveDlg.DefaultExt = "bin";
saveDlg.Filter = "Chess Opening Book (*.bin)|*.bin";
saveDlg.OverwritePrompt = true;
if (saveDlg.ShowDialog() == true) {
try {
book.SaveBookToFile(saveDlg.FileName);
} catch (System.Exception ex) {
MessageBox.Show(ex.Message);
}
}
}
}
}