private void SetUpDataFiles()
		{
			string server = Environment.MachineName + "\\SILFW";
			string database = "TestLangProj";

			string cnxString = "Server=" + server
				+ "; Database=" + database
				+ "; User ID=FWDeveloper;"
				+ "Password=careful; Pooling=false;";
			m_sqlConnection = new SqlConnection(cnxString);
			m_sqlConnection.Open();
//            SqlCommand command = m_sqlConnection.CreateCommand();
//            command.CommandText = "select top 1 Dst "
//                + "from LangProject_CurVernWss "
//                + "order by Ord";
//            m_vernacularWS = (int)command.ExecuteScalar();

			m_retriever = new M3ParserModelRetriever(SIL.FieldWorks.Common.Utils.BasicUtils.GetTestLangProjDataBaseName());
			using (SIL.FieldWorks.Common.FXT.XDumper fxtDumper = new XDumper(Cache))
			{
				m_sFxtResultFile = Path.Combine(Path.GetTempPath(), "TestLangProjParserFxtResult.xml");
				string ksFXTPath = Path.Combine(FwUtils.ksFlexAppName,
													Path.Combine("Configuration",
													Path.Combine("Grammar", "FXTs")));
				string sFxtFile = Path.Combine(ksFXTPath, "M3Parser.fxt");
				string sFxtPath = Path.Combine(DirectoryFinder.FWCodeDirectory, sFxtFile);
				fxtDumper.Go(Cache.LangProject as CmObject, sFxtPath, File.CreateText(m_sFxtResultFile),
							 new IFilterStrategy[] { new ConstraintFilterStrategy() });
			}


			m_fxtResult = new XmlDocument();
			m_fxtResult.Load(m_sFxtResultFile);
		}
Esempio n. 2
0
 /// -----------------------------------------------------------------------------------
 /// <summary>
 /// Initializes a new instance of the <see cref="ParserWorker"/> class.
 /// </summary>
 /// -----------------------------------------------------------------------------------
 protected ParserWorker(FdoCache cache, Action <TaskReport> taskUpdateHandler, IdleQueue idleQueue, ICmAgent agent)
 {
     m_cache             = cache;
     m_taskUpdateHandler = taskUpdateHandler;
     m_parseFiler        = new ParseFiler(cache, taskUpdateHandler, idleQueue, agent);
     m_projectName       = cache.ProjectId.Name;
     m_retriever         = new M3ParserModelRetriever(m_cache, m_taskUpdateHandler);
     Trace.WriteLineIf(m_tracingSwitch.TraceInfo, "ParserWorker(): CurrentThreadId = " + Win32.GetCurrentThreadId());
 }
		public override void FixtureSetup()
		{
			base.FixtureSetup();

			var projectId = new TestProjectId(FDOBackendProviderType.kMemoryOnly, "Test.fwdata");
			m_cache = FdoCache.CreateCacheWithNewBlankLangProj(projectId, "en", "fr", "en", new DummyFdoUI(), FwDirectoryFinder.FdoDirectories, new FdoSettings());
			NonUndoableUnitOfWorkHelper.Do(m_cache.ActionHandlerAccessor,
				() => m_cache.LangProject.MorphologicalDataOA.ParserParameters = "<ParserParameters><XAmple><MaxNulls>1</MaxNulls><MaxPrefixes>5</MaxPrefixes><MaxInfixes>1</MaxInfixes><MaxSuffixes>5</MaxSuffixes><MaxInterfixes>0</MaxInterfixes><MaxAnalysesToReturn>10</MaxAnalysesToReturn></XAmple><ActiveParser>XAmple</ActiveParser></ParserParameters>");
			m_retriever = new M3ParserModelRetriever(m_cache);
		}
Esempio n. 4
0
		public XAmpleParser(FdoCache cache, string dataDir)
		{
			m_cache = cache;
			m_xample = new XAmpleWrapper();
			m_xample.Init();
			m_dataDir = dataDir;
			m_retriever = new M3ParserModelRetriever(m_cache);
			m_database = ParserHelper.ConvertNameToUseAnsiCharacters(m_cache.ProjectId.Name);
			m_transformer = new M3ToXAmpleTransformer(m_database);
		}
Esempio n. 5
0
        internal TimeStamp LoadGrammarAndLexicon(ParserScheduler.NeedsUpdate eNeedsUpdate)
        {
            CheckDisposed();
            Trace.WriteLineIf(tracingSwitch.TraceInfo, "Worker.LoadGrammarAndLexicon: eNeedsUpdate = " + eNeedsUpdate);
            string     sDescription = SetDescription(eNeedsUpdate);
            TaskReport task         = new TaskReport(sDescription, m_taskUpdateHandler);

            // no longer need this pop-up; was only for debugging
            // task.NotificationMessage = "Loading Parser";

            if (m_retriever == null)
            {
                m_retriever = new M3ParserModelRetriever(m_database);
            }
            TimeStamp stamp;

            using (task)
            {
                XmlDocument fxtResult;
                XmlDocument gafawsFxtResult;
                try
                {
                    DateTime startTime = DateTime.Now;
                    stamp = m_retriever.RetrieveModel(m_connection, m_LangProject, task, eNeedsUpdate);
                    long ttlTicks = DateTime.Now.Ticks - startTime.Ticks;
                    Trace.WriteLineIf(tracingSwitch.TraceInfo, "FXT took : " + ttlTicks.ToString());
                    fxtResult       = m_retriever.ModelDom;
                    gafawsFxtResult = m_retriever.TemplateDom;
                }
                catch (Exception error)
                {
                    if (error.GetType() == Type.GetType("System.Threading.ThreadInterruptedException") ||
                        error.GetType() == Type.GetType("System.Threading.ThreadAbortException"))
                    {
                        throw error;
                    }
                    task.EncounteredError(null);                     // Don't want to show message box in addition to yellow crash box!
                    throw new ApplicationException("Error while retrieving model for the Parser.", error);
                }

                LoadParser(ref fxtResult, gafawsFxtResult, task, eNeedsUpdate);
            }
            return(stamp);
        }
