private ICmBaseAnnotation MakeSegment(IStTxtPara para, int beginOffset, int length)
        {
            ICmBaseAnnotation seg = CmBaseAnnotation.CreateUnownedCba(Cache);

            seg.BeginObjectRA       = para;
            seg.BeginOffset         = beginOffset;
            seg.EndOffset           = beginOffset + length;
            seg.AnnotationTypeRAHvo = m_hvoSegDefn;
            ISilDataAccess sda = para.Cache.MainCacheAccessor;

            int[] segments;
            if (sda.get_IsPropInCache(para.Hvo, kflidSegments, (int)CellarModuleDefns.kcptReferenceSequence, 0))
            {
                int[] segmentsT = Cache.GetVectorProperty(para.Hvo, kflidSegments, true);
                segments = new int[segmentsT.Length];
                Array.Copy(segmentsT, segments, segmentsT.Length);
                segments[segments.Length - 1] = seg.Hvo;
            }
            else
            {
                segments = new int[] { seg.Hvo };
            }
            para.Cache.VwCacheDaAccessor.CacheVecProp(seg.Hvo, kflidSegments, segments, segments.Length);
            return(seg);
        }
Пример #2
0
 /// <summary>
 /// Make one AND make the change to the cache.
 /// </summary>
 /// <param name="sda"></param>
 /// <param name="hvo"></param>
 /// <param name="flid"></param>
 /// <param name="newValue"></param>
 public CacheObjPropUndoAction(ISilDataAccess sda, int hvo, int flid, int newValue)
 {
     m_sda      = sda;
     m_hvo      = hvo;
     m_flid     = flid;
     m_newValue = newValue;
     m_oldValue = 0;
     // Since this is used for fake props, if it isn't already cached, it doesn't have an old value.
     if (sda.get_IsPropInCache(hvo, flid, (int)CellarModuleDefns.kcptReferenceAtom, 0))
     {
         m_oldValue = sda.get_ObjectProp(hvo, flid);
     }
     DoIt(m_newValue);
 }
Пример #3
0
        public void LoadData()
        {
            // Get the language project as an FDO object
            ILangProject lp = m_fdoCache.LangProject;

            // Use it to get the HVO of the data notebook, but without making an FDO object
            // and thus loading data.
            Assert.IsTrue(m_sda.get_IsPropInCache(lp.Hvo,
                                                  (int)LangProject.LangProjectTags.kflidResearchNotebook,
                                                  (int)CellarModuleDefns.kcptOwningAtom, 0),
                          "LP notebook loaded by FDO");
            int hvoNotebook = m_fdoCache.GetObjProperty(lp.Hvo,
                                                        (int)LangProject.LangProjectTags.kflidResearchNotebook);

            Assert.IsFalse(m_sda.get_IsPropInCache(hvoNotebook,
                                                   (int)RnResearchNbk.RnResearchNbkTags.kflidRecords,
                                                   (int)CellarModuleDefns.kcptOwningCollection, 0),
                           "Nb records not loaded");
            // Do a simple pre-load to get the records.
            IVwDataSpec dts = VwDataSpecClass.Create();

            // Request loading the title of each record. (Note that currently we must make
            // an entry for each concrete class; making one for the base class does not work.)
            dts.AddField(RnAnalysis.kClassId,
                         (int)RnGenericRec.RnGenericRecTags.kflidTitle,
                         FldType.kftString,
                         m_fdoCache.LanguageWritingSystemFactoryAccessor,
                         0);
            dts.AddField(RnEvent.kClassId,
                         (int)RnGenericRec.RnGenericRecTags.kflidTitle,
                         FldType.kftString,
                         m_fdoCache.LanguageWritingSystemFactoryAccessor,
                         0);
            int[] clsids = new int[1];
            clsids[0] = RnResearchNbk.kClassId;
            int[] hvos = new int[1];
            hvos[0] = hvoNotebook;
            m_da.LoadData(hvos, clsids, hvos.Length, dts, null, true);
            Assert.IsTrue(m_sda.get_IsPropInCache(hvoNotebook,
                                                  (int)RnResearchNbk.RnResearchNbkTags.kflidRecords,
                                                  (int)CellarModuleDefns.kcptOwningCollection, 0),
                          "Nb records are loaded");
            int chvoRecs = m_sda.get_VecSize(hvoNotebook,
                                             (int)RnResearchNbk.RnResearchNbkTags.kflidRecords);

            // Be careful what we assert...don't want it too dependent on the exact data.
            // Should be OK to assume at least a few records.
            Assert.IsTrue(chvoRecs > 4, "at least 4 recs");
            int hvoRec3 = m_sda.get_VecItem(hvoNotebook,
                                            (int)RnResearchNbk.RnResearchNbkTags.kflidRecords, 3);

            Assert.IsTrue(m_sda.get_IsPropInCache(hvoRec3,
                                                  (int)RnGenericRec.RnGenericRecTags.kflidTitle,
                                                  (int)CellarModuleDefns.kcptString, 0),
                          "Got title of rec 3");
            ITsString qtssRec3Title = m_sda.get_StringProp(hvoRec3,
                                                           (int)RnGenericRec.RnGenericRecTags.kflidTitle);
            // Now get the info through FDO
            ICmObject objRec3 = CmObject.CreateFromDBObject(m_fdoCache, hvoRec3);

            Assert.IsTrue(objRec3 is IRnGenericRec, "object of correct type");
            IRnGenericRec grRec3 = (IRnGenericRec)objRec3;

            // I'd prefer to use full ITsString equality test, but not sure how to get
            // a regular ITsString from FDO obj.
            Assert.AreEqual(qtssRec3Title.Text, grRec3.Title.Text,
                            "two ways to retrieve R3 title match");
        }
