示例#1
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Import from the specified XML (OXES) file.
 /// </summary>
 /// <param name="progressDlg"></param>
 /// <param name="parameters"></param>
 /// <returns></returns>
 /// ------------------------------------------------------------------------------------
 protected virtual object ImportXml(IAdvInd4 progressDlg, object[] parameters)
 {
     Debug.Assert(parameters.Length == 2);
     return(TeXmlImporter.Import(m_cache, m_styleSheet, m_sOXESFile,
                                 (UndoImportManager)parameters[0],
                                 (TeImportUi)parameters[1]));
 }
示例#2
0
        /// <summary>
        /// Calls the importer.
        /// </summary>
        /// <param name="importSettings">The import settings.</param>
        /// <param name="undoManager">The undo manager.</param>
        /// <param name="importUi">The import UI.</param>
        /// <returns></returns>
        protected virtual ScrReference Import(IScrImportSet importSettings, UndoImportManager undoManager,
                                              TeImportUi importUi)
        {
            if (importSettings != null)
            {
                return(TeSfmImporter.Import(importSettings, m_cache, m_styleSheet,
                                            undoManager, importUi, m_fParatextStreamlinedImport));
            }

            return((ScrReference)TeXmlImporter.Import(m_cache, m_styleSheet, m_sOXESFile,
                                                      undoManager, importUi));
        }
示例#3
0
		public override void Initialize()
		{
			base.Initialize();

			m_styleSheet = new FwStyleSheet();
			m_styleSheet.Init(Cache, m_scr.Hvo, (int)Scripture.ScriptureTags.kflidStyles);
			InitWsInfo();
			m_undoImportManager = new UndoImportManager(Cache, null);
			m_importer = ReflectionHelper.CreateObject("TeImportExport.dll",
				"SIL.FieldWorks.TE.TeXmlImporter", BindingFlags.NonPublic,
				new object[] {Cache, m_styleSheet, " ", m_undoImportManager,
				m_teImportUi}) as TeXmlImporter;

			ReflectionHelper.CallMethod(m_importer, "Initialize", null);
			m_stackSectionType = ReflectionHelper.GetField(m_importer, "m_stackSectionType") as Stack<string>;

			StyleProxyListManager.Initialize(m_styleSheet);
		}
示例#4
0
		public override void Exit()
		{
			CheckDisposed();

			m_importer.Dispose();
			m_importer = null;
			m_styleSheet = null;
			StyleProxyListManager.Cleanup();
			ScrNoteImportManager.Cleanup();

			base.Exit();
		}
示例#5
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Executes in two distinct scenarios.
		///
		/// 1. If disposing is true, the method has been called directly
		/// or indirectly by a user's code via the Dispose method.
		/// Both managed and unmanaged resources can be disposed.
		///
		/// 2. If disposing is false, the method has been called by the
		/// runtime from inside the finalizer and you should not reference (access)
		/// other managed objects, as they already have been garbage collected.
		/// Only unmanaged resources can be disposed.
		/// </summary>
		/// <param name="disposing"></param>
		/// <remarks>
		/// If any exceptions are thrown, that is fine.
		/// If the method is being done in a finalizer, it will be ignored.
		/// If it is thrown by client code calling Dispose,
		/// it needs to be handled by fixing the bug.
		///
		/// If subclasses override this method, they should call the base implementation.
		/// </remarks>
		/// ------------------------------------------------------------------------------------
		protected override void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (IsDisposed)
				return;

			if (disposing)
			{
				// Dispose managed resources here.
				if (m_importer != null)
					m_importer.Dispose();
			}

			// Dispose unmanaged resources here, whether disposing is true or false.
			m_styleSheet = null; // FwStyleSheet should implement IDisposable.
			m_importer = null; // TeImporter should implement IDisposable.

			base.Dispose(disposing);
		}
示例#6
0
        private bool VerifyLanguageInOxesFile()
        {
            string sFilename = m_tbFilename.Text;

            try
            {
                XmlReaderSettings readerSettings = new XmlReaderSettings();
                readerSettings.ValidationType = ValidationType.None;
                readerSettings.IgnoreComments = true;
                // The first element should look something like
                // <oxes xmlns="http://www.wycliffe.net/scripture/namespace/version_1.1.0">
                using (XmlReader reader = XmlReader.Create(sFilename, readerSettings))
                {
                    if (!reader.IsStartElement("oxes"))
                    {
                        throw new Exception();
                    }
                    string xmlns = reader.GetAttribute("xmlns");
                    if (String.IsNullOrEmpty(xmlns) ||
                        !xmlns.StartsWith("http://www.wycliffe.net/scripture/namespace/version_"))
                    {
                        throw new Exception();
                    }
                    // We appear to have an OXES file.  Find the first <revisionDesc> element.
                    reader.ReadStartElement("oxes");
                    if (!reader.IsStartElement("oxesText"))
                    {
                        throw new Exception();
                    }
                    Dictionary <string, string> attrs = TeXmlImporter.ReadXmlAttributes(reader);
                    string sValue;
                    if (attrs.TryGetValue("xml:lang", out sValue))
                    {
                        // Verify that the vernacular language matches the OXES file.
                        IWritingSystem wsObj = m_cache.ServiceLocator.WritingSystems.DefaultVernacularWritingSystem;
                        if (sValue != wsObj.Id)
                        {
                            // "The project's vernacular language ({0}) does not match the OXES file's data language ({1}).  Should import continue?"
                            string sFmt = TeResourceHelper.GetResourceString("kstidImportXmlLangMismatch");
                            // "Import Language Mismatch"
                            string sCaption = TeResourceHelper.GetResourceString("kstidImportXmlLangMismatchCaption");
                            string sMsg     = String.Format(sFmt, wsObj.Id, sValue);
                            if (MessageBox.Show(sMsg, sCaption, MessageBoxButtons.YesNo) != DialogResult.Yes)
                            {
                                return(false);
                            }
                        }
                    }
                }
            }
            catch
            {
                // "{0} is not a valid OXES file."
                string sFmt = TeResourceHelper.GetResourceString("kstidImportXmlBadFile");
                string sMsg = String.Format(sFmt, sFilename);
                // "Warning"
                string sCaption = TeResourceHelper.GetResourceString("kstidImportXmlWarning");
                MessageBox.Show(sMsg, sCaption, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return(false);
            }
            return(true);
        }
示例#7
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public override void TestTearDown()
		{
			m_undoImportManager.DoneImportingFiles(true);
			m_importer.Dispose();
			m_importer = null;
			m_styleSheet = null;
			StyleProxyListManager.Cleanup();
			ScrNoteImportManager.Cleanup();
			m_actionHandler.BeginUndoTask("bogus", "bogus");
			base.TestTearDown();
		}
示例#8
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Initialize the importer
		/// </summary>
		/// ------------------------------------------------------------------------------------
		public override void TestSetup()
		{
			base.TestSetup();

			m_styleSheet = new FwStyleSheet();
			m_styleSheet.Init(Cache, m_scr.Hvo, ScriptureTags.kflidStyles);
			InitWsInfo();
			m_actionHandler.EndUndoTask(); // Import expects to handle undo

			m_undoImportManager = new UndoImportManager(Cache);
			m_undoImportManager.StartImportingFiles();
			m_importer = new DummyTeXmlImporter(Cache, m_styleSheet, " ", m_undoImportManager,
				m_teImportUi);

			ReflectionHelper.CallMethod(m_importer, "Initialize", null);
			m_stackSectionType = ReflectionHelper.GetField(m_importer, "m_stackSectionType") as Stack<string>;

			StyleProxyListManager.Initialize(m_styleSheet);
		}