Esempio n. 1
0
        /// <summary>
        /// Make one. Call DoIt to actually make the change.
        /// </summary>
        /// <param name="cache"></param>
        /// <param name="hvo"></param>
        /// <param name="flid"></param>
        /// <param name="ihvoMin"></param>
        /// <param name="ihvoLim"></param>
        /// <param name="newValues"></param>
        public CacheReplaceOneUndoAction(FdoCache cache, int hvo, int flid, int ihvoMin, int ihvoLim, int[] newValues)
        {
            m_cache = cache;
            m_sda   = cache.MainCacheAccessor;
            m_hvo   = hvo;
            m_flid  = flid;
            IVwVirtualHandler vh;

            if (m_cache.TryGetVirtualHandler(m_flid, out vh))
            {
                m_bvh = vh as BaseVirtualHandler;
            }
            m_index     = ihvoMin;
            m_newValues = newValues;
            m_cvDel     = ihvoLim - ihvoMin;
            Debug.Assert(m_cvDel >= 0 && m_cvDel <= 1, "Currently only support deleting one item at a time.");
            if (m_cvDel > 0)
            {
                m_oldValue = m_sda.get_VecItem(hvo, flid, ihvoMin);
            }
        }
Esempio n. 2
0
			/// <summary>
			/// Return the segment range in terms of the segment indexes of the BeginObject segment property of the given hvoCba.
			/// </summary>
			/// <param name="cache"></param>
			/// <param name="hvoCba"></param>
			/// <param name="iBeginSegment">zero-based index into segments</param>
			/// <param name="iEndSegment">zero-based into segments</param>
			/// <returns></returns>
			static public bool TryGetSegmentRange(FdoCache cache, int hvoCba,
				out int iBeginSegment, out int iEndSegment)
			{
				iBeginSegment = -1;
				iEndSegment = -1;
				int[] segments = null;
				// if it's a twfic type, then use twfic info, otherwise find a segment range.
				ICmBaseAnnotation cba = CmBaseAnnotation.CreateFromDBObject(cache, hvoCba);
				int hvoPara = cba.BeginObjectRAHvo;
				IVwVirtualHandler vh;
				// first try to get the segments from our Segments virtual handler
				// if that has not been loaded for the paragraph, try SegmentsIgnoreTwfics
				// to save time.
				if (cache.TryGetVirtualHandler(StTxtPara.SegmentsFlid(cache), out vh) &&
					(vh as BaseFDOPropertyVirtualHandler).IsPropInCache(cache.MainCacheAccessor, hvoPara, 0))
				{
					if (cba.AnnotationTypeRAHvo != 0)
					{
						StTxtPara.TwficInfo twficInfo = new StTxtPara.TwficInfo(cache, hvoCba);
						if (twficInfo.SegmentIndex >= 0)
						{
							iBeginSegment = twficInfo.SegmentIndex;		// return zero-based index.
						}
						else if (!cache.IsDummyObject(hvoCba))
						{
							int segIndexLogical;
							string sql = string.Format("exec GetSegmentIndex {0}, {1}", hvoCba, CmAnnotationDefn.TextSegment(cache).Hvo);
							DbOps.ReadOneIntFromCommand(cache, sql, null, out segIndexLogical);
							if (segIndexLogical > 0)
								iBeginSegment = segIndexLogical - 1;	 // subtract 1 to get a zero-based index.
						}
					}
					if (iBeginSegment < 0)
						segments = cache.GetVectorProperty(hvoPara, vh.Tag, true);
				}
				else if (cache.TryGetVirtualHandler(StTxtPara.SegmentsIgnoreTwficsFlid(cache), out vh))
				{
					segments = cache.GetVectorProperty(hvoPara, vh.Tag, true);
				}
				if (iBeginSegment < 0)
				{
					// this is annotation into a paragraph (but may not be a twfic or exist in SegForms).
					// if it's not a twfic, find a segment range.
					ISilDataAccess sda = cache.MainCacheAccessor;
					int ihvoSeg = 0;
					int cbaBeginOffset = cba.BeginOffset;
					int cbaEndOffset = cba.EndOffset;
					for (; ihvoSeg < segments.Length; ihvoSeg++)
					{
						int segEndOffset = sda.get_IntProp(segments[ihvoSeg], (int)CmBaseAnnotation.CmBaseAnnotationTags.kflidEndOffset);
						if (segEndOffset <= cbaBeginOffset)
						{
							continue;
						}
						else if (iBeginSegment < 0)
						{
							iBeginSegment = ihvoSeg;
						}
						if (segEndOffset > cbaEndOffset)
						{
							iEndSegment = ihvoSeg;
							break; // we've passed our annotation's EndOffset, so the previous segment is the last one in range.
						}
					}
					// ihvoSeg should now be one index passed the segment in our range. this eguals the logical segment number.
					if (iBeginSegment >= 0 && iEndSegment == -1)
					{
						iEndSegment = ihvoSeg < segments.Length ? ihvoSeg - 1 : segments.Length - 1;
					}
				}
				return iBeginSegment >= 0;
			}
