Program.cs :  » Database » TDO » TdoCodeGenerator » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Database » TDO 
TDO » TdoCodeGenerator » Program.cs
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;
    }
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.