Ejemplo n.º 1
0
        static void Main(string[] a_aszArgs)
        {
            string   szExecutableName;
            string   szWriteFolder;
            float    fScale;
            FormMain form1;

            // Are we already running?
            Process[] aprocess = Process.GetProcessesByName(System.IO.Path.GetFileNameWithoutExtension(System.Reflection.Assembly.GetEntryAssembly().Location));
            foreach (Process process in aprocess)
            {
                // If it ain't us, it's somebody else...
                if (process.Id != Process.GetCurrentProcess().Id)
                {
                    MessageBox.Show("This program is already running.  If you don't see it on the screen, check the system tray for the TWAIN Direct icon, and right click on it for the list of options.", "TWAIN Direct on TWAIN Bridge");
                    Environment.Exit(1);
                }
            }

            // Load our configuration information and our arguments,
            // so that we can access them from anywhere in the code...
            if (!Config.Load(Application.ExecutablePath, a_aszArgs, "appdata.txt"))
            {
                MessageBox.Show("Error starting.  Try uninstalling and reinstalling this software.", "Error");
                Environment.Exit(1);
            }

            // Set up our data folders...
            szWriteFolder    = Config.Get("writeFolder", "");
            szExecutableName = Config.Get("executableName", "");

            // Turn on logging...
            Log.Open(szExecutableName, szWriteFolder, 1);
            Log.SetLevel((int)Config.Get("logLevel", 0));
            Log.Info(szExecutableName + " Log Started...");

            // Make sure that any stale TwainDirectOnTwain processes are gone...
            foreach (Process processTwainDirectOnTwain in Process.GetProcessesByName("TwainDirect.OnTwain"))
            {
                try
                {
                    processTwainDirectOnTwain.Kill();
                }
                catch (Exception exception)
                {
                    Log.Error("unable to kill TwainDirect.OnTwain - " + exception.Message);
                }
            }

            // Figure out what we're doing...
            string szCommand;
            Mode   mode = SelectMode(out szCommand, out fScale);

            // Pick our command...
            switch (mode)
            {
            // Uh-oh...
            default:
                Log.Error("Unrecognized mode: " + mode);
                break;

            case Mode.SERVICE:
                //Service service = new Service();
                //ServiceBase.Run(service);
                break;

            case Mode.TERMINAL:
                if (TwainLocalScanner.GetPlatform() == TwainLocalScanner.Platform.WINDOWS)
                {
                    Interpreter.CreateConsole();
                }
                Terminal terminal = new TwainDirect.Scanner.Terminal();
                switch (szCommand.ToLower())
                {
                default:
                    Log.Error("Unrecognized command: " + szCommand);
                    break;

                case "register":
                    terminal.Register();
                    break;

                case "start":
                    terminal.Start();
                    break;
                }
                terminal.Dispose();
                break;

            // Fire up our application window...
            case Mode.WINDOW:
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                form1 = new FormMain();
                Application.Run(form1);
                form1.Dispose();
                break;
            }


            // All done...
            Log.Info(szExecutableName + " Log Ended...");
            Log.Close();
            Environment.Exit(0);
        }
Ejemplo n.º 2
0
        static void Main(string[] a_aszArgs)
        {
            string szExecutableName;
            string szWriteFolder;
            float  fScale;
            Form1  form1;

            // Are we already running?
            Process[] aprocessTwainDirectScanner = Process.GetProcessesByName("TwainDirectScanner");
            if ((aprocessTwainDirectScanner != null) && (aprocessTwainDirectScanner.Length > 1))
            {
                //tbd it would be nice to send a message to the running program
                // so that it can make itself visible...
                Environment.Exit(1);
            }

            // Load our configuration information and our arguments,
            // so that we can access them from anywhere in the code...
            if (!Config.Load(Application.ExecutablePath, a_aszArgs, "appdata.txt"))
            {
                MessageBox.Show("Error starting, is appdata.txt damaged?");
                Environment.Exit(1);
            }

            // Set up our data folders...
            szWriteFolder    = Config.Get("writeFolder", "");
            szExecutableName = Config.Get("executableName", "");

            // Turn on logging...
            Log.Open(szExecutableName, szWriteFolder, 1);
            Log.SetLevel((int)Config.Get("logLevel", 0));
            Log.Info(szExecutableName + " Log Started...");

            // Make sure that any stale TwainDirectOnTwain processes are gone...
            foreach (Process processTwainDirectOnTwain in Process.GetProcessesByName("TwainDirectOnTwain"))
            {
                try
                {
                    processTwainDirectOnTwain.Kill();
                }
                catch (Exception exception)
                {
                    Log.Error("unable to kill TwainDirectOnTwain - " + exception.Message);
                }
            }

            // Figure out what we're doing...
            string szCommand;
            Mode   mode = SelectMode(out szCommand, out fScale);

            // Pick our command...
            switch (mode)
            {
            // Uh-oh...
            default:
                Log.Error("Unrecognized mode: " + mode);
                break;

            case Mode.SERVICE:
                //Service service = new Service();
                //ServiceBase.Run(service);
                break;

            case Mode.TERMINAL:
                if (TwainLocalScanner.GetPlatform() == TwainLocalScanner.Platform.WINDOWS)
                {
                    Interpreter.CreateConsole();
                }
                Terminal terminal = new TwainDirect.Scanner.Terminal();
                switch (szCommand.ToLower())
                {
                default:
                    Log.Error("Unrecognized command: " + szCommand);
                    break;

                case "register":
                    terminal.Register();
                    break;

                case "start":
                    terminal.Start();
                    break;
                }
                terminal.Dispose();
                break;

            // Fire up our application window...
            case Mode.WINDOW:
                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                form1 = new Form1();
                Application.Run(form1);
                form1.Dispose();
                break;
            }


            // All done...
            Log.Info(szExecutableName + " Log Ended...");
            Log.Close();
            Environment.Exit(0);
        }