예제 #1
0
        int IComparer.Compare(object x, object y)
        {
            if (x == null && y == null)
            {
                return(0);
            }

            int retval = x == null ? -1 : (y == null ? 1 : 0);

            if (retval == 0)
            {
                FileParser xParser = (FileParser)x;
                FileParser yParser = (FileParser)y;
                retval = string.Compare(xParser.fileName, yParser.fileName, true);
                if (retval == 0)
                {
                    retval = ParsingParams.Compare(xParser.prams, yParser.prams);
                }
            }

            return(retval);
        }
예제 #2
0
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        public void Execute(string[] args, PrintDelegate printDelg)
        {
            print = printDelg;
            if (args.Length > 0)
            {
                try
                {
                    #region Parse command-line arguments...
                    //here we need to separeate application arguments from script ones
                    //script engine arguments are followed by script arguments
                    for (int i = 0; i < args.Length; i++)
                    {
                        if (args[i].StartsWith("/"))
                        {
                            if (args[i] == "/nl")
                            {
                                options["noLogo"] = true;
                            }
                            else if (args[i] == "/c")
                            {
                                options["useCompiled"] = true;
                            }
                            else if (args[i].StartsWith("/ca"))
                            {
                                options["useCompiled"]      = true;
                                options["supressExecution"] = true;
                            }
                            else if (args[i].StartsWith("/cd"))
                            {
                                options["useCompiled"]      = true;
                                options["supressExecution"] = true;
                                options["DLLExtension"]     = true;
                            }
                            else if (args[i].StartsWith("/dbg"))
                            {
                                options["DBG"] = true;
                            }
                            else if (args[i].StartsWith("/r:"))
                            {
                                string[] assemblies = args[i].Remove(0, 3).Split(":".ToCharArray());
                                options["refAssemblies"] = assemblies;
                            }
                            else if (args[i].StartsWith("/e"))
                            {
                                options["buildExecutable"]    = true;
                                options["supressExecution"]   = true;
                                options["buildWinExecutable"] = args[i].StartsWith("/ew");
                            }
                            else if (args[0] == "/?" || args[0] == "-?")
                            {
                                ShowHelp();
                                options["processFile"] = false;
                                break;
                            }
                            else if (args[0] == "/s")
                            {
                                ShowSample();
                                options["processFile"] = false;
                                break;
                            }
                        }
                        else
                        {
                            //this is the end of application arguments
                            options["scriptFileName"] = args[i];

                            //prepare script arguments array
                            scriptArgs = new string[args.Length - (1 + i)];
                            Array.Copy(args, (1 + i), scriptArgs, 0, args.Length - (1 + i));
                            break;
                        }
                    }
                    #endregion

                    if (options.GetBool("processFile"))
                    {
                        options["scriptFileName"] = FileParser.ResolveFile((string)options["scriptFileName"], null);

                        if (!options.GetBool("noLogo"))
                        {
                            Console.WriteLine(AppInfo.appLogo);
                        }

                        //compile
                        string assemblyFileName = GetAvailableAssembly((string)options["scriptFileName"]);
                        if (!options.GetBool("buildExecutable") || !options.GetBool("useCompiled") ||
                            (options.GetBool("useCompiled") && assemblyFileName == null))
                        {
                            try
                            {
                                assemblyFileName = Compile((string)options["scriptFileName"]);
                            }
                            catch (Exception e)
                            {
                                print("Error: Specified file could not be compiled.\n");
                                throw e;
                            }
                        }

                        //execute
                        if (!options.GetBool("supressExecution"))
                        {
                            try
                            {
                                ExecuteAssembly(assemblyFileName);
                            }
                            catch (Exception e)
                            {
                                print("Error: Specified file could not be executed.\n");
                                throw e;
                            }

                            //cleanup
                            if (File.Exists(assemblyFileName) && !options.GetBool("useCompiled"))
                            {
                                try
                                {
                                    File.Delete(assemblyFileName);
                                }
                                catch
                                {
                                }
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    if (rethrow)
                    {
                        throw e;
                    }
                    else
                    {
                        print("Exception: " + e);
                    }
                }
            }
            else
            {
                ShowHelp();
            }
        }