コード例 #1
0
ファイル: DvtCmd.cs プロジェクト: ewcasas/DVTK
        static void Main(string[] arguments)
        {
            _MainArgs = arguments;

            Console.WriteLine();
            Console.WriteLine("> Executing DvtCmd");
            try
            {
                //
                // Initialise dvtk library.
                //
                Dvtk.Setup.Initialize();

                //
                // Determine the options and non-options parameters.
                //
                for (int index = 0; index < arguments.Length; index++)
                {
                    string argument = (string)arguments[index];
                    //
                    // Each option starts with '-'.
                    // For instance;
                    // '-c' <=> Compile Only option.
                    //
                    if (argument.StartsWith("-"))
                    {
                        string optionsString = argument.TrimStart('-');
                        optionsString = optionsString.ToLower();

                        if (optionsString == "c")
                        {
                            _OptionCompileOnly = true;
                        }

                        if (optionsString == "v")
                        {
                            _OptionVerbose = true;
                        }

                        if (optionsString == "m")
                        {
                            _OptionValidateMediaFile = true;
                        }

                        if (optionsString == "estscp")
                        {
                            _OptionEmulatorStorageSCP = true;
                        }

                        if (optionsString == "estscu")
                        {
                            _OptionEmulatorStorageSCU = true;
                        }

                        if (optionsString == "eprscp")
                        {
                            _OptionEmulatorPrintSCP = true;
                        }

                        if (optionsString == "h")
                        {
                            _OptionHelp = true;
                        }
                    }
                    else
                    {
                        _NonOptions.Add(argument);
                    }
                }

                ///
                /// Do the actual thing.
                ///
                if (_OptionHelp)
                {
                    ShowCommandLineArguments();
                }
                else if (_OptionCompileOnly)
                {
                    if (_NonOptions.Count == 1)
                    {
                        String scriptFullFileName = (string)_NonOptions[0];

                        // If this is a Visual Basic Script...
                        if (Path.GetExtension(scriptFullFileName).ToLower() == ".vbs")
                        {
                            // Compile the Visual Basic Script and display progress and errors.
                            ExpandAndCompileVisualBasicScript(scriptFullFileName);
                        }
                        else
                        {
                            ShowCommandLineArguments();
                        }
                    }
                    else
                    {
                        ShowCommandLineArguments();
                    }
                }
                else if (_OptionValidateMediaFile)
                {
                    if (_NonOptions.Count == 2)
                    {
                        ValidateMediaFile();
                    }
                    else
                    {
                        ShowCommandLineArguments();
                    }
                }
                else if (_OptionEmulatorStorageSCP)
                {
                    if (_NonOptions.Count == 1) {
                        FileInfo firstArg = new FileInfo((string)_NonOptions[0]);
                        if (!firstArg.Exists){
                            Console.WriteLine("Error : Session File does not exists");
                        }else {
                            EmulateSCP();
                        }
                    }
                    else {
                        ShowCommandLineArguments();
                    }
                }
                else if (_OptionEmulatorStorageSCU)
                {
                    if (_NonOptions.Count >= 2)
                    {
                        EmulateStorageSCU();
                    }
                    else
                    {
                        ShowCommandLineArguments();
                    }
                }
                else if (_OptionEmulatorPrintSCP)
                {
                    if (_NonOptions.Count == 3)
                    {
                        FileInfo firstArg = new FileInfo((string)_NonOptions[0]);
                        if (!firstArg.Exists){
                            Console.WriteLine("Error : Session File does not exists");
                        }else {
                            EmulateSCP();
                        }
                    }
                    else
                    {
                        ShowCommandLineArguments();
                    }
                }
                else
                    // Execute script.
                {
                    if (_NonOptions.Count == 2)
                    {
                        ExecuteScript();
                    }
                    else
                    {
                        ShowCommandLineArguments();
                    }
                }
            }

            catch(System.Exception theException)
            {
                ShowException(theException);
            }

            finally
            {
                // Clean up
                if( SCPEmulator != null)
                {
                    SCPEmulator = null;
                }

                //
                // Terminate the setup
                //
                Dvtk.Setup.Terminate();
            }

            // Don't show exceptions anymore when cleaning up resources from this application.
            CustomExceptionHandler eh = new CustomExceptionHandler();
            eh.ShowExceptions = false;
            System.AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(eh.OnAppDomainUnhandledException);
        }
