示例#1
0
        public TemplateFile(string templatePath, TransformationData data)
        {
            this.nonDynamicHTMLOutput = data.NonDynamicHTMLOutput;
            this.publishFlags = data.Markdown.PublishFlags;
            ParsedTemplate = null;

            if (string.IsNullOrWhiteSpace(templatePath))
            {
                throw new System.ArgumentException("Template path should be valid path.");
            }

            ReparseTemplate(templatePath);

            var templatePathDir = Path.GetDirectoryName(templatePath);
            var templatePathFileName = Path.GetFileName(templatePath);

            if (templatePathDir != null && templatePathFileName != null)
            {
                fileWatcher = new FileSystemWatcher(templatePathDir, templatePathFileName)
                    {
                        EnableRaisingEvents = true
                    };

                fileWatcher.Changed += (sender, args) =>
                    {
                        ReparseTemplate(templatePath);
                        if (TemplateChanged != null)
                        {
                            TemplateChanged();
                        }
                    };
            }
        }
        public static void Init(TransformationData transformationData, bool thisIsPreview)
        {
            var offensiveWordList = new FileInfo(Path.Combine(transformationData.CurrentFolderDetails.AbsoluteMarkdownPath, "Include", "NoRedist","OffensiveWordList", "wordlist.csv"));

            if (!offensiveWordList.Exists)
            {
                return;
            }

            var parser = new TextFieldParser(offensiveWordList.FullName);
            parser.HasFieldsEnclosedInQuotes = true;
            parser.Delimiters = new string[] {","};

            // for every line in file
            while (!parser.EndOfData)
            {
                var cells = parser.ReadFields();

                OffensiveWordList.Add(cells[0].ToLower());
            }

            _transformationData = transformationData;
            _thisIsPreview = thisIsPreview;
        }
示例#3
0
        private string ParseRegionsToDivsSingleLine(Match match, TransformationData translationVariablesForThisRun)
        {
            var regionParameters = match.Groups[1].Value;
            var regionContent =
                RegionMatchingSingleLine.Replace(RunSpanGamut(match.Groups[2].Value, translationVariablesForThisRun),
                                                 EveryMatch =>
                                                 ParseRegionsToDivsSingleLine(EveryMatch, translationVariablesForThisRun));

            return Templates.Region.Render(
                       Hash.FromAnonymousObject(new
                       {
                           regionParameters = regionParameters,
                           regionContent = regionContent,
                           singleLine = true
                       }));
        }
示例#4
0
        public static bool CheckAvailability(TransformationData data)
        {
            //Check Availability metadata values
            if (data.ProcessedDocumentCache.CurrentFileDocument.Metadata.Contains("availability"))
            {
                foreach (var metaDataValue in data.ProcessedDocumentCache.Metadata.Get("availability"))
                {
                    var availabilityPlatforms = metaDataValue.Replace(" ", "").Split(',');

                    foreach (var availabilityPlatform in availabilityPlatforms)
                    {
                        foreach (var publishFlag in data.Markdown.PublishFlags)
                        {
                            if (publishFlag.ToLower().Equals(data.Markdown.DoNotPublishAvailabilityFlag.ToLower()))
                            {
                                return false;
                            }

                            if (!data.Markdown.AllSupportedAvailability.Contains(publishFlag, StringComparer.OrdinalIgnoreCase))
                            {
                                // Not recognized
                                data.ErrorList.Add(new ErrorDetail(Language.Message("AvailabilityValueNotRecognized", publishFlag), MessageClass.Error, "", "", 0, 0));
                                break;
                            }

                            if (publishFlag.Equals(availabilityPlatform, StringComparison.OrdinalIgnoreCase) || publishFlag.Equals("all", StringComparison.OrdinalIgnoreCase))
                            {
                                return true;
                            }
                        }
                    }
                }
            }

            // if preview mode then allow to continue
            return data.Markdown.ThisIsPreview;
        }
