Inheritance: SystemException
コード例 #1
0
ファイル: BookStorage.cs プロジェクト: JohnThomson/testBloom
        public void Save()
        {
            Logger.WriteEvent("BookStorage.Saving... (eventual destination: {0})", PathToExistingHtml);

            Guard.Against(BookType != Book.BookType.Publication, "Tried to save a non-editable book.");
            Dom.UpdateMetaElement("Generator", "Bloom " + ErrorReport.GetVersionForErrorReporting());
            if (null != Assembly.GetEntryAssembly()) // null during unit tests
            {
                var ver = Assembly.GetEntryAssembly().GetName().Version;
                Dom.UpdateMetaElement("BloomFormatVersion", kBloomFormatVersion);
            }
            string tempPath = SaveHtml(Dom);

            string errors = ValidateBook(tempPath);
            if (!string.IsNullOrEmpty(errors))
            {
                var badFilePath = PathToExistingHtml + ".bad";
                File.Copy(tempPath, badFilePath, true);
                //hack so we can package this for palaso reporting
                errors += "\r\n\r\n\r\nContents:\r\n\r\n" + File.ReadAllText(badFilePath);
                var ex = new XmlSyntaxException(errors);

                Palaso.Reporting.ErrorReport.NotifyUserOfProblem(ex, "Before saving, Bloom did an integrity check of your book, and found something wrong. This doesn't mean your work is lost, but it does mean that there is a bug in the system or templates somewhere, and the developers need to find and fix the problem (and your book).  Please click the 'Details' button and send this report to the developers.  Bloom has saved the bad version of this book as " + badFilePath + ".  Bloom will now exit, and your book will probably not have this recent damage.  If you are willing, please try to do the same steps again, so that you can report exactly how to make it happen.");
                Process.GetCurrentProcess().Kill();
            }
            else
            {
                Logger.WriteMinorEvent("ReplaceFileWithUserInteractionIfNeeded({0},{1})", tempPath, PathToExistingHtml);
                if (!string.IsNullOrEmpty(tempPath))
                { Palaso.IO.FileUtils.ReplaceFileWithUserInteractionIfNeeded(tempPath, PathToExistingHtml, null); }

            }
        }
コード例 #2
0
        public void Save()
        {
            if (!string.IsNullOrEmpty(ErrorMessagesHtml))
            {
                return; //too dangerous to try and save
            }
            Logger.WriteEvent("BookStorage.Saving... (eventual destination: {0})", PathToExistingHtml);

            Dom.UpdateMetaElement("Generator", "Bloom " + ErrorReport.GetVersionForErrorReporting());
            if (!Program.RunningUnitTests)
            {
                var ver = Assembly.GetEntryAssembly().GetName().Version;
                Dom.UpdateMetaElement("BloomFormatVersion", kBloomFormatVersion);
            }
            MetaData.FormatVersion = kBloomFormatVersion;
            string tempPath = SaveHtml(Dom);

            string errors = ValidateBook(Dom, tempPath);
            if (!string.IsNullOrEmpty(errors))
            {
                Logger.WriteEvent("Errors saving book {0}: {1}", PathToExistingHtml, errors);
                var badFilePath = PathToExistingHtml + ".bad";
                RobustFile.Copy(tempPath, badFilePath, true);
                // delete the temporary file since we've made a copy of it.
                RobustFile.Delete(tempPath);
                //hack so we can package this for palaso reporting
                errors += string.Format("{0}{0}{0}Contents:{0}{0}{1}", Environment.NewLine,
                    RobustFile.ReadAllText(badFilePath));
                var ex = new XmlSyntaxException(errors);

                SIL.Reporting.ErrorReport.NotifyUserOfProblem(ex, "Before saving, Bloom did an integrity check of your book, and found something wrong. This doesn't mean your work is lost, but it does mean that there is a bug in the system or templates somewhere, and the developers need to find and fix the problem (and your book).  Please click the 'Details' button and send this report to the developers.  Bloom has saved the bad version of this book as " + badFilePath + ".  Bloom will now exit, and your book will probably not have this recent damage.  If you are willing, please try to do the same steps again, so that you can report exactly how to make it happen.");
                Process.GetCurrentProcess().Kill();
            }
            else
            {
                Logger.WriteMinorEvent("ReplaceFileWithUserInteractionIfNeeded({0},{1})", tempPath, PathToExistingHtml);
                if (!string.IsNullOrEmpty(tempPath))
                    FileUtils.ReplaceFileWithUserInteractionIfNeeded(tempPath, PathToExistingHtml, null);
            }

            MetaData.Save();
        }