示例#1
0
        private void GenerateScript()
        {
            if (_options.TemplateFile != null)
            {
                PreprocessorOptions preprocessorOptions = new PreprocessorOptions();
                preprocessorOptions.SourceFile  = _options.TemplateFile;
                preprocessorOptions.TargetFile  = _options.ScriptFile;
                preprocessorOptions.DebugFlavor = _options.DebugFlavor;
                preprocessorOptions.Minimize    = _options.Minimize;
                // preprocessorOptions.StripCommentsOnly = _options.StripCommentsOnly;
                preprocessorOptions.UseWindowsLineBreaks  = !_options.Minimize;
                preprocessorOptions.PreprocessorVariables = _options.Defines;

                ScriptPreprocessor preprocessor = new ScriptPreprocessor(this, this, this);
                preprocessor.Preprocess(preprocessorOptions);
            }
            else
            {
                Stream     outputStream = null;
                TextWriter outputWriter = null;

                try {
                    outputStream = _options.ScriptFile.GetStream();
                    if (outputStream == null)
                    {
                        ((IErrorHandler)this).ReportError("Unable to write to file " + _options.ScriptFile.FullName,
                                                          _options.ScriptFile.FullName);
                        return;
                    }

                    outputWriter = new StreamWriter(outputStream);

#if DEBUG
                    if (_options.InternalTestMode)
                    {
                        if (_testOutput != null)
                        {
                            outputWriter.Write(_testOutput);
                            outputWriter.WriteLine("Script");
                            outputWriter.WriteLine("================================================================");
                            outputWriter.WriteLine();
                            outputWriter.WriteLine();
                        }
                    }
#endif // DEBUG

                    GenerateScriptCore(outputWriter);
                }
                catch (Exception e) {
                    Debug.Fail(e.ToString());
                }
                finally {
                    if (outputWriter != null)
                    {
                        outputWriter.Flush();
                    }
                    if (outputStream != null)
                    {
                        _options.ScriptFile.CloseStream(outputStream);
                    }
                }
            }
        }
示例#2
0
        private void GenerateScript() {
            if (_options.TemplateFile != null) {
                PreprocessorOptions preprocessorOptions = new PreprocessorOptions();
                preprocessorOptions.SourceFile = _options.TemplateFile;
                preprocessorOptions.TargetFile = _options.ScriptFile;
                preprocessorOptions.DebugFlavor = _options.DebugFlavor;
                preprocessorOptions.Minimize = _options.Minimize;
                // preprocessorOptions.StripCommentsOnly = _options.StripCommentsOnly;
                preprocessorOptions.UseWindowsLineBreaks = !_options.Minimize;
                preprocessorOptions.PreprocessorVariables = _options.Defines;

                ScriptPreprocessor preprocessor = new ScriptPreprocessor(this, this, this);
                preprocessor.Preprocess(preprocessorOptions);
            }
            else {
                Stream outputStream = null;
                TextWriter outputWriter = null;

                try {
                    outputStream = _options.ScriptFile.GetStream();
                    if (outputStream == null) {
                        ((IErrorHandler)this).ReportError("Unable to write to file " + _options.ScriptFile.FullName,
                                                                  _options.ScriptFile.FullName);
                        return;
                    }

                    outputWriter = new StreamWriter(outputStream);

#if DEBUG
                    if (_options.InternalTestMode) {
                        if (_testOutput != null) {
                            outputWriter.Write(_testOutput);
                            outputWriter.WriteLine("Script");
                            outputWriter.WriteLine("================================================================");
                            outputWriter.WriteLine();
                            outputWriter.WriteLine();
                        }
                    }
#endif // DEBUG

                    GenerateScriptCore(outputWriter);
                }
                catch (Exception e) {
                    Debug.Fail(e.ToString());
                }
                finally {
                    if (outputWriter != null) {
                        outputWriter.Flush();
                    }
                    if (outputStream != null) {
                        _options.ScriptFile.CloseStream(outputStream);
                    }
                }
            }
        }
