Example #1
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>
        private void Dispose(bool disposing)
        {
            //Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
            // Must not be run more than once.
            if (m_isDisposed)
            {
                return;
            }

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

            // Dispose unmanaged resources here, whether disposing is true or false.
            m_formMsaObjs = null;
            // Caller will handle disposal of m_connection,
            // since it provided it.
            m_connection       = null;
            m_currentFormMSA   = null;
            m_lastEngineUpdate = null;

            m_isDisposed = true;
        }
Example #2
0
		/*------------------------------------------------------------------------------------------
			Clear out the data related to a particular word, get ready for the next one
		------------------------------------------------------------------------------------------*/
		private void ResetForNextWord()
		{
			m_currentWordformId = 0;
			m_currentFormMSA = null;
			m_formMsaObjs.Clear();
		}
Example #3
0
		private bool ProcessElementStart(XmlTextReader reader)
		{
			bool keepReading = true; // Be optimistic.
			switch (reader.Name)
			{
				default:
					break; // Do nothing for any others.
				case "Wordform":
				{
					Debug.Assert(m_agentId > 0);
					m_currentWordformId = GetId(reader);
					SqlCommand command = m_connection.CreateCommand();
					command.CommandTimeout = 60; // seconds, which is the default of 30.
					command.CommandText = string.Format("SELECT count(*) "
						+ "FROM WfiWordform_Analyses "
						+ "WHERE Src={0}", m_currentWordformId);
					m_startAnalysesCount = (int)command.ExecuteScalar();
					command.CommandText = string.Format("SELECT Id from CmBaseAnnotation_ "
						+ "WHERE BeginObject={0} and Source={1}", m_currentWordformId, m_agentId);
					SqlDataReader sqlReader = null;
					Set<int> problemIDs = new Set<int>();
					try // Needs a try here in order to deal with reader on a problem.
					{
						sqlReader = command.ExecuteReader();
						// Gather up a list of ids, since we have to close the reader,
						// before actually deleting them.
						while (sqlReader.Read())
							problemIDs.Add(sqlReader.GetInt32(0));
					}
					finally
					{
						if (sqlReader != null)
						{
							sqlReader.Close();
							sqlReader = null;
						}
					}
					// REVIEW/TODO: it would be faster to delete these all at once rather than one at a time.
					foreach(int problemID in problemIDs)
					{
						command = m_connection.CreateCommand();
						command.CommandText = string.Format("EXEC DeleteObjects '{0}'", problemID);
						command.ExecuteNonQuery();
					}
#if TrackingPFProblems
					// Set the id to the wordform you want to look at,
					// and then put a breakpoint on the Debug.WriteLine line.
					if (m_currentWordformId == 4616)
						Debug.WriteLine("Have biliya.");
#endif
					// REVIEW RandyR: Should this be turned into an SP?
					command = m_connection.CreateCommand();
					command.CommandText = String.Format(
						"DECLARE @d datetime;\n"
						+ "set @d = '{0}';\n"
						+ "declare @retval int;\n"
						+ "exec @retval = SetAgentEval {1}, {2}, 1, 'a wordform eval', @d;\n"
						+ "select @retval",
						m_lastEngineUpdate, m_agentId, m_currentWordformId);
					if ((int)command.ExecuteScalar() != 0)
						throw new Exception("Unspecified SetAgentEval stored procedure problem.");
					break;
				}
				case "WfiAnalysis":
				{
					Debug.Assert(m_formMsaObjs.Count == 0);
#if DOSOMETHINGFORFAILURE
					if (reader.IsEmptyElement)
					{
						try
						{
							ProcessAnalysis();
						}
						catch
						{
							ResetForNextWord();
							throw;
						}
						finally
						{
							Debug.Assert(m_currentWordformId > 0
								&& m_agentId > 0
								&& m_formMsaObjs.Count == 0);
						}
					}
#endif
					break;
				}
				case "MoForm":
				{
					Debug.Assert(m_currentFormMSA == null);
					m_currentFormMSA = new FormMSA(GetId(reader));
					break;
				}
				case "MSI":
					goto case "MSA"; // Fall through.
				case "MSA":
				{
					Debug.Assert(m_currentFormMSA != null
						&& m_currentFormMSA.m_formId > 0
						&& m_currentFormMSA.m_msaId == 0);

					m_currentFormMSA.m_msaId = GetId(reader);
					m_formMsaObjs.Add(m_currentFormMSA);
					m_currentFormMSA = null;
					break;
				}
				case "Exception":
				{
					Debug.Assert(reader.HasAttributes);
					// "<Exception code='ReachedMaxBufferSize' totalAnalyses='117'/>\n"
					string codeValue = null;
					string totalAnalysesValue = null;
					for (int i = 0; i < reader.AttributeCount; ++i)
					{
						reader.MoveToAttribute(i);
						switch (reader.Name)
						{
							default:
								Debug.Assert(false, "Unknown attribute '" + reader.Name + "' in <Exception> element.");
								break;
							case "code":
								codeValue = reader.Value;
								break;
							case "totalAnalyses":
								totalAnalysesValue = reader.Value;
								break;
						}
					}
					Debug.Assert(codeValue != null && totalAnalysesValue != null);
					string msg = null;
					switch (codeValue)
					{
						default:
							Debug.Assert(false, "Unknown code value: " + codeValue);
							break;
						case "ReachedMaxAnalyses":
							msg = String.Format(ParserCoreStrings.ksReachedMaxAnalysesAllowed,
								totalAnalysesValue);
							break;
						case "ReachedMaxBufferSize":
							msg = String.Format(ParserCoreStrings.ksReachedMaxInternalBufferSize,
								totalAnalysesValue);
							break;
					}
					reader.MoveToElement();
					SqlCommand command = m_connection.CreateCommand();
					command.CommandText = string.Format("exec CreateParserProblemAnnotation '{0}', {1}, {2}, {3}",
						msg, m_currentWordformId, m_agentId, "null"); // TODO: Replace "null" with an annotationDefn some day.
					command.CommandTimeout = 60; // seconds, which is the default of 30.
					command.ExecuteNonQuery();
					if (m_currentWordformId > 0)
					{
						// The least we can do is clear out any stale analyses.
						FinishWordForm();
						ResetForNextWord();
					}
					keepReading = false; // Stop, since the XML beyond this point may not be well-formed.
					break;
				}
			}
			return keepReading;
		}
