コード例 #1
0
ファイル: Generator.cs プロジェクト: gregorypilar/interlace
        public static void Generate(Language language, string documentPath, string destinationPath)
        {
            if (!File.Exists(documentPath))
            {
                throw new ApplicationException(string.Format(
                    "The specified input file \"{0}\" does not exist.", documentPath));
            }

            PropertyDictionary documentOptions;
            string actualDocumentPath;

            if (_suffixRegex.IsMatch(documentPath))
            {
                documentOptions = PropertyDictionary.FromFile(documentPath);
                actualDocumentPath = _suffixRegex.Replace(documentPath, ".pinch");

                if (!File.Exists(actualDocumentPath))
                {
                    throw new ApplicationException(string.Format(
                        "The instance configuration \"{0}\" exists, but not the expected corresponding specification file \"{1}\".",
                        documentPath, actualDocumentPath));
                }
            }
            else
            {
                actualDocumentPath = documentPath;

                documentOptions = PropertyDictionary.EmptyDictionary();
                actualDocumentPath = documentPath;
            }

            DateTime documentModified = File.GetLastWriteTimeUtc(documentPath);
            DateTime actualDocumentModified = File.GetLastWriteTimeUtc(actualDocumentPath);

            DateTime mostRecent = documentModified > actualDocumentModified ? documentModified : actualDocumentModified;

            Document document = Document.Parse(actualDocumentPath);

            Compilation compilation = new Compilation();
            compilation.AddDocument(document);
            compilation.Resolve();
            compilation.Number();

            language.CreateDomImplementationHelpers(document, documentOptions);

            Generator generator = new Generator(language, document, actualDocumentPath, destinationPath, mostRecent);

            language.GenerateFiles(generator, document);
        }
コード例 #2
0
        public override bool Execute()
        {
            List<ITaskItem> results = new List<ITaskItem>();

            foreach (ITaskItem source in _sources)
            {
                string sourcePath = source.ItemSpec;
                string destinationPath = Path.ChangeExtension(sourcePath, ".cs");

                bool upToDate = File.Exists(destinationPath) &&
                    File.GetLastWriteTimeUtc(sourcePath) <= File.GetLastWriteTimeUtc(destinationPath);

                if (!upToDate)
                {
                    Document document = Document.Parse(sourcePath);

                    Compilation compilation = new Compilation();
                    compilation.AddDocument(document);
                    compilation.Resolve();
                    compilation.Number();

                    Language language = Language.Cs;

                    language.CreateDomImplementationHelpers(document, PropertyDictionary.EmptyDictionary());

                    Generator.Generate(language, destinationPath, Path.GetDirectoryName(destinationPath));

                    Log.LogMessage(MessageImportance.Low, "Pinch compiled {0}", sourcePath);
                }

                results.Add(new TaskItem(destinationPath));
            }

            _results = results.ToArray();

            return true;
        }