コード例 #2
0
        static void Main(string[] arguments)
        {
            _MainArgs = arguments;

            Console.WriteLine();
            Console.WriteLine("> Executing DvtCmd");
            try
            {
                //
                // Initialise dvtk library.
                //
                Dvtk.Setup.Initialize();

                //
                // Determine the options and non-options parameters.
                //
                for (int index = 0; index < arguments.Length; index++)
                {
                    string argument = (string)arguments[index];
                    //
                    // Each option starts with '-'.
                    // For instance;
                    // '-c' <=> Compile Only option.
                    //
                    if (argument.StartsWith("-"))
                    {
                        string optionsString = argument.TrimStart('-');
                        optionsString = optionsString.ToLower();

                        if (optionsString == "c")
                        {
                            _OptionCompileOnly = true;
                        }

                        if (optionsString == "v")
                        {
                            _OptionVerbose = true;
                        }

                        if (optionsString == "m")
                        {
                            _OptionValidateMediaFile = true;
                        }

                        if (optionsString == "estscp")
                        {
                            _OptionEmulatorStorageSCP = true;
                        }

                        if (optionsString == "estscu")
                        {
                            _OptionEmulatorStorageSCU = true;
                        }

                        if (optionsString == "eprscp")
                        {
                            _OptionEmulatorPrintSCP = true;
                        }

                        if (optionsString == "h")
                        {
                            _OptionHelp = true;
                        }
                    }
                    else
                    {
                        _NonOptions.Add(argument);
                    }
                }

                ///
                /// Do the actual thing.
                ///
                if (_OptionHelp)
                {
                    ShowCommandLineArguments();
                }
                else if (_OptionCompileOnly)
                {
                    if (_NonOptions.Count == 1)
                    {
                        String scriptFullFileName = (string)_NonOptions[0];

                        // If this is a Visual Basic Script...
                        if (Path.GetExtension(scriptFullFileName).ToLower() == ".vbs")
                        {
                            // Compile the Visual Basic Script and display progress and errors.
                            ExpandAndCompileVisualBasicScript(scriptFullFileName);
                        }
                        else
                        {
                            ShowCommandLineArguments();
                        }
                    }
                    else
                    {
                        ShowCommandLineArguments();
                    }
                }
                else if (_OptionValidateMediaFile)
                {
                    if (_NonOptions.Count == 2)
                    {
                        ValidateMediaFile();
                    }
                    else
                    {
                        ShowCommandLineArguments();
                    }
                }
                else if (_OptionEmulatorStorageSCP)
                {
                    if (_NonOptions.Count == 1)
                    {
                        FileInfo firstArg = new FileInfo((string)_NonOptions[0]);
                        if (!firstArg.Exists)
                        {
                            Console.WriteLine("Error : Session File does not exists");
                        }
                        else
                        {
                            EmulateSCP();
                        }
                    }
                    else
                    {
                        ShowCommandLineArguments();
                    }
                }
                else if (_OptionEmulatorStorageSCU)
                {
                    if (_NonOptions.Count >= 2)
                    {
                        EmulateStorageSCU();
                    }
                    else
                    {
                        ShowCommandLineArguments();
                    }
                }
                else if (_OptionEmulatorPrintSCP)
                {
                    if (_NonOptions.Count == 3)
                    {
                        FileInfo firstArg = new FileInfo((string)_NonOptions[0]);
                        if (!firstArg.Exists)
                        {
                            Console.WriteLine("Error : Session File does not exists");
                        }
                        else
                        {
                            EmulateSCP();
                        }
                    }
                    else
                    {
                        ShowCommandLineArguments();
                    }
                }
                else
                // Execute script.
                {
                    if (_NonOptions.Count == 2)
                    {
                        ExecuteScript();
                    }
                    else
                    {
                        ShowCommandLineArguments();
                    }
                }
            }

            catch (System.Exception theException)
            {
                ShowException(theException);
            }

            finally
            {
                // Clean up
                if (SCPEmulator != null)
                {
                    SCPEmulator = null;
                }

                //
                // Terminate the setup
                //
                Dvtk.Setup.Terminate();
            }

            // Don't show exceptions anymore when cleaning up resources from this application.
            CustomExceptionHandler eh = new CustomExceptionHandler();

            eh.ShowExceptions = false;
            System.AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(eh.OnAppDomainUnhandledException);
        }