/// <summary> /// This is temporary behavior until a full import dialog/wizard is written which allows /// the user to specify the original LinguaLinks language project dump file. /// </summary> private void linkLabel1_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e) { // Fire up a file chooser to select an XML file. // Try importing the selected file. // Report success or failure. System.Windows.Forms.OpenFileDialog openFileDialog = new System.Windows.Forms.OpenFileDialog(); openFileDialog.Filter = ResourceHelper.FileFilter(FileFilterType.XML); openFileDialog.FilterIndex = 0; openFileDialog.CheckFileExists = true; openFileDialog.Multiselect = false; openFileDialog.Title = ITextStrings.ksSelectLLFWXMLFile; if (openFileDialog.ShowDialog() == DialogResult.OK) { using (new SIL.FieldWorks.Common.Utils.WaitCursor(this)) { StatusBarProgressPanel panel = m_mediator.PropertyTable.GetValue("ProgressBar") as StatusBarProgressPanel; ProgressReporter prog = new ProgressReporter(panel); string sXmlFile = openFileDialog.FileName; string sLogFile = sXmlFile; int ich = sLogFile.LastIndexOf("."); if (ich >= 0) { sLogFile.Remove(ich, sLogFile.Length - ich); } sLogFile += "-Import.log"; try { IFwXmlData2 fwxd2 = FwXmlDataClass.Create(); fwxd2.Open(m_cache.ServerName, m_cache.DatabaseName); fwxd2.ImportMultipleXmlFields(sXmlFile, m_cache.LangProject.Hvo, prog as IAdvInd); System.Runtime.InteropServices.Marshal.ReleaseComObject(fwxd2); fwxd2 = null; MessageBox.Show(this, String.Format(ITextStrings.ksSuccessLoadingLL, sXmlFile, m_cache.DatabaseName, System.Environment.NewLine, sLogFile), ITextStrings.ksLLImportSucceeded, MessageBoxButtons.OK, MessageBoxIcon.Information); } catch { MessageBox.Show(this, String.Format(ITextStrings.ksFailedLoadingLL, sXmlFile, m_cache.DatabaseName, System.Environment.NewLine, sLogFile), ITextStrings.ksLLImportFailed, MessageBoxButtons.OK, MessageBoxIcon.Error); } } } }
/// ------------------------------------------------------------------------------------ /// <summary> /// Load the NewLangProj.xml file into the new database /// </summary> /// ------------------------------------------------------------------------------------ protected virtual void LoadNewLangProj(IAdvInd4 progressDlg) { try { // Load the NewLangProj.xml into the new database. IFwXmlData xmlDataLoader = FwXmlDataClass.Create(); xmlDataLoader.Open(m_serverName, m_dbName); xmlDataLoader.LoadXml(DirectoryFinder.TemplateDirectory + @"\NewLangProj.xml", progressDlg); xmlDataLoader.Close(); } catch (Exception) { // TODO: Handle any XML loading errors throw; } }
/// ------------------------------------------------------------------------------------ /// <summary> /// does the import /// </summary> /// <param name="dlg">The progress dialog.</param> /// <param name="parameters">The parameters: 1) runToCompletion, 2) last step, /// 3) start phase, 4) database file name, 5) number of entries, 6) true to display /// the import report, 7) name of phase 1 HTML report file, 8) name of phase 1 file. /// </param> /// <returns><c>true</c> if import was successful, otherwise <c>false</c>.</returns> /// ------------------------------------------------------------------------------------ public object Import(IAdvInd4 dlg, params object[] parameters) { Debug.Assert(parameters.Length == 8); bool runToCompletion = (bool)parameters[0]; int lastStep = (int)parameters[1]; int startPhase = (int)parameters[2]; string databaseFileName = (string)parameters[3]; int cEntries = (int)parameters[4]; m_fDisplayImportReport = (bool)parameters[5]; m_sPhase1HtmlReport = (string)parameters[6]; m_sPhase1FileName = (string)parameters[7]; string sErrorMsg = LexTextControls.ksTransformProblem_X; bool fAttemptedXml = false; bool fXmlOk = false; string processedInputFile = databaseFileName; string sPhase1Output = Path.Combine(m_sTempDir, s_sPhase1FileName); string sPhase2Output = Path.Combine(m_sTempDir, s_sPhase2FileName); string sPhase3Output = Path.Combine(m_sTempDir, s_sPhase3FileName); m_sPhase4Output = Path.Combine(m_sTempDir, s_sPhase4FileName); try { // if starting with a phase file, rename the phase file with the input file switch (startPhase) { case 1: sPhase1Output = databaseFileName; break; case 2: sPhase2Output = databaseFileName; break; case 3: sPhase3Output = databaseFileName; break; case 4: m_sPhase4Output = databaseFileName; break; default: break; // no renaming needed } IAdvInd ai = dlg as IAdvInd; if (startPhase < 2) { dlg.Title = String.Format(LexTextControls.ksImportingXEntriesFromY, cEntries, processedInputFile); dlg.Message = String.Format(LexTextControls.ksPhase1ofX_Preview, lastStep); sErrorMsg = LexTextControls.ksTransformProblemPhase1_X; DoTransform(m_sBuildPhase2XSLT, sPhase1Output, m_sPhase2XSLT); } ai.Step(10); if (m_fCancel) { return(false); } sErrorMsg = LexTextControls.ksTransformProblemPhase2_X; dlg.Message = String.Format(LexTextControls.ksPhase2ofX, lastStep); if (startPhase < 2) { DoTransform(m_sPhase2XSLT, sPhase1Output, sPhase2Output); } ai.Step(10); if (m_fCancel) { return(false); } sErrorMsg = LexTextControls.ksTransformProblemPhase3_X; dlg.Message = String.Format(LexTextControls.ksPhase3ofX, lastStep); if (startPhase < 3) { DoTransform(m_sPhase3XSLT, sPhase2Output, sPhase3Output); } ai.Step(10); if (m_fCancel) { return(false); } sErrorMsg = LexTextControls.ksTransformProblemPhase4_X; dlg.Message = String.Format(LexTextControls.ksPhase4ofX, lastStep); if (startPhase < 4) { DoTransform(m_sPhase4XSLT, sPhase3Output, m_sPhase4Output); } ai.Step(20); if (m_fCancel) { return(false); } if (runToCompletion) { sErrorMsg = LexTextControls.ksXmlParsingProblem5_X; dlg.Message = LexTextControls.ksPhase5of5_LoadingData; IFwXmlData2 fxd = FwXmlDataClass.Create(); fxd.Open(m_cache.ServerName, m_cache.DatabaseName); int hvoOwner = m_cache.LangProject.LexDbOA.Hvo; int flid = (int)LexDb.LexDbTags. kflidEntries; if (m_fCancel) { return(false); } ai.Step(1); // There's no way to cancel from here on out. if (dlg is ProgressDialogWithTask) { ((ProgressDialogWithTask)dlg).CancelButtonVisible = false; } fAttemptedXml = true; if (startPhase == 4 && processedInputFile.Length == 0) { processedInputFile = m_sPhase4Output; } fxd.put_BaseImportDirectory(processedInputFile.Substring(0, processedInputFile.LastIndexOfAny(new char[2] { '\\', '/' }))); fxd.ImportXmlObject(m_sPhase4Output, hvoOwner, flid, ai); fXmlOk = true; sErrorMsg = LexTextControls.ksLogFileProblem5_X; ProcessLogFile(processedInputFile, startPhase); return(true); } } catch (Exception ex) { Debug.WriteLine("Error: " + ex.Message); ReportError(string.Format(sErrorMsg, ex.Message), LexTextControls.ksUnhandledError); if (fAttemptedXml && !fXmlOk) { // We want to see the log file even (especially) if the Xml blows up. ProcessLogFile(processedInputFile, startPhase); } } return(false); }