示例#5
0
        private EMDocument ParseDocument(string text, TransformationData transformationData)
        {
            Templates.Init(transformationData, ThisIsPreview);
            OffensiveWordFilterHelper.Init(transformationData, ThisIsPreview);

            OriginalText = text.Split('\n');

            LoadAPIManifest(transformationData);

            transformationData.Document.Parse(text);

            return transformationData.Document;
        }
示例#6
0
        public string Transform(string text, TransformationData transformationData)
        {
            if (String.IsNullOrEmpty(text))
            {
                return null;
            }

            var document = ParseDocument(text, transformationData);

            document.FlattenInternalLinks(transformationData);

            return document.Render();
        }
示例#7
0
        public string Transform(string text, List<ErrorDetail> ErrorList, List<ImageConversion> ImageDetails, List<AttachmentConversionDetail> AttachNames, FolderDetails CurrentFolderDetails, IEnumerable<string> LanguagesLinksToGenerate = null, bool nonDynamicHTMLOutput = false)
        {
            Setup();

            using (
                var td = new TransformationData(
                    this, ErrorList, ImageDetails, AttachNames, CurrentFolderDetails, LanguagesLinksToGenerate, nonDynamicHTMLOutput))
            {
                return Transform(text, td);
            }
        }
示例#8
0
        public string DoAddHTMLWrapping(string text, TransformationData data)
        {
            // Add a meta data item for each row in the MetaData Dictionary,
            // which was populated at the start of all document processing.

            var metadata = "";
            var metadataTemplate = "";

            foreach (var metadataRow in data.ProcessedDocumentCache.Metadata.MetadataMap)
            {
                switch (metadataRow.Key)
                {
                    case "template":
                        metadataTemplate = metadataRow.Value[0];
                        break;
                    case "forcepublishfiles":
                        foreach (var reference in metadataRow.Value[0].Split(','))
                        {
                            RunSpanGamut(reference, data);
                        }
                        break;
                }

                if (metadataRow.Key == "description" && data.ProcessedDocumentCache.Metadata.MetadataMap.ContainsKey("seo-description"))
                {
                    continue;
                }
                
                if (metadataRow.Key == "seo-description")
                {
                    metadata = metadataRow.Value.Aggregate(metadata,
                        (current, metadataValue) =>
                        current + Templates.Metadata.Render(Hash.FromAnonymousObject(new
                        {
                            key = "description",
                            value = metadataValue
                        })));
                }
                else
                {
                    metadata = metadataRow.Value.Aggregate(metadata,
                        (current, metadataValue) =>
                        current + Templates.Metadata.Render(Hash.FromAnonymousObject(new
                            {
                                key = metadataRow.Key,
                                value = metadataValue
                            })));
                }
            }

            var translatedPageLinks = "";

            //Generate links to other languages for this page
            foreach (var translatedLanguage in data.LanguagesLinksToGenerate)
            {
                var linkParams =
                    Hash.FromAnonymousObject(
                        new
                            {
                                pathToPage =
                                    String.IsNullOrWhiteSpace(
                                        data.CurrentFolderDetails.CurrentFolderFromMarkdownAsTopLeaf)
                                        ? ""
                                        : data.CurrentFolderDetails.CurrentFolderFromMarkdownAsTopLeaf.Replace("\\", "/"),
                                otherLanguage = translatedLanguage,
                                relativeHTMLPath = data.CurrentFolderDetails.RelativeHTMLPath
                            });

                if (translatedLanguage.Equals(data.CurrentFolderDetails.Language))
                {
                    linkParams.Add("selected", " selected");
                }

                if(Directory.GetFiles(Path.Combine(
                        Path.Combine(data.CurrentFolderDetails.AbsoluteMarkdownPath,
                        data.CurrentFolderDetails.CurrentFolderFromMarkdownAsTopLeaf)),
                        string.Format("*.{0}.udn", translatedLanguage)).Length == 0)
                {
                    linkParams.Add("disabled", " disabled");
                }

                // Cope with top level folders having blank current folder.
                translatedPageLinks += 
                    Templates.TranslatedPageLink.Render(linkParams);
            }

            //add a warning if crumbs for the document have not been updated to new format
            if ((data.ProcessedDocumentCache.Metadata.CrumbsLinks == null || data.ProcessedDocumentCache.Metadata.CrumbsLinks.Count == 0) && text.Contains("<div class=\"crumbs\">"))
            {
                data.ErrorList.Add(new ErrorDetail(Language.Message("DocumentNeedsToBeUpdatedToUserCrumbLinkMetadata"), MessageClass.Info, "", "", 0, 0));
            }

            // Use language template files if available.
            var defaultLanguagePageLocation = Path.Combine(Path.Combine(Path.Combine(data.CurrentFolderDetails.AbsoluteMarkdownPath, "Include"), "Templates"), data.CurrentFolderDetails.Language);
            var defaultIntPageLocation = Path.Combine(Path.Combine(data.CurrentFolderDetails.AbsoluteMarkdownPath, "Include"), "Templates");

            var webPage = Templates.GetCached(!string.IsNullOrWhiteSpace(metadataTemplate) ? metadataTemplate : DefaultTemplate);

            // If crumbs is empty remove div crumbs from the template.

            var crumbs = data.Markdown.ProcessCrumbs(data.ProcessedDocumentCache.Metadata.CrumbsLinks, data);

            return webPage.Render(Hash.FromAnonymousObject(
                new
                    {
                        crumbsLink = String.IsNullOrWhiteSpace(crumbs)
                                         ? ""
                                         : Templates.GetCached("crumbsDiv.html").Render(Hash.FromAnonymousObject(new { crumbs })),
                        title = data.ProcessedDocumentCache.CurrentFileDocument.Metadata.DocumentTitle,
                        seotitle = (data.ProcessedDocumentCache.CurrentFileDocument.Metadata.SEOTitle != null) ? data.ProcessedDocumentCache.CurrentFileDocument.Metadata.SEOTitle : data.ProcessedDocumentCache.CurrentFileDocument.Metadata.DocumentTitle,
                        metadata = metadata,
                        translatedPages = translatedPageLinks,
                        relatedPagesMenu = Templates.RelatedPages.Render(Hash.FromAnonymousObject(
                            new {
                                relatedPages = data.ProcessedDocumentCache.Metadata.RelatedLinks,
                                relatedPagesCount = data.ProcessedDocumentCache.Metadata.RelatedLinks.Count,
                                quickjump = ""
                            })),
                        relatedPages = Templates.RelatedPages.Render(Hash.FromAnonymousObject(
                            new
                            {
                                relatedPages = data.ProcessedDocumentCache.Metadata.RelatedLinks,
                                relatedPagesCount = data.ProcessedDocumentCache.Metadata.RelatedLinks.Count,
                                relativeHtmlPath = data.CurrentFolderDetails.RelativeHTMLPath
                            })),
                        prereqPages = Templates.PrereqPages.Render(Hash.FromAnonymousObject(
                            new
                            {
                                prereqPages = data.ProcessedDocumentCache.Metadata.PrereqLinks,
                                prereqPagesCount = data.ProcessedDocumentCache.Metadata.PrereqLinks.Count,
                                relativeHtmlPath = data.CurrentFolderDetails.RelativeHTMLPath
                            })),
                        versions = Templates.Versions.Render(Hash.FromAnonymousObject(
                            new
                            {
                                versions = data.ProcessedDocumentCache.Metadata.EngineVersions,
                                versionCount = data.ProcessedDocumentCache.Metadata.EngineVersions.Count
                            })),
                        skilllevels = Templates.SkillLevels.Render(Hash.FromAnonymousObject(
                            new
                            {
                                skilllevels = data.ProcessedDocumentCache.Metadata.SkillLevels,
                                skilllevelCount = data.ProcessedDocumentCache.Metadata.SkillLevels.Count
                            })),
                        errors = ThisIsPreview
                                     ? Templates.ErrorDetails.Render(Hash.FromAnonymousObject(
                                         new
                                             {
                                                 errorDetails = data.ErrorList.ConvertAll(errorDetail => new ErrorDetailDrop(errorDetail)).ToList(),
                                                 outputAtAll = data.ErrorList.Count > 0,
                                                 outputErrors = data.ErrorList.Any(errorDetail => errorDetail.ClassOfMessage == MessageClass.Error),
                                                 outputWarnings = data.ErrorList.Any(errorDetail => errorDetail.ClassOfMessage == MessageClass.Warning),
                                                 outputInfo = data.ErrorList.Any(errorDetail => errorDetail.ClassOfMessage == MessageClass.Info)
                                             }))
                                     : null,
                        markdownContent = text,
                        language = data.CurrentFolderDetails.Language,
                        relativeHtmlPath = data.CurrentFolderDetails.RelativeHTMLPath
                    }));
        }
