public override void Run(Canguro.Controller.CommandServices services)
{
gettingResults = false;
try
{
string message = "";
System.Windows.Forms.Cursor cursor = System.Windows.Forms.Cursor.Current;
bool isConnected;
bool canAnalyze = false;
new Canguro.Commands.Model.UnselectCmd().Run(services);
// Verify model consistency for analysis (e.g. graph connectivity)
if (!(canAnalyze = AnalysisUtils.CanAnalyze(services.Model, ref message, out isConnected)))
{
if (!isConnected)
{
if (System.Windows.Forms.MessageBox.Show(message, Culture.Get("error"),
System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Error) ==
System.Windows.Forms.DialogResult.Yes)
{
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
new JoinCmd().Run(services);
canAnalyze = AnalysisUtils.CanAnalyze(services.Model, ref message, out isConnected);
System.Windows.Forms.Cursor.Current = cursor;
}
else
return;
}
}
if (canAnalyze)
{
System.Windows.Forms.SaveFileDialog dlg = new System.Windows.Forms.SaveFileDialog();
dlg.Filter = "S2K File (*.s2k)|*.s2k";
dlg.DefaultExt = "s2k";
dlg.AddExtension = true;
dlg.Title = Culture.Get("ExportS2KTitle");
if (!string.IsNullOrEmpty(services.Model.CurrentPath))
dlg.FileName = Path.Combine(Path.GetDirectoryName(services.Model.CurrentPath), Path.GetFileNameWithoutExtension(services.Model.CurrentPath)) + ".s2k";
else
dlg.FileName = Culture.Get("defaultModelName");
System.Windows.Forms.DialogResult result = (dlg).ShowDialog();
if (result == System.Windows.Forms.DialogResult.Cancel)
{
return;
}
string dstFile = dlg.FileName;
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
// Serialize the model
string modelPath = System.IO.Path.GetTempFileName();
AnalysisCmd.FixPDelta(services.Model.AbstractCases);
Stream stream = File.Create(modelPath);
new Canguro.Model.Serializer.Serializer(services.Model).Serialize(stream, false);
stream.Close();
System.Windows.Forms.Cursor.Current = cursor;
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor;
// Export to s2k
Export(modelPath, dstFile);
System.Windows.Forms.Cursor.Current = cursor;
}
else // Can't export
{
if (!isConnected)
message = Culture.Get("structureIsDisconnectedWrn");
System.Windows.Forms.MessageBox.Show(message, Culture.Get("error"), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
}
}
catch (Exception)
{
System.Windows.Forms.MessageBox.Show(Culture.Get("ErrorExporting"), Culture.Get("error"), System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
}
}