Пример #4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="hvo"></param>
 /// <param name="tag"></param>
 /// <param name="cpt"></param>
 /// <param name="ws"></param>
 /// <returns></returns>
 public bool get_IsPropInCache(int hvo, int tag, int cpt, int ws)
 {
     return(m_sda.get_IsPropInCache(hvo, tag, cpt, ws));
 }
Пример #5
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Check the IsPropInCache method.
        /// </summary>
        /// <param name="hvo">HVO part of the key</param>
        /// <param name="tag">tag part of the key</param>
        /// <param name="expValues">Expected values</param>
        /// ------------------------------------------------------------------------------------
        private void CheckIsPropInCache(int hvo, int tag, object[] expValues)
        {
            for (CellarPropertyType cpt = CellarPropertyType.Nil;
                 cpt <= CellarPropertyType.ReferenceSequence; cpt++)
            {
                bool flag = false;
                switch (cpt)
                {
                case CellarPropertyType.Nil:
                    try
                    {
                        Assert.IsFalse(m_ISilDataAccess.get_IsPropInCache(hvo, tag,
                                                                          (int)cpt, 0));
                    }
                    catch (ArgumentException)
                    {
                    }
                    continue;

                case CellarPropertyType.Boolean:
                case CellarPropertyType.Integer:
                case CellarPropertyType.Numeric:
                    flag = ((int)expValues[5] != 0);
                    break;

                case CellarPropertyType.Float:
                    // Never cached so far
                    // TODO: We expect this to fail the test for VwCacheDa because the existing
                    // implementation fails to set the return value to false. Need to fix this
                    // at line 520 of VwCacheDa.cpp.
                    break;

                case CellarPropertyType.Time:
                    flag = (expValues[4] is long || (int)expValues[4] != 0);
                    break;

                case CellarPropertyType.Guid:
                    flag = ((Guid)expValues[3] != Guid.Empty);
                    break;

                case CellarPropertyType.Image:
                case CellarPropertyType.GenDate:
                    // Never cached so far
                    // TODO: We expect this to fail the test for VwCacheDa because the existing
                    // implementation fails to set the return value to false. Need to fix this
                    // at line 535 of VwCacheDa.cpp.
                    break;

                case CellarPropertyType.Binary:
                    flag = (expValues[2] is byte[]);
                    break;

                case CellarPropertyType.MultiString:
                case CellarPropertyType.MultiUnicode:
                    flag = (expValues[6] != null);
                    break;

                case CellarPropertyType.String:
                    flag = (expValues[7] != null);
                    break;

                case CellarPropertyType.Unicode:
                    flag = (expValues[8] != null);
                    break;

                case CellarPropertyType.OwningAtomic:
                case CellarPropertyType.ReferenceAtomic:
                    flag = ((int)expValues[0] != 0);
                    break;

                case CellarPropertyType.OwningCollection:
                case CellarPropertyType.ReferenceCollection:
                case CellarPropertyType.OwningSequence:
                case CellarPropertyType.ReferenceSequence:
                    flag = (expValues[1] is int[]);
                    break;

                default:
                    continue;
                }
                Assert.AreEqual(flag, m_ISilDataAccess.get_IsPropInCache(hvo, tag, (int)cpt, 12345),
                                string.Format("IsPropInCache for property type '{0}' failed;", cpt));
            }
        }