示例#9
0
        private static string IconEvaluator(Match match, TransformationData translationVariablesForThisRun)
        {
            // These keywords are skipped previously by the variables engine. To add another icon, update also VariableManager.IsKeywordToSkip accordingly.

            string text = match.Groups[1].Value;
            string imagesPath = Path.Combine(Path.Combine(
                translationVariablesForThisRun.CurrentFolderDetails.RelativeHTMLPath,
                "include"), "images");
            
            switch (text)
            {
                //These are all shared images at the top level.
                case "H":
                    text = Templates.ImageFrame.Render(Hash.FromAnonymousObject(new { imageAlt = "HELP", imagePath = Path.Combine(imagesPath, "help.gif") }));
                    break;
                case "I":
                    text = Templates.ImageFrame.Render(Hash.FromAnonymousObject(new { imageAlt = "IDEA!", imagePath = Path.Combine(imagesPath, "idea.gif") }));
                    break;
                case "M":
                    text = Templates.ImageFrame.Render(Hash.FromAnonymousObject(new { imageAlt = "MOVED TO...", imagePath = Path.Combine(imagesPath, "arrowright.gif") }));
                    break;
                case "N":
                    text = Templates.ImageFrame.Render(Hash.FromAnonymousObject(new { imageAlt = "NEW", imagePath = Path.Combine(imagesPath, "new.gif") }));
                    break;
                case "P":
                    text = Templates.ImageFrame.Render(Hash.FromAnonymousObject(new { imageAlt = "REFACTOR", imagePath = Path.Combine(imagesPath, "pencil.gif") }));
                    break;
                case "Q":
                    text = Templates.ImageFrame.Render(Hash.FromAnonymousObject(new { imageAlt = "QUESTION?", imagePath = Path.Combine(imagesPath, "question.gif") }));
                    break;
                case "S":
                    text = Templates.ImageFrame.Render(Hash.FromAnonymousObject(new { imageAlt = "PICK", imagePath = Path.Combine(imagesPath, "starred.gif") }));
                    break;
                case "T":
                    text = Templates.ImageFrame.Render(Hash.FromAnonymousObject(new { imageAlt = "TIP", imagePath = Path.Combine(imagesPath, "tip.gif") }));
                    break;
                case "U":
                    text = Templates.ImageFrame.Render(Hash.FromAnonymousObject(new { imageAlt = "UPDATED", imagePath = Path.Combine(imagesPath, "updated.gif") }));
                    break;
                case "X":
                    text = Templates.ImageFrame.Render(Hash.FromAnonymousObject(new { imageAlt = "ALERT!", imagePath = Path.Combine(imagesPath, "warning.gif") }));
                    break;
                case "Y":
                    text = Templates.ImageFrame.Render(Hash.FromAnonymousObject(new { imageAlt = "DONE", imagePath = Path.Combine(imagesPath, "choice-yes.gif") }));
                    break;
                default:
                    //set back to how it was
                    text = "%" + text + "%";
                    break;
            }
            return text;
        }
