예제 #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Ensures the given localization is at the current version.
        /// </summary>
        /// <param name="locale">The locale representing the required localization.</param>
        /// <param name="caller">The form that is calling this method (used as the owner
        /// of the progress dialog box - can be null if progress dialog is supplied).</param>
        /// <param name="existingProgressDlg">The existing progress dialog box if any.</param>
        /// ------------------------------------------------------------------------------------
        private void EnsureCurrentLocalization(string locale, Form caller,
                                               IProgress existingProgressDlg)
        {
            string localizationFile = DirectoryFinder.GetKeyTermsLocFilename(locale);

            if (!FileUtils.FileExists(localizationFile))
            {
                return;                 // There is no localization available for this locale, so we're as current as we're going to get.
            }
            BiblicalTermsLocalization loc;

            try
            {
                loc = DeserializeBiblicalTermsLocFile(localizationFile);
            }
            catch (InstallationException e)
            {
                ErrorReporter.ReportException(e, m_app.SettingsKey, m_app.SupportEmailAddress, caller, false);
                return;
            }

            string resourceName = GetLocalizationResourceName(locale);

            if (IsResourceOutdated(resourceName, loc.Version))
            {
                NonUndoableUnitOfWorkHelper.DoUsingNewOrCurrentUOW(m_servLoc.GetInstance <IActionHandler>(),
                                                                   () => {
                    if (existingProgressDlg is IThreadedProgress)
                    {
                        ((IThreadedProgress)existingProgressDlg).RunTask(true, UpdateLocalization, loc, locale);
                    }
                    else if (existingProgressDlg != null)
                    {
                        using (ProgressDialogWithTask dlg = new ProgressDialogWithTask(existingProgressDlg))
                            dlg.RunTask(true, UpdateLocalization, loc, locale);
                    }
                    else
                    {
                        using (ProgressDialogWithTask dlg = new ProgressDialogWithTask(caller, m_scr.Cache.ThreadHelper))
                        {
                            dlg.AllowCancel = false;
                            dlg.RunTask(true, UpdateLocalization, loc, locale);
                        }
                    }
                    SetNewResourceVersion(resourceName, loc.Version);
                });
            }
        }
예제 #2
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Gets all the available Key Terms localizations.
        /// </summary>
        /// ------------------------------------------------------------------------------------
        protected virtual List <BiblicalTermsLocalization> GetLocalizations()
        {
            int defaultUserWs = m_scr.Cache.DefaultUserWs;

            string[] locFiles = DirectoryFinder.KeyTermsLocalizationFiles;
            List <BiblicalTermsLocalization> localizations =
                new List <BiblicalTermsLocalization>(locFiles.Length);
            bool fFoundDefaultLoc = false;

            foreach (string localizationFile in locFiles)
            {
                int hvoWs = GetWsFromLocFile(m_wsf, localizationFile);
                if (hvoWs > 0)
                {
                    BiblicalTermsLocalization loc = DeserializeBiblicalTermsLocFile(localizationFile);
                    if (loc != null)
                    {
                        fFoundDefaultLoc    |= (hvoWs == defaultUserWs);
                        loc.WritingSystemHvo = hvoWs;
                        localizations.Add(loc);
                    }
                }
            }
            if (!fFoundDefaultLoc || localizations.Count == 0)
            {
                string icuLocale = m_wsf.GetStrFromWs(defaultUserWs);
                string message   = String.Format("File {0} is missing", DirectoryFinder.GetKeyTermsLocFilename(icuLocale));
                Debug.Fail(message);
                Logger.WriteEvent(message);
                if (icuLocale == "en" || localizations.Count == 0)
                {
#if !DEBUG
                    message = TeResourceHelper.GetResourceString("kstidInvalidInstallation");
#endif
                    throw new InstallationException(message, null);
                }
            }
            return(localizations);
        }