コード例 #1
0
        public static string TestCase(string inputFileName, List <ErrorDetail> errorList = null)
        {
            var errors = errorList ?? new List <ErrorDetail>();

            var targetFileName  = GetTargetFileName(inputFileName);
            var sourceDirectory = Regex.Replace(Settings.Default.SourceDirectory, @"(^\.[/|\\])?[\\|/]*(.*?)[\\|/]*$", "$2");
            var outputDirectory = Regex.Replace(Settings.Default.OutputDirectory, @"(^\.[/|\\])?[\\|/]*(.*?)[\\|/]*$", "$2");

            Language.LangID = "INT";

            Language.Init(
                Path.Combine(sourceDirectory, Settings.Default.IncludeDirectory, Settings.Default.InternationalizationDirectory));

            var markdown = new Markdown();

            Markdown.MetadataErrorIfMissing = Settings.Default.MetadataErrorIfMissing.Split(',');
            Markdown.MetadataInfoIfMissing  = Settings.Default.MetadataInfoIfMissing.Split(',');
            markdown.PublishFlags           = new List <string>()
            {
                "Licensee", "Public"
            };
            markdown.AllSupportedAvailability =
                (Settings.Default.SupportedAvailability + ",Public").ToLower().Split(',').ToList();

            markdown.DoNotPublishAvailabilityFlag = "NoPublish";

            markdown.DefaultTemplate = Settings.Default.DefaultTemplate;

            markdown.ThisIsPreview = false;

            markdown.SupportedLanguages      = Settings.Default.SupportedLanguages.ToUpper().Split(',');
            markdown.SupportedLanguageLabels = Settings.Default.SupportedLanguageLabels.Split(',');
            for (int i = 0; i < markdown.SupportedLanguages.Length; i++)
            {
                markdown.SupportedLanguageMap.Add(markdown.SupportedLanguages[i], markdown.SupportedLanguageLabels[i]);
            }

            //Pass the default conversion settings to Markdown for use in the imagedetails creation.
            markdown.DefaultImageDoCompress      = Settings.Default.DoCompressImages;
            markdown.DefaultImageFormatExtension = Settings.Default.CompressImageType;
            markdown.DefaultImageFillColor       = ImageConversion.GetColorFromHexString(Settings.Default.ImageFillColor);
            markdown.DefaultImageFormat          = ImageConversion.GetImageFormat(Settings.Default.CompressImageType);
            markdown.DefaultImageQuality         = Settings.Default.ImageJPGCompressionValue;

            var imageDetails             = new List <ImageConversion>();
            var attachNames              = new List <AttachmentConversionDetail>();
            var languagesLinksToGenerate = new[] { "INT " };

            var fileOutputDirectory =
                (new DirectoryInfo(inputFileName).Parent).FullName.Replace(
                    sourceDirectory + Path.DirectorySeparatorChar.ToString(CultureInfo.InvariantCulture), "")
                .Replace(sourceDirectory, "");

            var currentFolderDetails = new FolderDetails(
                GetRelativeHTMLPath(targetFileName, outputDirectory),
                new DirectoryInfo(outputDirectory).FullName,
                new DirectoryInfo(sourceDirectory).FullName,
                "Temp",
                "API",
                (new DirectoryInfo(inputFileName).Parent).FullName.Replace(
                    sourceDirectory + Path.DirectorySeparatorChar.ToString(), "")
                .Replace(sourceDirectory, "")
                .Replace(Path.DirectorySeparatorChar.ToString(), " - "),
                GetLanguage(inputFileName));

            var text = File.ReadAllText(inputFileName);

            var actual = markdown.Transform(
                text, errors, imageDetails, attachNames, currentFolderDetails, languagesLinksToGenerate);

            return(actual);
        }