示例#10
0
 private static string DoGraphicIcons(string text, TransformationData translationVariablesForThisRun)
 {
     return _graphicIcons.Replace(text, everyMatch => IconEvaluator(everyMatch, translationVariablesForThisRun));
 }
示例#11
0
        /// <summary>
        /// Perform transformations that occur *within* block-level tags like paragraphs, headers, and list items.
        /// </summary>
        public string RunSpanGamut(string text, TransformationData translationVariablesForThisRun)
        {
            text = DoColours(text);
            text = DoGraphicIcons(text, translationVariablesForThisRun);
            text = EscapeSpecialCharsWithinTagAttributes(text);
            text = EscapeBackslashes(text);

            text = ReplaceRegionsWithDivsSpan(text, translationVariablesForThisRun);

            text = DoGraphicIcons(text, translationVariablesForThisRun);

            // Must come after DoAnchors(), because you can use < and >
            // delimiters in inline links like [this](<url>).
            text = DoAutoLinks(text);

            text = EncodeAmpsAndAngles(text);

            text = DoHardBreaks(text);

            return text;
        }
示例#12
0
        public Hash ProcessPrereqs(string path, TransformationData data)
        {
            ClosestFileStatus status;
            var linkedDoc = data.ProcessedDocumentCache.GetClosest(path, out status);

            if (status == ClosestFileStatus.FileMissing)
            {
                var errorId = data.ErrorList.Count;
                data.ErrorList.Add(
                    GenerateError(
                        Language.Message("BadPrereqPageLink", path), MessageClass.Error, path, errorId, data));

                return new Hash();
            }

            var parameters = Hash.FromAnonymousObject(
                new
                {
                    relativeLink = linkedDoc.GetRelativeTargetPath(data.Document)
                });

            foreach (var metadata in linkedDoc.PreprocessedData.Metadata.MetadataMap)
            {
                parameters.Add(metadata.Key, string.Join(", ", metadata.Value));
            }

            return parameters;
        }