Example #4
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>
		private void Dispose(bool disposing)
		{
			//Debug.WriteLineIf(!disposing, "****************** " + GetType().Name + " 'disposing' is false. ******************");
			// Must not be run more than once.
			if (m_isDisposed)
				return;

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

			// Dispose unmanaged resources here, whether disposing is true or false.
			m_formMsaObjs = null;
			// Caller will handle disposal of m_connection,
			// since it provided it.
			m_connection = null;
			m_currentFormMSA = null;
			m_lastEngineUpdate = null;

			m_isDisposed = true;
		}
Example #5
0
 /*------------------------------------------------------------------------------------------
 *       Clear out the data related to a particular word, get ready for the next one
 *  ------------------------------------------------------------------------------------------*/
 private void ResetForNextWord()
 {
     m_currentWordformId = 0;
     m_currentFormMSA    = null;
     m_formMsaObjs.Clear();
 }
Example #6
0
        private bool ProcessElementStart(XmlTextReader reader)
        {
            bool keepReading = true;             // Be optimistic.

            switch (reader.Name)
            {
            default:
                break;                         // Do nothing for any others.

            case "Wordform":
            {
                Debug.Assert(m_agentId > 0);
                m_currentWordformId = GetId(reader);
                SqlCommand command = m_connection.CreateCommand();
                command.CommandTimeout = 60;                         // seconds, which is the default of 30.
                command.CommandText    = string.Format("SELECT count(*) "
                                                       + "FROM WfiWordform_Analyses "
                                                       + "WHERE Src={0}", m_currentWordformId);
                m_startAnalysesCount = (int)command.ExecuteScalar();
                command.CommandText  = string.Format("SELECT Id from CmBaseAnnotation_ "
                                                     + "WHERE BeginObject={0} and Source={1}", m_currentWordformId, m_agentId);
                SqlDataReader sqlReader  = null;
                Set <int>     problemIDs = new Set <int>();
                try                         // Needs a try here in order to deal with reader on a problem.
                {
                    sqlReader = command.ExecuteReader();
                    // Gather up a list of ids, since we have to close the reader,
                    // before actually deleting them.
                    while (sqlReader.Read())
                    {
                        problemIDs.Add(sqlReader.GetInt32(0));
                    }
                }
                finally
                {
                    if (sqlReader != null)
                    {
                        sqlReader.Close();
                        sqlReader = null;
                    }
                }
                // REVIEW/TODO: it would be faster to delete these all at once rather than one at a time.
                foreach (int problemID in problemIDs)
                {
                    command             = m_connection.CreateCommand();
                    command.CommandText = string.Format("EXEC DeleteObjects '{0}'", problemID);
                    command.ExecuteNonQuery();
                }
#if TrackingPFProblems
                // Set the id to the wordform you want to look at,
                // and then put a breakpoint on the Debug.WriteLine line.
                if (m_currentWordformId == 4616)
                {
                    Debug.WriteLine("Have biliya.");
                }
#endif
                // REVIEW RandyR: Should this be turned into an SP?
                command             = m_connection.CreateCommand();
                command.CommandText = String.Format(
                    "DECLARE @d datetime;\n"
                    + "set @d = '{0}';\n"
                    + "declare @retval int;\n"
                    + "exec @retval = SetAgentEval {1}, {2}, 1, 'a wordform eval', @d;\n"
                    + "select @retval",
                    m_lastEngineUpdate, m_agentId, m_currentWordformId);
                if ((int)command.ExecuteScalar() != 0)
                {
                    throw new Exception("Unspecified SetAgentEval stored procedure problem.");
                }
                break;
            }

            case "WfiAnalysis":
            {
                Debug.Assert(m_formMsaObjs.Count == 0);
#if DOSOMETHINGFORFAILURE
                if (reader.IsEmptyElement)
                {
                    try
                    {
                        ProcessAnalysis();
                    }
                    catch
                    {
                        ResetForNextWord();
                        throw;
                    }
                    finally
                    {
                        Debug.Assert(m_currentWordformId > 0 &&
                                     m_agentId > 0 &&
                                     m_formMsaObjs.Count == 0);
                    }
                }
#endif
                break;
            }

            case "MoForm":
            {
                Debug.Assert(m_currentFormMSA == null);
                m_currentFormMSA = new FormMSA(GetId(reader));
                break;
            }

            case "MSI":
                goto case "MSA";                         // Fall through.

            case "MSA":
            {
                Debug.Assert(m_currentFormMSA != null &&
                             m_currentFormMSA.m_formId > 0 &&
                             m_currentFormMSA.m_msaId == 0);

                m_currentFormMSA.m_msaId = GetId(reader);
                m_formMsaObjs.Add(m_currentFormMSA);
                m_currentFormMSA = null;
                break;
            }

            case "Exception":
            {
                Debug.Assert(reader.HasAttributes);
                // "<Exception code='ReachedMaxBufferSize' totalAnalyses='117'/>\n"
                string codeValue          = null;
                string totalAnalysesValue = null;
                for (int i = 0; i < reader.AttributeCount; ++i)
                {
                    reader.MoveToAttribute(i);
                    switch (reader.Name)
                    {
                    default:
                        Debug.Assert(false, "Unknown attribute '" + reader.Name + "' in <Exception> element.");
                        break;

                    case "code":
                        codeValue = reader.Value;
                        break;

                    case "totalAnalyses":
                        totalAnalysesValue = reader.Value;
                        break;
                    }
                }
                Debug.Assert(codeValue != null && totalAnalysesValue != null);
                string msg = null;
                switch (codeValue)
                {
                default:
                    Debug.Assert(false, "Unknown code value: " + codeValue);
                    break;

                case "ReachedMaxAnalyses":
                    msg = String.Format(ParserCoreStrings.ksReachedMaxAnalysesAllowed,
                                        totalAnalysesValue);
                    break;

                case "ReachedMaxBufferSize":
                    msg = String.Format(ParserCoreStrings.ksReachedMaxInternalBufferSize,
                                        totalAnalysesValue);
                    break;
                }
                reader.MoveToElement();
                SqlCommand command = m_connection.CreateCommand();
                command.CommandText = string.Format("exec CreateParserProblemAnnotation '{0}', {1}, {2}, {3}",
                                                    msg, m_currentWordformId, m_agentId, "null"); // TODO: Replace "null" with an annotationDefn some day.
                command.CommandTimeout = 60;                                                      // seconds, which is the default of 30.
                command.ExecuteNonQuery();
                if (m_currentWordformId > 0)
                {
                    // The least we can do is clear out any stale analyses.
                    FinishWordForm();
                    ResetForNextWord();
                }
                keepReading = false;                         // Stop, since the XML beyond this point may not be well-formed.
                break;
            }
            }
            return(keepReading);
        }