Beispiel #1
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";
            string directoryPath;

            try
            {
                directoryPath = fileLocator.LocateDirectoryWithThrow(directoryName);
            }
            catch (Exception error)
            {
                //NB: we don't want to put up a dialog for each one; one failure here often means 20 more are coming as the other books are loaded!
                throw new ApplicationException(String.Format("Could not find xmatter pack directory named " + directoryName), error);
            }
            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);
        }
Beispiel #2
0
        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);
        }
 public static string GetXMatterDirectory(string nameOfXMatterPack, IFileLocator fileLocator, string errorMsg, bool throwIfError)
 {
     try
     {
         var directoryName = nameOfXMatterPack + "-XMatter";
         return(fileLocator.LocateDirectoryWithThrow(directoryName));
     }
     catch (ApplicationException error)
     {
         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);
 }
        /// <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 us 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";
            string directoryPath;
            try
            {
                directoryPath = fileLocator.LocateDirectoryWithThrow(directoryName);
            }
            catch(ApplicationException error)
            {
                var errorTemplate = LocalizationManager.GetString("Errors.XMatterNotFound",
                    "This Book called for Front/Back Matter pack named '{0}', but Bloom couldn't find that on this computer. You can either install a Bloom Pack that will give you '{0}', or go to Settings:Book Making and change to another Front/Back Matter Pack.");
                var msg = string.Format(errorTemplate, nameOfXMatterPack);

                ErrorReport.NotifyUserOfProblem(new ShowOncePerSessionBasedOnExactMessagePolicy(), msg);
                //NB: we don't want to put up a dialog for each one; one failure here often means 20 more are coming as the other books are loaded!
                throw new ApplicationException(msg);
            }
            var htmName = nameOfXMatterPack + "-XMatter.html";
            PathToXMatterHtml = directoryPath.CombineForPath(htmName);
            if(!RobustFile.Exists(PathToXMatterHtml))
            {
                htmName = nameOfXMatterPack + "-XMatter.htm"; // pre- Bloom 3.7
                PathToXMatterHtml = directoryPath.CombineForPath(htmName);
            }
            if (!RobustFile.Exists(PathToXMatterHtml))
            {
                ErrorReport.NotifyUserOfProblem(new ShowOncePerSessionBasedOnExactMessagePolicy(), "Could not locate the file {0} in {1} (also checked .html)", htmName, directoryPath);
                throw new ApplicationException();
            }
            PathToStyleSheetForPaperAndOrientation = directoryPath.CombineForPath(GetStyleSheetFileName());
            if (!RobustFile.Exists(PathToXMatterHtml))
            {
                ErrorReport.NotifyUserOfProblem(new ShowOncePerSessionBasedOnExactMessagePolicy(), "Could not locate the file {0} in {1}", GetStyleSheetFileName(), directoryPath);
                throw new ApplicationException();
            }
            XMatterDom = XmlHtmlConverter.GetXmlDomFromHtmlFile(PathToXMatterHtml, false);
        }