using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Windows.Forms;
using TdoCodeGenerator.TdoGeneratorDom;
using System.Reflection;
namespace TdoCodeGenerator{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] arguments)
{
//arguments = new string[] {
// @"/generate",
// @"C:\Documents and Settings\Administrator\My Documents\Visual Studio 2005\Projects\TdoSolution\Tdo Generate All Code.tdosln"
// };
Application.EnableVisualStyles();
try
{
if (Program.RunningInstance() != null)
{
MessageBox.Show("Another Tdo Code Generator instance may already be running.","Warning",MessageBoxButtons.OK,MessageBoxIcon.Information,MessageBoxDefaultButton.Button1);
Application.Exit();
return;
}
Program.ValidateArguments(arguments);
if (arguments != null && arguments.Length==2)
{
//Generate
Program.Generate(arguments);
}
else
{
frmSplashScreen splash = new frmSplashScreen();
splash.canClose = false;
splash.Cursor = Cursors.WaitCursor;
Application.DoEvents();
splash.Show();
frmMain main;
if (arguments.Length == 0)
main = new frmMain();
else
main = new frmMain(arguments);
main.Show();
while (!main.showed)
{
System.Threading.Thread.Sleep(300);
Application.DoEvents();
}
splash.canClose = true;
splash.Cursor = Cursors.Arrow;
Application.DoEvents();
for (int i = 0; i < 20; i++) //2 seconds
{
System.Threading.Thread.Sleep(100);
Application.DoEvents();
if (!splash.Visible)
break;
}
if (splash != null)
splash.Close();
Application.Run(main);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
}
finally
{
}
}
private static void ValidateArguments(string[] arguments)
{
// TODO: finire
if (arguments == null || arguments.Length==0)
return;
if (arguments.Length != 1 && arguments.Length != 2)
{
throw new ArgumentException("Wrong parameters number !\r\n\r\nUsage: TdoCodeGenerator.exe [[/generate] tdosolutionfilename.tdosln | tdoprojectfilename.tdoprj]");
}
if (arguments.Length == 2)
{
if (
arguments[0].Trim().ToLower() != "/generate" &&
arguments[1].Trim().ToLower() != "/generate")
{
throw new ArgumentException("Wrong parameters !\r\n\r\nUsage: TdoCodeGenerator.exe [[/generate] tdosolutionfilename.tdosln | tdoprojectfilename.tdoprj]");
}
}
}
private static void Generate(string[] arguments)
{
frmGenerate fGen = new frmGenerate();
TdoSolutionClass sol = null;
try
{
fGen.SilentMode = true;
if (arguments[1].Trim('"').ToLower().EndsWith(".tdosln"))
{
fGen.TdoSolution = TdoSolutionClass.Open(arguments[1]);
fGen.ShowDialog();
//MessageBox.Show("Generate DDE Request on Tdo Solution: " + arguments[1].Trim().ToLower());
}
else if (arguments[1].Trim('"').ToLower().EndsWith(".tdoprj"))
{
sol = new TdoSolutionClass();
TdoProjectClass prj = TdoProjectClass.Open(arguments[1]);
sol.TdoProjects.Add(prj);
fGen.TdoSolution = sol;
fGen.ShowDialog();
//MessageBox.Show("Generate DDE Request on Tdo Project: " + arguments[1].Trim().ToLower());
}
Application.Exit();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
}
finally
{
}
Application.Exit();
}
public static Process RunningInstance()
{
Process current = Process.GetCurrentProcess();
Process[] processes = Process.GetProcessesByName(current.ProcessName);
//Loop through the running processes in with the same name
foreach (Process process in processes)
{
//Ignore the current process
if (process.Id != current.Id)
{
//Make sure that the process is running from the exe file.
if (Assembly.GetExecutingAssembly().Location.
Replace("/", "\\") == current.MainModule.FileName)
{
//Return the other process instance.
return process;
}
}
}
//No other instance was found, return null.
return null;
}
}
}
|