コード例 #1
0
        public Field ResolveReference()
        {
            var index = Name.IndexOf(ReferenceSeparator);

            if (index < 0)
            {
                return(null);
            }

            var path      = Name.Substring(0, index);
            var fieldName = Name.Substring(index + 1);

            FieldCollection fields = null;

            if (!string.IsNullOrEmpty(path))
            {
                HtmlFile file = null;
                if (File?.Project != null)
                {
                    // TODO handle relative path "../../SR.html"
                    file = File.Project.Files.FirstOrDefault(f => f.Path == path);
                }

                if (file == null)
                {
                    return(null);
                }

                fields = file.Fields;
            }
            else
            {
                fields = File?.Fields;
            }

            if (fields == null)
            {
                return(null);
            }

            return(fields[fieldName]);
        }
コード例 #2
0
        protected virtual string GenerateFileName(HtmlFile file, CultureInfo cultureInfo, FileLayout fileLayout)
        {
            var path = file.Path;

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

            switch (fileLayout)
            {
            case FileLayout.Extensions:
                return(Path.GetFileNameWithoutExtension(path) + "." + cultureInfo.Name + Path.GetExtension(path));

            case FileLayout.SubDirectory:
                return(Path.Combine(Path.GetDirectoryName(path), cultureInfo.Name, Path.GetFileName(path)));

            default:
                throw new ArgumentOutOfRangeException(nameof(fileLayout), fileLayout, null);
            }
        }
コード例 #3
0
        public void OpenDirectory(DirectoryInfo root, IEnumerable <FileInfo> files)
        {
            if (root == null)
            {
                throw new ArgumentNullException(nameof(root));
            }
            if (files == null)
            {
                throw new ArgumentNullException(nameof(files));
            }

            foreach (var file in files)
            {
                var filePath = GetFilePath(root, file);

                bool created  = false;
                var  htmlFile = FindFile(filePath);
                if (htmlFile == null)
                {
                    htmlFile = new HtmlFile();
                    created  = true;
                }

                htmlFile.Project = this;
                htmlFile.Path    = filePath;

                htmlFile.LoadHtml(File.ReadAllText(file.FullName));
                htmlFile.ExtractFields();

                // Do not add files without fields
                if (created && htmlFile.Fields.Any())
                {
                    Files.Add(htmlFile);
                }
            }
        }