Example #1
0
        private void Process()
        {
            if (_arguments.Verbose)
            {
                BasicConfigurator.Configure();
            }

            // select correct CodeDOM provider and configure syntax
            CodeDomProvider codeDomProvider;

            switch (_arguments.Language)
            {
            case Language.CSharp:
                codeDomProvider = new CSharpCodeProvider();
                _inputProvider  = new CSharpProvider();

                break;

            case Language.VB:
                codeDomProvider = new VBCodeProvider();
                _inputProvider  = new VBProvider();
                break;

            default:
                throw new Exception("Unknown language " + _arguments.Language);
            }

            // generate classes for each [WxePageFunction] class
            CodeCompileUnit unit = new CodeCompileUnit();

            string        fileMask  = Path.Combine(Directory.GetCurrentDirectory(), _arguments.FileMask);
            DirectoryInfo directory = new DirectoryInfo(Path.GetDirectoryName(fileMask));

            FileInfo[] files = directory.GetFiles(
                Path.GetFileName(fileMask),
                _arguments.Recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly);

            bool     outputUpToDate = false;
            FileInfo outputFile     = new FileInfo(_arguments.OutputFile);

            if (_arguments.ProjectFile != null)
            {
                if (outputFile.Exists)
                {
                    outputUpToDate = true;
                }

                FileInfo projectFile = new FileInfo(_arguments.ProjectFile);
                if (!projectFile.Exists)
                {
                    throw new ApplicationException("Project file " + _arguments.ProjectFile + " not found.");
                }

                if (outputUpToDate && projectFile.LastWriteTimeUtc > outputFile.LastWriteTimeUtc)
                {
                    outputUpToDate = false;
                }
            }

            char[]   whitespace = new char[] { ' ', '\t' };
            FileInfo file       = null;

            try
            {
                for (int idxFile = 0; idxFile < files.Length; ++idxFile)
                {
                    file = files[idxFile];

                    if (outputUpToDate && file.LastWriteTimeUtc > outputFile.LastWriteTimeUtc)
                    {
                        outputUpToDate = false;
                    }

                    var fileProcessor = new FileProcessor(_inputProvider, _arguments.FunctionBaseType);
                    fileProcessor.ProcessFile(file, whitespace, unit);
                }
            }
            catch (Exception e)
            {
                if (e is InputException || file == null)
                {
                    throw;
                }
                else
                {
                    throw new InputException(InputError.Unknown, file.FullName, 1, 1, e);
                }
            }

            // write generated code
            if (!outputUpToDate)
            {
                using (TextWriter writer = new StreamWriter(_arguments.OutputFile, false, Encoding.Unicode))
                {
                    Console.WriteLine("Writing classes to " + _arguments.OutputFile);
                    CodeGeneratorOptions options   = new CodeGeneratorOptions();
                    ICodeGenerator       generator = codeDomProvider.CreateGenerator(_arguments.OutputFile);
                    generator.GenerateCodeFromCompileUnit(unit, writer, options);
                }
            }
        }
Example #2
0
 public FileProcessor(LanguageProvider languageProvider, string functionBaseType)
 {
     ArgumentUtility.CheckNotNull("languageProvider", languageProvider);
     _languageProvider = languageProvider;
     _functionBaseType = functionBaseType;
 }