Esempio n. 3
0
		/// <summary>
		/// Try deleting wordforms when none of the given paragraphs have annotations (including dummies)
		/// with instances of the wordforms.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="wfIdsToTry">wordform ids to try to delete</param>
		/// <param name="hvoParasInView">the paragraphs that may have dummy annotations with instances of those wordforms</param>
		/// <param name="delObjIds">the wordforms that actually got deleted.</param>
		/// <returns>true if we deleted a wordform</returns>
		public static bool TryDeleteWordforms(FdoCache cache, int[] wfIdsToTry, int[] hvoParasInView, out Set<int> delObjIds)
		{
			int vtagSegments = StTxtPara.SegmentsFlid(cache);
			IVwVirtualHandler vh;
			cache.TryGetVirtualHandler(vtagSegments, out vh);
			FDOSequencePropertyVirtualHandler segmentsVh = vh as FDOSequencePropertyVirtualHandler;
			delObjIds = new Set<int>(wfIdsToTry.Length);
			foreach (int wfid in wfIdsToTry)
			{
				if (!cache.IsValidObject(wfid))
					continue;	// already been deleted, probably as a consequence of annotation.DeleteUnderlyingObject.
				ICmObject obj = CmObject.CreateFromDBObject(cache, wfid, false);
				if (obj.CanDelete)
				{
					// make a final check to see if any of the segment forms in the given paragraphs contain an
					// instance to this wordform. If not, it's safe to delete it.
					if (!WordformHasOccurrenceInParas(cache, wfid, hvoParasInView, segmentsVh))
						delObjIds.Add(wfid);
				}
			}
			foreach (WfiWordform wf in new FdoObjectSet<WfiWordform>(cache, delObjIds.ToArray(), false, typeof(WfiWordform)))
			{
				wf.DeleteUnderlyingObject();
			}
			return delObjIds.Count != 0;
		}
Esempio n. 4
0
		private void SetupGhostOwningFlidInfo(FdoCache cache, int ghostListFlid)
		{
			if (ghostListFlid == 0)
				return;
			IVwVirtualHandler vh;
			cache.TryGetVirtualHandler(ghostListFlid, out vh);
			m_vh = vh as FDOGhostSequencePropertyVirtualHandler;
			// the ghost owner is on the last level.
			m_cpiForOwningFlidForGhost = m_vh.RealOwningPath[m_vh.RealOwningPath.Count - 1];
		}
Esempio n. 5
0
		/// <summary>
		/// Make one. Call DoIt to actually make the change.
		/// </summary>
		/// <param name="cache"></param>
		/// <param name="hvo"></param>
		/// <param name="flid"></param>
		/// <param name="ihvoMin"></param>
		/// <param name="ihvoLim"></param>
		/// <param name="newValues"></param>
		public CacheReplaceOneUndoAction(FdoCache cache, int hvo, int flid, int ihvoMin, int ihvoLim, int[] newValues)
		{
			m_cache = cache;
			m_sda = cache.MainCacheAccessor;
			m_hvo = hvo;
			m_flid = flid;
			IVwVirtualHandler vh;
			if (m_cache.TryGetVirtualHandler(m_flid, out vh))
			{
				m_bvh = vh as BaseVirtualHandler;
			}
			m_index = ihvoMin;
			m_newValues = newValues;
			m_cvDel = ihvoLim - ihvoMin;
			Debug.Assert(m_cvDel >= 0 && m_cvDel <= 1, "Currently only support deleting one item at a time.");
			if (m_cvDel > 0)
				m_oldValue = m_sda.get_VecItem(hvo, flid, ihvoMin);
		}