コード例 #1
0
ファイル: XMatterHelper.cs プロジェクト: gmartin7/myBloomFork
        public static string GetXMatterDirectory(string nameOfXMatterPack, IFileLocator fileLocator, string errorMsg, bool throwIfError, bool silent = false)
        {
            var directoryName = nameOfXMatterPack + "-XMatter";

            if (Program.RunningHarvesterMode)
            {
                // Get a new file locator that also searches the Custom XMatter directory.
                // This allows the Harvseter to preserve custom branding if those books are uploaded to web. (See BL-BL-9084)
                var extraSearchPaths = new string[]  { BloomFileLocator.GetCustomXMatterDirectory() };
                fileLocator = fileLocator.CloneAndCustomize(extraSearchPaths);
            }

            if (silent)
            {
                // Using LocateDirectoryWithThrow is quite expensive for directories we don't find...the Exception it creates, which we don't use,
                // includes a concatenation of a long list of paths it searched in. (It's quite common now to search for an xmatter directory
                // we don't often find, such as looking for one called Traditional-Device when publishing something with Traditional xmatter
                // on a device.
                try
                {
                    var result = fileLocator.LocateDirectory(directoryName);
                    if (result == null || !Directory.Exists(result))
                    {
                        return(null);
                    }
                    return(result);
                }
                catch (ApplicationException)
                {
                    return(null);
                }
            }
            try
            {
                return(fileLocator.LocateDirectoryWithThrow(directoryName));
            }
            catch (ApplicationException error)
            {
                if (silent)
                {
                    return(null);
                }
                var frontBackMatterProblem = LocalizationManager.GetString("Errors.XMatterProblemLabel", "Front/Back Matter Problem", "This shows in the 'toast' that pops up to notify the user of a non-fatal problem.");
                NonFatalProblem.Report(ModalIf.None, PassiveIf.All, frontBackMatterProblem, errorMsg, error);
                if (throwIfError)
                {
                    throw new ApplicationException(errorMsg);
                }
            }
            return(null);
        }
コード例 #2
0
        /// <summary>
        /// Constructs by finding the file and folder of the xmatter pack, given the its key name e.g. "Factory", "SILIndonesia".
        /// The name of the file should be (key)-XMatter.htm. The name and the location of the folder is not our problem...
        /// we leave it to the supplied fileLocator to find it.
        /// </summary>
        /// <param name="nameOfXMatterPack">e.g. "Factory", "SILIndonesia"</param>
        /// <param name="fileLocator">The locator needs to be able tell use the path to an xmater html file, given its name</param>
        public XMatterHelper(HtmlDom bookDom, string nameOfXMatterPack, IFileLocator fileLocator)
        {
            _bookDom = bookDom;
            _nameOfXMatterPack = nameOfXMatterPack;

            string directoryName = nameOfXMatterPack + "-XMatter";
            var directoryPath = fileLocator.LocateDirectory(directoryName, "xmatter pack directory named " + directoryName);
            string htmName = nameOfXMatterPack + "-XMatter.htm";
            PathToXMatterHtml = directoryPath.CombineForPath(htmName);
            if(!File.Exists(PathToXMatterHtml))
            {
                ErrorReport.NotifyUserOfProblem(new ShowOncePerSessionBasedOnExactMessagePolicy(), "Could not locate the file {0} in {1}", htmName, directoryPath);
                throw new ApplicationException();
            }
            PathToStyleSheetForPaperAndOrientation = directoryPath.CombineForPath(GetStyleSheetFileName());
            if (!File.Exists(PathToXMatterHtml))
            {
                ErrorReport.NotifyUserOfProblem(new ShowOncePerSessionBasedOnExactMessagePolicy(), "Could not locate the file {0} in {1}", GetStyleSheetFileName(), directoryPath);
                throw new ApplicationException();
            }
            XMatterDom = XmlHtmlConverter.GetXmlDomFromHtmlFile(PathToXMatterHtml, false);
        }
コード例 #3
0
        /// <summary>
        /// Constructs by finding the file and folder of the xmatter pack, given the its key name e.g. "Factory", "SILIndonesia".
        /// The name of the file should be (key)-XMatter.htm. The name and the location of the folder is not our problem...
        /// we leave it to the supplied fileLocator to find it.
        /// </summary>
        /// <param name="nameOfXMatterPack">e.g. "Factory", "SILIndonesia"</param>
        /// <param name="fileLocator">The locator needs to be able tell use the path to an xmater html file, given its name</param>
        public XMatterHelper(HtmlDom bookDom, string nameOfXMatterPack, IFileLocator fileLocator)
        {
            _bookDom           = bookDom;
            _nameOfXMatterPack = nameOfXMatterPack;

            string directoryName = nameOfXMatterPack + "-XMatter";
            var    directoryPath = fileLocator.LocateDirectory(directoryName, "xmatter pack directory named " + directoryName);
            string htmName       = nameOfXMatterPack + "-XMatter.htm";

            PathToXMatterHtml = directoryPath.CombineForPath(htmName);
            if (!File.Exists(PathToXMatterHtml))
            {
                ErrorReport.NotifyUserOfProblem(new ShowOncePerSessionBasedOnExactMessagePolicy(), "Could not locate the file {0} in {1}", htmName, directoryPath);
                throw new ApplicationException();
            }
            PathToStyleSheetForPaperAndOrientation = directoryPath.CombineForPath(GetStyleSheetFileName());
            if (!File.Exists(PathToXMatterHtml))
            {
                ErrorReport.NotifyUserOfProblem(new ShowOncePerSessionBasedOnExactMessagePolicy(), "Could not locate the file {0} in {1}", GetStyleSheetFileName(), directoryPath);
                throw new ApplicationException();
            }
            XMatterDom = XmlHtmlConverter.GetXmlDomFromHtmlFile(PathToXMatterHtml, false);
        }