示例#13
0
        public string SimplifyHtmlLinkPath(string path, TransformationData data)
        {
            // Get the full path to the source and target files
            var sourceDirPath = Path.Combine(
                data.CurrentFolderDetails.AbsoluteHTMLPath,
                data.CurrentFolderDetails.Language,
                data.CurrentFolderDetails.CurrentFolderFromMarkdownAsTopLeaf);

            if (sourceDirPath[sourceDirPath.Length - 1] != Path.AltDirectorySeparatorChar
                && sourceDirPath[sourceDirPath.Length - 1] != Path.DirectorySeparatorChar)
            {
                sourceDirPath += "/";
            }

            Uri source = new Uri(sourceDirPath);
            Uri target = new Uri(source, path);

            // Create the relative URI between them
            Uri relative = source.MakeRelativeUri(target);
            return relative.ToString();
        }
示例#14
0
        public string ProcessCrumbs(List<string> crumbsLists, TransformationData data)
        {
            var output = new StringBuilder();

            foreach (var crumbList in crumbsLists)
            {
                output.Append(
                    Templates.Crumbs.Render(
                        Hash.FromAnonymousObject(
                            new
                                {
                                    crumbs = crumbList.Split(',').Select((crumb) => GetCrumbsURL(MarkdownSharp.Preprocessor.Preprocessor.UnescapeChars(crumb.Trim(), true), data)),
                                    title = data.ProcessedDocumentCache.CurrentFileDocument.Metadata.DocumentTitle
                                })));
            }

            return output.ToString();
        }
