|
using System;
using System.Globalization;
using System.Windows.Forms;
namespace DataBinding
{
public static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
public static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
var solverFileName = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\solver.xml";
var persistence = new Persistence<AsynchronousSolver>(solverFileName);
var solver = CreateSolver(persistence);
Application.Run(new SolverForm(new SolverPresenter(solver)));
SaveSolver(persistence, solver);
}
private static void SaveSolver(Persistence<AsynchronousSolver> persistence, AsynchronousSolver solver)
{
try
{
persistence.WriteObject(solver);
}
catch (OperationFailedException ex)
{
MessageBox.Show(
ex.Message,
Application.ProductName,
MessageBoxButtons.OK,
MessageBoxIcon.None,
MessageBoxDefaultButton.Button1,
MessageBoxOptions.DefaultDesktopOnly);
}
}
private static AsynchronousSolver CreateSolver(Persistence<AsynchronousSolver> persistence)
{
try
{
return persistence.ReadObject();
}
catch (OperationFailedException)
{
var msg = string.Format(
CultureInfo.CurrentCulture,
"An error occurred while retrieving the previous Solver record file - {0}.\n\nSolver will start out with default parameters.",
persistence.FileName);
MessageBox.Show(
msg,
Application.ProductName,
MessageBoxButtons.OK,
MessageBoxIcon.None,
MessageBoxDefaultButton.Button1,
MessageBoxOptions.DefaultDesktopOnly);
return AsynchronousSolver.CreateDefaultSolver();
}
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
He started his career as a PDP-11 assembly language programmer in downtown Tokyo, learning what "patience" in real life means by punching a 110 baud ASR-33 Teletype frantically. He used to be able to put in the absolute loader sequence through the switch panel without consulting the DEC programming card.
Since then, his computer language experiences include 8051 assembly, FOCAL, BASIC, FORTRAN-IV, Turbo/MS C, VB. VB.NET, and C#.
Now, he lives with his wife, two grown-up kids (get out of my place!), and two cats in Westerville, Ohio.