Пример #6
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Get all the possibilities (or subpossibiities) of the owner and (optionally their
		/// subpossibilities).
		/// </summary>
		/// <param name="hvoOwn">The hvo own.</param>
		/// <param name="flid">flid for Possibilities for a CmPossibilityList, or
		/// SubPossibilities for a CmPossibility</param>
		/// <param name="list">list of ids to return.</param>
		/// <param name="sda">The sda.</param>
		/// <param name="fGetAllDescendants">if true, recurse to get ALL subpossibilities.</param>
		/// ------------------------------------------------------------------------------------
		private static void GetItems(int hvoOwn, int flid, Set<int> list, ISilDataAccess sda,
			bool fGetAllDescendants)
		{
			int flidPss = (int)CellarModuleDefns.kflidCmPossibility_SubPossibilities;
			int chvo = 0;
			// Note, calling get_VecSize directly will result in a SQL query for all of the nodes of
			// the tree to verify that they are zero. This generates around 1400 queries for the
			// semantic domain list during loading. These will likely never be needed for anything
			// else, so it simply wastes time.
			if (sda.get_IsPropInCache(hvoOwn, flid, (int)FieldType.kcptOwningCollection, 0))
				chvo = sda.get_VecSize(hvoOwn, flid);
			for (int ihvo = 0; ihvo < chvo; ++ihvo)
			{
				int hvo = sda.get_VecItem(hvoOwn, flid, ihvo);
				list.Add(hvo);
				if (fGetAllDescendants)
					CmPossibility.GetItems(hvo, flidPss, list, sda, fGetAllDescendants);
			}
		}
Пример #7
0
		/// <summary>
		/// Make one AND make the change to the cache.
		/// </summary>
		/// <param name="sda"></param>
		/// <param name="hvo"></param>
		/// <param name="flid"></param>
		/// <param name="newValue"></param>
		public CacheObjPropUndoAction(ISilDataAccess sda, int hvo, int flid, int newValue)
		{
			m_sda = sda;
			m_hvo = hvo;
			m_flid = flid;
			m_newValue = newValue;
			m_oldValue = 0;
			// Since this is used for fake props, if it isn't already cached, it doesn't have an old value.
			if (sda.get_IsPropInCache(hvo, flid, (int)CellarModuleDefns.kcptReferenceAtom, 0))
				m_oldValue = sda.get_ObjectProp(hvo, flid);
			DoIt(m_newValue);
		}
Пример #8
0
		/// ------------------------------------------------------------------------------------
		/// <summary>
		/// Determines whether our Tag has been stored in the cache for the given hvo and ws.
		/// </summary>
		/// <param name="sda">The sda.</param>
		/// <param name="hvo">hvo owner of Tag</param>
		/// <param name="ws">0, if the Tag does not relate to ws.</param>
		/// <returns><c>true</c> if the prop is in the cache; otherwise, <c>false</c>.</returns>
		/// ------------------------------------------------------------------------------------
		public bool IsPropInCache(ISilDataAccess sda, int hvo, int ws)
		{
			return sda.get_IsPropInCache(hvo, this.Tag, this.Type, ws);
		}
Пример #9
0
 /// <summary>
 /// Find out whether a particular property is cached.
 /// Eventually we may support using kcptNil as 'any' but not yet.
 /// cpt is a member of the defines in CmTypes.h
 /// ws is ignored unless cpt is kcptMulti...
 ///</summary>
 /// <param name='hvo'></param>
 /// <param name='tag'></param>
 /// <param name='cpt'></param>
 /// <param name='ws'></param>
 /// <returns></returns>
 public virtual bool get_IsPropInCache(int hvo, int tag, int cpt, int ws)
 {
     return(m_baseSda.get_IsPropInCache(hvo, tag, cpt, ws));
 }
Пример #10
0
 /// ------------------------------------------------------------------------------------
 /// <summary>
 /// Determines whether our Tag has been stored in the cache for the given hvo and ws.
 /// </summary>
 /// <param name="sda">The sda.</param>
 /// <param name="hvo">hvo owner of Tag</param>
 /// <param name="ws">0, if the Tag does not relate to ws.</param>
 /// <returns><c>true</c> if the prop is in the cache; otherwise, <c>false</c>.</returns>
 /// ------------------------------------------------------------------------------------
 public bool IsPropInCache(ISilDataAccess sda, int hvo, int ws)
 {
     return(sda.get_IsPropInCache(hvo, this.Tag, this.Type, ws));
 }
Пример #11
0
		/// <summary>
		/// If object hvo has no cached value for the property flidVirtual, do nothing.
		/// Otherwise, compute a new value for the property, and issue a PropChanged. (Currently only string type supported)
		/// If it has owning properties of type clidVirtual, do the same for all their items.
		/// </summary>
		/// <param name="hvo"></param>
		/// <param name="flidVirtual"></param>
		/// <param name="mdc"></param>
		/// <param name="sda"></param>
		private void RecomputeVirtuals(int hvo, uint clidVirtual, int flidVirtual, int typeVirtual, IFwMetaDataCache mdc, ISilDataAccess sda,
			IVwVirtualHandler vh)
		{
			if (Cache.GetClassOfObject(hvo) != clidVirtual)
				return;
			// Unless it's a computeEveryTime property, we don't need to worry if it's not already cached.
			if (vh.ComputeEveryTime || sda.get_IsPropInCache(hvo, flidVirtual, typeVirtual, 0))
			{
				vh.Load(hvo, flidVirtual, 0, Cache.VwCacheDaAccessor);
				switch (typeVirtual)
				{
					case (int)CellarModuleDefns.kcptString:
						sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, hvo, flidVirtual, 0, 0, 0);
						break;
					default:
						Debug.WriteLine("RecomputeVirtuals: unimplemented prop type");
						break;
				}
			}
			uint[] flids = DbOps.GetFieldsInClassOfType(mdc, (int)clidVirtual, FieldType.kgrfcptOwning);
			foreach (uint flid in flids)
			{
				int type = mdc.GetFieldType(flid);
				if (type == (int)CellarModuleDefns.kfcptOwningAtom)
				{
					RecomputeVirtuals(sda.get_ObjectProp(hvo, (int)flid), clidVirtual, flidVirtual, typeVirtual, mdc, sda, vh);
				}
				else
				{
					// must be owning sequence or collection; do them all.
					int chvo = sda.get_VecSize(hvo, (int)flid);
					for (int i = 0; i < chvo; i++)
						RecomputeVirtuals(sda.get_VecItem(hvo, (int)flid, i), clidVirtual, flidVirtual, typeVirtual, mdc, sda, vh);

				}
			}
		}