示例#15
0
        private string GetCrumbsURL(string FileLocation, TransformationData InstanceVariablesForThisRun)
        {
            string result = "";
            bool IsURLProblem = false;
            var errorId = 0;
            FileLocation = FileLocation.Replace("%ROOT%", "");


            //Check for invalid characters
            foreach (char EachCharacter in FileLocation)
            {
                if (Array.IndexOf(_problemFileChars, EachCharacter) != -1)
                {
                    errorId = InstanceVariablesForThisRun.ErrorList.Count;

                    result = FileLocation.Replace("<", "&lt;");
                    InstanceVariablesForThisRun.ErrorList.Add(GenerateError(Language.Message("InvalidCharactersDetected", result), MessageClass.Error, Unescape(FileLocation), errorId, InstanceVariablesForThisRun));

                    IsURLProblem = true;
                    break;
                }
            }

            if (!IsURLProblem)
            {
                string linkText;
                var cacheKey = Path.Combine(FileLocation, InstanceVariablesForThisRun.CurrentFolderDetails.Language);
                if (!CachedLinkText.TryGetValue(cacheKey, out linkText))
                {
                    linkText = GetTitleFromDocument(FileLocation, InstanceVariablesForThisRun);
                    CachedLinkText.Add(cacheKey, linkText);
                }

                bool bChangedLanguage = false;

                //This should be a link to a local web page, test that the folder and file exists for the current language in the destination of the link folder in markdown

                string LanguageForFile = InstanceVariablesForThisRun.CurrentFolderDetails.Language;

                DirectoryInfo DirLocationOfLinkedFile =
                    new DirectoryInfo(Path.Combine(Path.Combine(InstanceVariablesForThisRun.CurrentFolderDetails.AbsoluteMarkdownPath, FileLocation)));

                if (!DirLocationOfLinkedFile.Exists ||
                    DirLocationOfLinkedFile.GetFiles(string.Format("*.{0}.udn", InstanceVariablesForThisRun.CurrentFolderDetails.Language)).Length ==
                    0)
                {
                    // if this is not an INT file check for the INT version.
                    if (InstanceVariablesForThisRun.CurrentFolderDetails.Language != "INT")
                    {
                        if (!DirLocationOfLinkedFile.Exists || DirLocationOfLinkedFile.GetFiles("*.INT.udn").Length == 0)
                        {
                            errorId = InstanceVariablesForThisRun.ErrorList.Count;
                            InstanceVariablesForThisRun.ErrorList.Add(
                                GenerateError(
                                    Language.Message("BadLinkOrMissingMarkdownFileForLinkAndNoINTFile", FileLocation),
                                    MessageClass.Error, Unescape(FileLocation), errorId,
                                    InstanceVariablesForThisRun));

                            IsURLProblem = true;
                        }
                        else
                        {
                            // Found int file
                            LanguageForFile = "INT";

                            //Raise info so that now we are allowing missing linked files to still allow processing of the file if INT file is there
                            errorId = InstanceVariablesForThisRun.ErrorList.Count;
                            InstanceVariablesForThisRun.ErrorList.Add(
                                GenerateError(
                                    Language.Message("BadLinkOrMissingMarkdownFileForLinkINTUsed", FileLocation),
                                    MessageClass.Info, Unescape(FileLocation),
                                    errorId, InstanceVariablesForThisRun));

                            IsURLProblem = true;

                            //If we had to replace the language with int then update the linkText to include link to image of flag
                            linkText += Templates.ImageFrame.Render(
                                Hash.FromAnonymousObject(
                                    new
                                    {
                                        imageClass = "languageinline",
                                        imagePath = Path.Combine(
                                            InstanceVariablesForThisRun.CurrentFolderDetails.RelativeHTMLPath,
                                            "Include", "Images", "INT_flag.jpg")
                                    }));

                            bChangedLanguage = true;

                        }
                    }
                    else
                    {
                        errorId = InstanceVariablesForThisRun.ErrorList.Count;
                        InstanceVariablesForThisRun.ErrorList.Add(GenerateError(
                            Language.Message("BadLinkOrMissingMarkdownFileForLink", FileLocation), MessageClass.Error,
                            Unescape(FileLocation), errorId, InstanceVariablesForThisRun));

                        IsURLProblem = true;
                    }
                }

                //add relative htmlpath to local linked page
                FileLocation =
                    Path.Combine(Path.Combine(Path.Combine(InstanceVariablesForThisRun.CurrentFolderDetails.RelativeHTMLPath, LanguageForFile),
                                              FileLocation.Replace("%ROOT%", ""), "index.html"));

                FileLocation = SimplifyHtmlLinkPath(FileLocation, InstanceVariablesForThisRun);

                result = Templates.Link.Render(
                    Hash.FromAnonymousObject(
                        new
                        {
                            linkUrl = FileLocation,
                            linkText = linkText
                        }));

                if (bChangedLanguage)
                {
                    result = Templates.NonlocalizedFrame.Render(
                        Hash.FromAnonymousObject(new { content = result }));
                }
            }

            if (ThisIsPreview && IsURLProblem)
            {
                return Templates.ErrorHighlight.Render(
                    Hash.FromAnonymousObject(
                        new
                        {
                            errorId = errorId,
                            errorText = result
                        }));
            }
            else
            {
                return result;
            }

        }
