Пример #1
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Install the control.
        /// </summary>
        /// <param name="dockHost">The control that hosts the browser</param>
        /// <param name="cache">The cache (needed in case we have to create the English LDS file
        /// on the fly)</param>
        /// <param name="normalStyle">The normal style (needed in case we have to create the
        /// English LDS file on the fly)</param>
        /// <returns>
        ///     <c>true</c> if the browser was installed successfully; <c>false</c>
        /// otherwise.
        /// </returns>
        /// ------------------------------------------------------------------------------------
        public bool Install(Control dockHost, FdoCache cache, IStStyle normalStyle)
        {
            while (true)
            {
                try
                {
                    RegistrationInfo.AllowP6RegistrationCode = true;
                    RegistrationInfo.AllowAccessToResources();
                    string paratextProjectDir = ScrImportP6Project.ProjectDir;

                    if (!String.IsNullOrEmpty(paratextProjectDir))
                    {
                        string englishLdsPathname = Path.Combine(paratextProjectDir, "English.lds");
                        if (!File.Exists(englishLdsPathname))
                        {
                            ParatextLdsFileAccessor ldsAccessor     = new ParatextLdsFileAccessor(cache);
                            UsfmStyEntry            normalUsfmStyle = new UsfmStyEntry();
                            StyleInfoTable          styleTable      = new StyleInfoTable(normalStyle.Name,
                                                                                         cache.LanguageWritingSystemFactoryAccessor);
                            normalUsfmStyle.SetPropertiesBasedOnStyle(normalStyle);
                            styleTable.Add(normalStyle.Name, normalUsfmStyle);
                            styleTable.ConnectStyles();
                            ldsAccessor.WriteParatextLdsFile(englishLdsPathname,
                                                             cache.LanguageWritingSystemFactoryAccessor.GetWsFromStr("en"), normalUsfmStyle);
                        }
                    }
                    ScrTextCollection.Initialize();
                    break;
                }
                catch (Exception e)
                {
                    try
                    {
                        ReflectionHelper.SetField(typeof(ScrTextCollection), "initialized", false);
                    }
                    catch (Exception reflectionHelperException)
                    {
                        throw new ContinuableErrorException("Paratext resource browser failed to initialize." +
                                                            Environment.NewLine + reflectionHelperException.Message, e);
                    }
                    if (MessageBox.Show(dockHost.FindForm(), String.Format(
                                            Properties.Resources.kstidCannotDisplayResourcePane,
                                            Application.ProductName, e.Message), Application.ProductName,
                                        MessageBoxButtons.RetryCancel, MessageBoxIcon.Error,
                                        MessageBoxDefaultButton.Button2) != DialogResult.Retry)
                    {
                        return(false);
                    }
                }
            }
            m_toolStrip.Text = "USFM Resource Browser";
            m_extender       = new DockExtender(dockHost);
            dockHost.Controls.Add(this);
            m_floaty = m_extender.Attach(this, m_toolStrip, true);
            this.SendToBack();
            return(true);
        }
Пример #2
0
        public bool Install(Control dockHost, IApp app)
        {
            while (true)
            {
                try
                {
                    RegistrationInfo.AllowParatext6Code = true;
                    RegistrationInfo.AllowAccessToResources();
                    break;
                }
                catch (Exception e)
                {
                    try
                    {
                        ReflectionHelper.SetField(typeof(ScrTextCollection), "initialized", false);
                    }
                    catch (Exception reflectionHelperException)
                    {
                        throw new ContinuableErrorException("Paratext resource browser failed to initialize." +
                                                            Environment.NewLine + reflectionHelperException.Message, e);
                    }
                    if (MessageBox.Show(dockHost.FindForm(), String.Format(
                                            Properties.Resources.kstidCannotDisplayResourcePane,
                                            app.ApplicationName, e.Message), app.ApplicationName,
                                        MessageBoxButtons.RetryCancel, MessageBoxIcon.Error,
                                        MessageBoxDefaultButton.Button2) != DialogResult.Retry)
                    {
                        return(false);
                    }
                }
            }

            m_toolStrip.Text = "USFM Resource Browser";
            m_extender       = new DockExtender(dockHost);
            dockHost.Controls.Add(this);
            m_floaty = m_extender.Attach(this, m_toolStrip, true);
            this.SendToBack();
            return(true);
        }