コード例 #2
0
        //Setup defaults and file values for this documents markdown transform
        private void markdownTransformSetup(string FileName, Markdown markdownTransform, FolderDetails CurrentFolderDetails)
        {
            DirectoryInfo SourceDirectoryInfo = new DirectoryInfo(FileName).Parent;

            //Source directory path is found using the SourceDirectoryName setting and the file
            while (SourceDirectoryInfo != null && SourceDirectoryInfo.Name != Settings.Default.SourceDirectoryName)
            {
                SourceDirectoryInfo = SourceDirectoryInfo.Parent;
            }

            if (SourceDirectoryInfo != null)
            {
                string SourceDirectory = SourceDirectoryInfo.FullName;

                string OutputDirectory = Path.Combine(Path.GetTempPath(), "UDTMarkdownMode") + "/";


                string FileOutputDirectory = (new DirectoryInfo(FileName).Parent).FullName.Replace(SourceDirectory + Path.DirectorySeparatorChar, "").Replace(SourceDirectory, "");

                CurrentFolderDetails.RelativeHTMLPath     = OutputDirectory.Replace(@"C:\", @"file://127.0.0.1/c$/");
                CurrentFolderDetails.AbsoluteHTMLPath     = OutputDirectory;
                CurrentFolderDetails.AbsoluteMarkdownPath = SourceDirectory;
                CurrentFolderDetails.CurrentFolderFromMarkdownAsTopLeaf = FileOutputDirectory;
                CurrentFolderDetails.DocumentTitle = (new DirectoryInfo(FileName).Parent).FullName.Replace(SourceDirectory + Path.DirectorySeparatorChar.ToString(), "").Replace(SourceDirectory, "").Replace(Path.DirectorySeparatorChar.ToString(), " - ");
                CurrentFolderDetails.Language      = Regex.Replace(Path.GetFileNameWithoutExtension(FileName).ToUpper(), @"[^\.]*?\.(.*$)", "$1");
                CurrentFolderDetails.APIFolderLocationFromMarkdownAsTop = Settings.Default.APIFolderLocation;

                Language.Init(Path.Combine(CurrentFolderDetails.AbsoluteMarkdownPath, "Include", "Internationalization"));

                DoxygenHelper.DoxygenInputFilter =
                    new FileInfo(
                        Path.Combine(
                            CurrentFolderDetails.AbsoluteMarkdownPath,
                            "..",
                            "..",
                            "Binaries",
                            "DotNET",
                            "UnrealDocToolDoxygenInputFilter.exe")).FullName;

                if (CurrentFolderDetails.Language != "INT")
                {
                    CurrentFolderDetails.DocumentTitle += " - " + CurrentFolderDetails.Language;
                }
                CurrentFolderDetails.DocumentTitle += " - " + Language.Message("Preview");

                Markdown.MetadataErrorIfMissing = Settings.MetadataErrorIfMissing;
                Markdown.MetadataInfoIfMissing  = Settings.MetadataInfoIfMissing;

                markdownTransform.DefaultTemplate = Settings.Default.DefaultTemplate;

                markdownTransform.ThisIsPreview = true;

                markdownTransform.SupportedLanguages      = Settings.SupportedLanguages;
                markdownTransform.SupportedLanguageLabels = Settings.SupportedLanguageLabels;
                for (int i = 0; i < markdownTransform.SupportedLanguages.Length; i++)
                {
                    if (!markdownTransform.SupportedLanguageMap.ContainsKey(markdownTransform.SupportedLanguages[i]))
                    {
                        markdownTransform.SupportedLanguageMap.Add(markdownTransform.SupportedLanguages[i], markdownTransform.SupportedLanguageLabels[i]);
                    }
                }

                markdownTransform.AllSupportedAvailability = new List <string>();
                foreach (string Availablity in Settings.SupportedAvailabilities)
                {
                    markdownTransform.AllSupportedAvailability.Add(Availablity);
                }
                //Add public into list
                markdownTransform.AllSupportedAvailability.Add(Settings.Default.PublicAvailabilitiesString);

                markdownTransform.PublishFlags = new List <string>();
                markdownTransform.DoNotPublishAvailabilityFlag = Settings.Default.DoNotPublishAvailabilitiesFlag.ToLower();

                //Pass the default conversion settings to Markdown for use in the imagedetails creation.
                markdownTransform.DefaultImageDoCompress      = Settings.Default.DoCompressImages;
                markdownTransform.DefaultImageFormatExtension = Settings.Default.CompressImageType;
                markdownTransform.DefaultImageFillColor       = Settings.DefaultImageFillColor;
                markdownTransform.DefaultImageFormat          = ImageConversion.GetImageFormat(Settings.Default.CompressImageType);
                markdownTransform.DefaultImageQuality         = Settings.Default.JpegCompressionRate;
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            Directory.SetCurrentDirectory(
                Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location));

            //Get directory for P4 Document Directory location.
            //make sure does not start with \ or / or end with them
            //strip ./ from start if there
            SourceDirectory = Regex.Replace(
                Settings.Default.SourceDirectory, @"(^\.[/|\\])?[\\|/]*(.*?)[\\|/]*$", "$2");
            OutputDirectory = Regex.Replace(
                Settings.Default.OutputDirectory, @"(^\.[/|\\])?[\\|/]*(.*?)[\\|/]*$", "$2");

            Language.LangID = "INT";

            Language.Init(
                Path.Combine(
                    SourceDirectory,
                    Settings.Default.IncludeDirectory,
                    Settings.Default.InternationalizationDirectory));

            DoCompressImages = Settings.Default.DoCompressImages;
            if (DoCompressImages)
            {
                //If we are not compressing an image no need to set other conversion variables
                JpegCompressionRate = Settings.Default.ImageJPGCompressionValue;
                try
                {
                    DefaultImageFillColor = ImageConversion.GetColorFromHexString(Settings.Default.ImageFillColor);
                }
                catch (Exception)
                {
                    DefaultImageFillColor = default(Color);
                }
                CompressImageType   = Settings.Default.CompressImageType;
                CompressImageFormat = ImageConversion.GetImageFormat(CompressImageType);
                if (CompressImageFormat == null)
                {
                    log.Error(Language.Message("UnsupportedCompressImgType", CompressImageType));
                    return;
                }
            }

            SupportedLanguages      = Settings.Default.SupportedLanguages.ToUpper().Split(',');
            SupportedLanguageLabels = Settings.Default.SupportedLanguageLabels.Split(',');
            for (int i = 0; i < SupportedLanguages.Length; i++)
            {
                SupportedLanguageMap.Add(SupportedLanguages[i], SupportedLanguageLabels[i]);
            }

            MetadataErrorIfMissing = Settings.Default.MetadataErrorIfMissing.Split(',');
            MetadataInfoIfMissing  = Settings.Default.MetadataInfoIfMissing.Split(',');
            MetadataCleanKeepThese = Settings.Default.MetadataCleanKeepThese.ToLower().Split(',');
            SupportedAvailability  = Settings.Default.SupportedAvailability.ToLower().Split(',');
            PublicAvailabilityFlag = Settings.Default.PublicAvailabilityFlag.ToLower();

            //AllSupportedAvailablities needs to include the public and supported availabilities
            foreach (string Availability in SupportedAvailability)
            {
                AllSupportedAvailability.Add(Availability);
            }
            AllSupportedAvailability.Add(PublicAvailabilityFlag);

            var config = new Configuration(SupportedAvailability, PublicAvailabilityFlag, SupportedLanguages, false);

            if (args.Length == 0)
            {
                config = new Configuration(SupportedAvailability, PublicAvailabilityFlag, SupportedLanguages, true);
                // There are no arguments, so try to obtain them from GUI.
                var gui = new GUI.GUI();

                var wpfLogger = new WPFLogger();

                gui.Init(config, wpfLogger);

                log = wpfLogger;

                HideConsole();

                gui.Run();
            }
            else
            {
                log = new LogFileLogger();

                try
                {
                    config.ParamsManager.Parse(args);

                    RunUDNConversion(config, log);
                }
                catch (ParsingErrorException e)
                {
                    if (e.Sender != null)
                    {
                        log.Error(Language.Message("ErrorParsingParam", e.Sender.Name));
                    }

                    log.Error(e.Message);
                    log.Info(config.ParamsManager.GetHelp());
                }
                catch (Exception e)
                {
                    // catching all and printing out -- finishing anyway
                    // print out exception and exit gently rather than panic
                    PrintUnhandledException(e);
                }
                finally
                {
                    log.WriteToLog(Language.Message("UnrealDocToolFinished"));
                }
            }

            AppDomain.CurrentDomain.ProcessExit += (sender, e) => OnProcessExit(sender, e, config);
        }
コード例 #4
0
        private static EMElement Create(
            TransformationData data,
            EMDocument doc,
            EMElementOrigin origin,
            EMElement parent,
            string url,
            string alt,
            string title,
            string convert,
            string width,
            string height,
            string convertQuality,
            string hexFillColor,
            string convertType,
            ImageOptions options)
        {
            ImageFormat imageFormatType;

            if (String.IsNullOrWhiteSpace(url))
            {
                return(EMErrorElement.Create(doc, origin, parent, data, "EmptyLink", origin.Text));
            }

            alt = alt.Replace("\"", "&quot;");

            if (title != null)
            {
                title = title.Replace("\"", "&quot;");
            }

            if (url.StartsWith("<") && url.EndsWith(">"))
            {
                url = url.Substring(1, url.Length - 2); // Remove <>'s surrounding URL, if present
            }

            if (String.IsNullOrWhiteSpace(alt))
            {
                //if no alt text provided use the file name.
                alt = Regex.Replace(url, @".*[\\|/](.*)", "$1");
            }

            var doConvert = !convert.ToLower().Equals("false") && data.Markdown.DefaultImageDoCompress;

            int widthIntConverted;
            int heightIntConverted;
            int quality;

            Color fillColor;

            if (doConvert)
            {
                //if we are converting try to get the other values
                //try parse the strings for width and height into integers
                try
                {
                    widthIntConverted = Int32.Parse(width);
                }
                catch (FormatException)
                {
                    widthIntConverted = 0;
                }

                try
                {
                    heightIntConverted = Int32.Parse(height);
                }
                catch (FormatException)
                {
                    heightIntConverted = 0;
                }

                try
                {
                    quality = Int32.Parse(convertQuality);
                }
                catch (FormatException)
                {
                    quality = data.Markdown.DefaultImageQuality;
                }

                try
                {
                    fillColor = ImageConversion.GetColorFromHexString(hexFillColor);
                }
                catch (Exception)
                {
                    fillColor = data.Markdown.DefaultImageFillColor;
                }

                if (String.IsNullOrWhiteSpace(convertType))
                {
                    convertType     = data.Markdown.DefaultImageFormatExtension;
                    imageFormatType = data.Markdown.DefaultImageFormat;
                }
                else
                {
                    try
                    {
                        imageFormatType = ImageConversion.GetImageFormat(convertType.ToLower());
                    }
                    catch (Exception)
                    {
                        return(EMErrorElement.Create(
                                   doc,
                                   origin,
                                   parent,
                                   data,
                                   "UnsupportedImageFileTypeConversion",
                                   Markdown.Unescape(url),
                                   convertType.ToLower()));
                    }
                }
            }
            else
            {
                //set width and height to zero indicating to converter that we want to use the images values
                widthIntConverted  = 0;
                heightIntConverted = 0;

                //set conversion type to itself, but do check it is a supported image type.
                convertType =
                    Regex.Match(Markdown.Unescape(url), @"\.(png|gif|tga|bmp|jpg)", RegexOptions.IgnoreCase).Groups[1].Value;

                try
                {
                    imageFormatType = ImageConversion.GetImageFormat(convertType.ToLower());
                }
                catch (Exception)
                {
                    return(EMErrorElement.Create(
                               doc,
                               origin,
                               parent,
                               data,
                               "UnsupportedImageFileTypeConversion",
                               Markdown.Unescape(url),
                               convertType.ToLower()));
                }

                quality   = 100;
                fillColor = data.Markdown.DefaultImageFillColor;
            }

            if (!String.IsNullOrWhiteSpace(convertType))
            {
                try
                {
                    var path = new EMLocalFilePath(Markdown.Unescape(url), doc, data,
                                                   fileName => System.IO.Path.GetFileNameWithoutExtension(fileName) + "." + ImageConversion.GetImageExt(imageFormatType));

                    if (!path.IsImage)
                    {
                        throw new EMPathVerificationException(Language.Message("GivenPathIsNotAnImage", url));
                    }

                    data.ImageDetails.Add(
                        new ImageConversion(
                            path.GetSource(),
                            path.GetAbsolutePath(data),
                            widthIntConverted,
                            heightIntConverted,
                            doConvert,
                            imageFormatType,
                            fillColor,
                            quality));

                    return(new EMImage(doc, origin, parent, path, title, alt, options));
                }
                catch (EMPathVerificationException e)
                {
                    return(new EMErrorElement(doc, origin, parent, e.AddToErrorList(data, origin.Text)));
                }
            }

            throw new InvalidOperationException("Should not happen!");
        }