コード例 #1
0
        public static bool ProcessFile(string xmlFilePath, bool bForce = false, bool bOpen = false)
        {
            MetaDoc xmlTextWork = new Metadoc.MetaDoc();

            if (!xmlTextWork.Load(xmlFilePath))
            {
                Globals.m_Logger.Error(string.Format("Unable to load metadoc"));
                return(false);
            }

            if (xmlTextWork.IsNoProcess())
            {
                Globals.m_Logger.Info("Skip: no process enabled");
                return(false);
            }

            // ok: here the xml is available and consistent
            string htmlFilePath = Utils.ChangePathExtension(Globals.HtmlWorkFolder() + xmlTextWork.GetFileName(), Globals.HTML_EXT);

            if (!File.Exists(htmlFilePath) || Globals.IsForcedHTMLRebuild() || bForce)
            {
                Globals.m_Logger.Info(string.Format("Processing document {0}", Path.GetFileName(xmlFilePath)));

                if (!BuildHTMLFromTextWork(xmlTextWork))
                {
                    Globals.m_Logger.Error("Unable to build HTML");
                    return(false);
                }
                Globals.m_Logger.Info(string.Format("Building done!"));
            }

            if (bOpen)
            {
                System.Diagnostics.Process.Start(htmlFilePath);
            }

            return(true);
        }
コード例 #2
0
        public static bool ProcessFile(string txtFilePath, bool bForce = false, bool bOpen = false)
        {
            if (!Globals.IsInitialized())
            {
                return(false);
            }

            if (!File.Exists(txtFilePath))
            {
                return(false);
            }

            string xmlFilePath = Utils.ChangePathExtension(txtFilePath, Globals.XML_EXT);

            if (!File.Exists(xmlFilePath))
            {
                BuildTextWorkFromScratch(txtFilePath);
            }
            else
            {
                long xmlLength = new System.IO.FileInfo(xmlFilePath).Length;
                if (xmlLength <= 10)
                {
                    BuildTextWorkFromScratch(txtFilePath);
                }
            }
            if (!File.Exists(xmlFilePath))
            {
                Globals.m_Logger.Error(string.Format("Unable to create XML"));
                return(false);
            }

            MetaDoc xmlTextWork = new Metadoc.MetaDoc();

            if (!xmlTextWork.Load(xmlFilePath))
            {
                Globals.m_Logger.Error(string.Format("Unable to load XML"));
                return(false);
            }

            bool bTextWorkResaved = false;

            if (!xmlTextWork.IsConsistent() || bForce)
            {
                int rev = xmlTextWork.GetRevision();
                if (!xmlTextWork.IsConsistent())
                {
                    Globals.m_Logger.Info(string.Format("Metadoc content is not consistent: rebuilding it..."));
                }
                else
                {
                    Globals.m_Logger.Info(string.Format("Metadoc content is forced to be rebuilt"));
                }

                BuildTextWorkFromScratch(txtFilePath);

                if (!xmlTextWork.Load(xmlFilePath))
                {
                    Globals.m_Logger.Error(string.Format("Unable to load XML"));
                    return(false);
                }
                xmlTextWork.SetRevision(rev + 1);
                bTextWorkResaved = xmlTextWork.Save();
            }
            return(true);
        }