示例#3
0
        public bool Execute()
        {
            if (_commandLine.ShowHelp)
            {
                ShowHelp();
                return(true);
            }

            List <string> predefinedVariables = new List <string>();
            bool          debug                = false;
            bool          minimize             = true;
            bool          stripCommentsOnly    = false;
            bool          useWindowsLineBreaks = false;

            if (_commandLine.Options.Contains("debug"))
            {
                predefinedVariables.Add("DEBUG");
                debug = true;
            }

            string definesArgument = (string)_commandLine.Options["d"];

            if (definesArgument != null)
            {
                string[] defines = definesArgument.Split(',');
                predefinedVariables.AddRange(defines);
            }

            if (_commandLine.Options.Contains("noMin"))
            {
                minimize = false;
            }

            if (minimize)
            {
                if (_commandLine.Options.Contains("stripCommentsOnly"))
                {
                    stripCommentsOnly = true;
                }
            }

            if (_commandLine.Options.Contains("crlf"))
            {
                useWindowsLineBreaks = true;
            }

            string inputFile  = (string)_commandLine.Options["input"];
            string outputFile = (string)_commandLine.Options["output"];

            if (String.IsNullOrEmpty(inputFile))
            {
                ShowError("Input file was not specified.");
                return(false);
            }
            if (File.Exists(inputFile) == false)
            {
                ShowError("The specified input file does not exist.");
                return(false);
            }

            PreprocessorOptions options = new PreprocessorOptions();

            options.SourceFile            = new FileInputStreamSource(inputFile);
            options.TargetFile            = new FileOutputStreamSource(outputFile);
            options.DebugFlavor           = debug;
            options.Minimize              = minimize;
            options.StripCommentsOnly     = stripCommentsOnly;
            options.UseWindowsLineBreaks  = useWindowsLineBreaks;
            options.PreprocessorVariables = predefinedVariables;

            try {
                if (_commandLine.HideAbout == false)
                {
                    Console.WriteLine(GetAboutString());
                }

                ScriptPreprocessor preprocessor = new ScriptPreprocessor(this, this);
                preprocessor.Preprocess(options);

                return(true);
            }
            catch (Exception e) {
                ShowError("Unhandled Exception: " + Environment.NewLine + e.Message);
            }

            return(false);
        }
示例#4
0
        public bool Execute()
        {
            if (_commandLine.ShowHelp) {
                ShowHelp();
                return true;
            }

            List<string> predefinedVariables = new List<string>();
            bool debug = false;
            bool minimize = true;
            bool stripCommentsOnly = false;
            bool useWindowsLineBreaks = false;

            if (_commandLine.Options.Contains("debug")) {
                predefinedVariables.Add("DEBUG");
                debug = true;
            }

            string definesArgument = (string)_commandLine.Options["d"];
            if (definesArgument != null) {
                string[] defines = definesArgument.Split(',');
                predefinedVariables.AddRange(defines);
            }

            if (_commandLine.Options.Contains("noMin")) {
                minimize = false;
            }

            if (minimize) {
                if (_commandLine.Options.Contains("stripCommentsOnly")) {
                    stripCommentsOnly = true;
                }
            }

            if (_commandLine.Options.Contains("crlf")) {
                useWindowsLineBreaks = true;
            }

            string inputFile = (string)_commandLine.Options["input"];
            string outputFile = (string)_commandLine.Options["output"];

            if (String.IsNullOrEmpty(inputFile)) {
                ShowError("Input file was not specified.");
                return false;
            }
            if (File.Exists(inputFile) == false) {
                ShowError("The specified input file does not exist.");
                return false;
            }

            PreprocessorOptions options = new PreprocessorOptions();
            options.SourceFile = new FileInputStreamSource(inputFile);
            options.TargetFile = new FileOutputStreamSource(outputFile);
            options.DebugFlavor = debug;
            options.Minimize = minimize;
            options.StripCommentsOnly = stripCommentsOnly;
            options.UseWindowsLineBreaks = useWindowsLineBreaks;
            options.PreprocessorVariables = predefinedVariables;

            try {
                if (_commandLine.HideAbout == false) {
                    Console.WriteLine(GetAboutString());
                }

                ScriptPreprocessor preprocessor = new ScriptPreprocessor(this, this);
                preprocessor.Preprocess(options);

                return true;
            }
            catch (Exception e) {
                ShowError("Unhandled Exception: " + Environment.NewLine + e.Message);
            }

            return false;
        }