Exemplo n.º 1
0
        protected virtual IEnumerable <ITextNode> LoadSchemas([NotNull] ICheckerContext context)
        {
            var pathMappingContext = new PathMappingContext(PathMapper);

            var directory = Path.Combine(Configuration.GetToolsDirectory(), "files\\architecture");

            foreach (var fileName in FileSystem.GetFiles(directory, "*.xml", SearchOption.AllDirectories))
            {
                var sourceFile = Factory.SourceFile(fileName);

                var snapshot = SnapshotService.LoadSnapshot(context.Project, sourceFile, pathMappingContext) as ITextSnapshot;
                if (snapshot != null)
                {
                    yield return(snapshot.Root);
                }
            }
        }
        public override void Compile(ICompileContext context, IProjectItem projectItem, SourceProperty <string> property)
        {
            var item = projectItem as Item;

            Assert.Cast(item, nameof(item));

            var value = property.GetValue().Trim();

            if (string.IsNullOrEmpty(value))
            {
                return;
            }

            var project = projectItem.Project;

            var fileName = value;

            if (fileName.StartsWith("~/"))
            {
                fileName = fileName.Mid(2);
            }

            fileName = Path.Combine(project.ProjectDirectory, fileName);
            if (!FileSystem.FileExists(fileName))
            {
                Trace.TraceError(Msg.C1061, Texts.File_not_found, fileName);
                return;
            }

            var sourceFile         = Factory.SourceFile(fileName);
            var pathMappingContext = new PathMappingContext(PathMapper).Parse(project, sourceFile);

            var snapshot = SnapshotService.LoadSnapshot(project, sourceFile, pathMappingContext) as ITextSnapshot;

            if (snapshot == null)
            {
                return;
            }

            var layoutResolveContext = Factory.LayoutCompileContext(project, item.Database, snapshot);
            var layoutCompiler       = Factory.LayoutCompiler();

            var xml = layoutCompiler.Compile(layoutResolveContext, snapshot.Root);

            SetRenderingsField(context, item, xml);
        }
        public virtual ISnapshot LoadSnapshot(IProjectBase project, ISourceFile sourceFile, PathMappingContext pathMappingContext)
        {
            var itemName = sourceFile.GetFileNameWithoutExtensions();
            var filePath = pathMappingContext.FilePath;

            if (filePath.StartsWith("~/"))
            {
                filePath = filePath.Mid(1);
            }

            var filePathWithExtensions = PathHelper.NormalizeItemPath(PathHelper.GetDirectoryAndFileNameWithoutExtensions(filePath));
            var fileName = Path.GetFileName(filePath);
            var fileNameWithoutExtensions = PathHelper.GetFileNameWithoutExtensions(fileName);
            var directoryName             = string.IsNullOrEmpty(filePath) ? string.Empty : PathHelper.NormalizeItemPath(Path.GetDirectoryName(filePath) ?? string.Empty);

            var tokens = new Dictionary <string, string>
            {
                ["ItemPath"] = itemName,
                ["FilePathWithoutExtensions"] = filePathWithExtensions,
                ["FilePath"] = filePath,
                ["Database"] = project.Options.DatabaseName,
                ["FileNameWithoutExtensions"] = fileNameWithoutExtensions,
                ["FileName"]         = fileName,
                ["DirectoryName"]    = directoryName,
                ["ProjectDirectory"] = project.ProjectDirectory
            };

            tokens.AddRange(project.Options.Tokens);

            var snapshotParseContext = Factory.SnapshotParseContext(project, tokens);
            var snapshot             = LoadSnapshot(snapshotParseContext, sourceFile);

            return(snapshot);
        }