示例#16
0
 private string ReplaceRegionsWithDivsSpan(string text, TransformationData translationVariablesForThisRun)
 {
     return RegionMatchingSingleLine.Replace(text, EveryMatch => ParseRegionsToDivsSingleLine(EveryMatch, translationVariablesForThisRun));
 }
示例#17
0
        private static string GetTitleFromDocument(string FileLocation, TransformationData translationVariablesForThisRun)
        {
            //Check for this languages markdown file if not found use INT

            //Full local path to markdown directory
            DirectoryInfo AbsoluteDir = new DirectoryInfo(Path.Combine(translationVariablesForThisRun.CurrentFolderDetails.AbsoluteMarkdownPath, FileLocation));

            //string AbsolutePath = Path.Combine(InstanceVariablesForThisRun.CurrentFolderDetails.AbsoluteMarkdownPath, FileLocation);

            if (AbsoluteDir.Exists)
            {
                FileInfo[] AbsoluteMarkdownFilePath = AbsoluteDir.GetFiles(string.Format("*.{0}.udn", translationVariablesForThisRun.CurrentFolderDetails.Language));

                if (AbsoluteMarkdownFilePath.Length == 0)
                {
                    AbsoluteMarkdownFilePath = AbsoluteDir.GetFiles("*.INT.udn");
                }

                if (AbsoluteMarkdownFilePath.Length == 0)
                {
                    //Neither language file or INT file exists in the location specified, use the path as the title
                    return Regex.Replace(FileLocation, "([^\\/]*?)\\|/", "$1");
                }
                else
                {
                    var title = "";

                    return
                        translationVariablesForThisRun.ProcessedDocumentCache.TryGetLinkedFileVariable(AbsoluteMarkdownFilePath[0], "title", out title)
                            ? title
                            : Regex.Replace(FileLocation, "([^\\/]*?)\\|/", "$1");
                }
            }
            else
            {
                //Directory does not exist
                return Regex.Replace(FileLocation, "([^\\/]*?)\\|/", "$1");
            }
        }