Esempio n. 6
0
		public HCParser(FdoCache cache, string dataDir)
		{
			m_cache = cache;

			m_retriever = new M3ParserModelRetriever(m_cache);
			m_patr = new PatrParser
			{
				CommentChar = '|',
				CodePage = Encoding.UTF8.CodePage
			};
			m_loader = new XmlLoader
			{
				XmlResolver = new XmlFwResolver(dataDir),
				QuitOnError = false
			};

			m_outputDirectory = Path.GetTempPath();
			m_projectName = ParserHelper.ConvertNameToUseAnsiCharacters(cache.ProjectId.Name);
			m_transformer = new M3ToHCTransformer(m_projectName);
		}
Esempio n. 7
0
		internal TimeStamp LoadGrammarAndLexicon(ParserScheduler.NeedsUpdate eNeedsUpdate)
		{
			CheckDisposed();
			Trace.WriteLineIf(tracingSwitch.TraceInfo, "Worker.LoadGrammarAndLexicon: eNeedsUpdate = " + eNeedsUpdate);
			string sDescription = SetDescription(eNeedsUpdate);
			TaskReport task = new TaskReport(sDescription, m_taskUpdateHandler);
			// no longer need this pop-up; was only for debugging
			// task.NotificationMessage = "Loading Parser";

			if (m_retriever == null)
				m_retriever = new M3ParserModelRetriever(m_database);
			TimeStamp stamp;
			using (task)
			{
				XmlDocument fxtResult;
				XmlDocument gafawsFxtResult;
				try
				{
					DateTime startTime = DateTime.Now;
					stamp = m_retriever.RetrieveModel(m_connection, m_LangProject, task, eNeedsUpdate);
					long ttlTicks = DateTime.Now.Ticks - startTime.Ticks;
					Trace.WriteLineIf(tracingSwitch.TraceInfo, "FXT took : " + ttlTicks.ToString());
					fxtResult = m_retriever.ModelDom;
					gafawsFxtResult = m_retriever.TemplateDom;
				}
				catch (Exception error)
				{
					if (error.GetType() == Type.GetType("System.Threading.ThreadInterruptedException") ||
						error.GetType() == Type.GetType("System.Threading.ThreadAbortException"))
					{
						throw error;
					}
					task.EncounteredError(null); // Don't want to show message box in addition to yellow crash box!
					throw new ApplicationException("Error while retrieving model for the Parser.", error);
				}

				LoadParser(ref fxtResult, gafawsFxtResult, task, eNeedsUpdate);

			}
			return stamp;
		}
Esempio n. 8
0
		private void SetUpDataFiles()
		{

			string server = Environment.MachineName + "\\SILFW";
			string database = "TestLangProj";

			string cnxString = "Server=" + server
				+ "; Database=" + database
				+ "; User ID=FWDeveloper;"
				+ "Password=careful; Pooling=false;";
			m_sqlConnection = new SqlConnection(cnxString);
			m_sqlConnection.Open();
			SqlCommand command = m_sqlConnection.CreateCommand();
			command.CommandText = "select top 1 Dst "
				+ "from LangProject_CurVernWss "
				+ "order by Ord";
			m_vernacularWS = (int)command.ExecuteScalar();

			m_retriever = new M3ParserModelRetriever("TestLangProj");
			using (SIL.FieldWorks.Common.FXT.XDumper fxtDumper = new XDumper(Cache))
			{
				m_sFxtResultFile = Path.Combine(Path.GetTempPath(), "TestLangProjParserFxtResult.xml");
				const string ksFXTPath = @"Language Explorer\Configuration\Grammar\FXTs";
				string sFxtFile = Path.Combine(ksFXTPath, "M3Parser.fxt");
				string sFxtPath = Path.Combine(DirectoryFinder.FWCodeDirectory, sFxtFile);
				fxtDumper.Go(Cache.LangProject as CmObject, sFxtPath, File.CreateText(m_sFxtResultFile),
							 new IFilterStrategy[] { new ConstraintFilterStrategy() });
			}


			m_fxtResult = new XmlDocument();
			m_fxtResult.Load(m_sFxtResultFile);
		}
Esempio n. 9
0
		protected override void DisposeManagedResources()
		{
			if (m_patr != null)
			{
				m_patr.Dispose();
				m_patr = null;
			}

			if (m_retriever != null)
			{
				m_retriever.Dispose();
				m_retriever = null;
			}
		}