示例#18
0
 private static void LoadAPIManifest(TransformationData translationVariablesForThisRun)
 {
     //We only need to load this file once and share across all files in this run
     if (APIFileLocation.Count() == 0)
     {
         FileInfo APIManifestFile = new FileInfo(Path.Combine(Path.Combine(translationVariablesForThisRun.CurrentFolderDetails.AbsoluteMarkdownPath, translationVariablesForThisRun.CurrentFolderDetails.APIFolderLocationFromMarkdownAsTop), "api.manifest"));
         if (!APIManifestFile.Exists)
         {
             //Raise info on not being able to locate the api manifest file, error on specific API: matches in the document
             translationVariablesForThisRun.ErrorList.Add(new ErrorDetail(Language.Message("UnableToLocateAPIManifestInTheSourceDir"), MessageClass.Info, "", "", 0, 0));
         }
         else
         {
             StreamReader APIManifestFileSR = APIManifestFile.OpenText();
             string APIManifestFileLine = "";
             while((APIManifestFileLine = APIManifestFileSR.ReadLine()) != null)
             {
                 Match match = MatchLastCommaOnALine.Match(APIManifestFileLine);
             
                 //Check that no duplicates are in the file if they are raise an info and do not add the subsequent.
                 if (APIFileLocation.ContainsKey(match.Groups["Key"].Value))
                 {
                     translationVariablesForThisRun.ErrorList.Add(new ErrorDetail(Language.Message("DuplicateAPIKeyInAPIManifestFile", match.Groups["Key"].Value), MessageClass.Info, "", "", 0, 0));
                 }
                 else
                 {
                     APIFileLocation.Add(match.Groups["Key"].Value, match.Groups["Value"].Value);
                 }
             }
         }
     }
 }
示例#19
0
        public static void Init(TransformationData data, bool thisIsPreviewRun = false)
        {
            transformationData = data;
            _thisIsPreviewRun = thisIsPreviewRun;

            _defaultLanguageTemplateLocation = Path.Combine(Path.Combine(Path.Combine(transformationData.CurrentFolderDetails.AbsoluteMarkdownPath, "Include"), "Templates"), transformationData.CurrentFolderDetails.Language);
            _defaultIntTemplateLocation = Path.Combine(Path.Combine(transformationData.CurrentFolderDetails.AbsoluteMarkdownPath, "Include"), "Templates");
        }
示例#20
0
        public static ErrorDetail GenerateError(string FullErrorMessage, MessageClass ClassOfError, string OriginalText, int CountOfPreceedingErrors, TransformationData translationVariablesForThisRun)
        {
            //Check the OrignalText, it must not be blank
            if (String.IsNullOrWhiteSpace(OriginalText))
            {
                //Unable to determine line of error with blank OriginalText
                FullErrorMessage = Language.Message("UnableToDetectLineOfError", FullErrorMessage);
            }
            else
            {
                //Get the line numbers with the string that caused this error
                List<ErrorLineNumbersAndColumns> ErrorLineNumbers = GetErrorLineNumbers(OriginalText);

                // 1 detection, raise
                if (ErrorLineNumbers.Count() == 1)
                {
                    return (new ErrorDetail(FullErrorMessage, ClassOfError, "#Error" + CountOfPreceedingErrors, OriginalText, ErrorLineNumbers[0].LineNumber, ErrorLineNumbers[0].Column));
                }
                //more than check for the error line number and column not already raised
                else
                {
                    foreach (ErrorLineNumbersAndColumns LineNumberAndColumn in ErrorLineNumbers)
                    {

                        bool FoundThisErrorHasBeenRaised = false;
                        foreach (ErrorDetail Error in translationVariablesForThisRun.ErrorList)
                        {
                            if (Error.Line == LineNumberAndColumn.LineNumber && Error.Column == LineNumberAndColumn.Column && Error.OriginalText.Equals(OriginalText))
                            {
                                FoundThisErrorHasBeenRaised = true;
                            }
                        }
                        if (!FoundThisErrorHasBeenRaised)
                        {
                            return (new ErrorDetail(FullErrorMessage, ClassOfError, "#Error" + CountOfPreceedingErrors, OriginalText, LineNumberAndColumn.LineNumber, LineNumberAndColumn.Column));
                        }
                    }
                }
            }

            //if here problem have to return 0 line number
            return (new ErrorDetail(FullErrorMessage, ClassOfError, "#Error" + CountOfPreceedingErrors, OriginalText, 0, 0));
        }