Пример #1
0
        public void IntProp()
        {
            int valNew = m_ISilDataAccess.get_IntProp(1115, 2225);

            Assert.AreEqual(0, valNew);

            bool f;

            valNew = m_IVwCacheDa.get_CachedIntProp(1115, 2225, out f);
            Assert.AreEqual(false, f);
            Assert.AreEqual(0, valNew);

            m_IVwCacheDa.CacheIntProp(1115, 2225, int.MaxValue);
            valNew = m_ISilDataAccess.get_IntProp(1115, 2225);
            Assert.AreEqual(int.MaxValue, valNew);
            valNew = m_IVwCacheDa.get_CachedIntProp(1115, 2225, out f);
            Assert.AreEqual(true, f);
            Assert.AreEqual(int.MaxValue, valNew);

            m_IVwCacheDa.CacheIntProp(1115, 2225, int.MinValue);
            valNew = m_ISilDataAccess.get_IntProp(1115, 2225);
            Assert.AreEqual(int.MinValue, valNew);
            valNew = m_IVwCacheDa.get_CachedIntProp(1115, 2225, out f);
            Assert.AreEqual(true, f);
            Assert.AreEqual(int.MinValue, valNew);
        }
Пример #2
0
        /// <summary>
        /// Fake doing the change by setting the specified property to the appropriate value
        /// for each item in the list. Disable items that can't be set.
        /// </summary>
        /// <param name="itemsToChange"></param>
        /// <param name="ktagFakeFlid"></param>
        public void FakeDoit(Set <int> itemsToChange, int tagFakeFlid, int tagEnable, ProgressState state)
        {
            CheckDisposed();

            IVwCacheDa     cda = m_cache.VwCacheDaAccessor;
            ISilDataAccess sda = m_cache.MainCacheAccessor;
            ITsString      tss = m_cache.MakeAnalysisTss(m_selectedLabel);
            // Build a Set of parts of speech that can take this class.
            Set <int> possiblePOS = GetPossiblePartsOfSpeech();

            int i = 0;
            // Report progress 50 times or every 100 items, whichever is more (but no more than once per item!)
            int interval = Math.Min(100, Math.Max(itemsToChange.Count / 50, 1));

            foreach (int hvo in itemsToChange)
            {
                i++;
                if (i % interval == 0)
                {
                    state.PercentDone = i * 100 / itemsToChange.Count;
                    state.Breath();
                }
                bool fEnable = IsItemEligible(sda, hvo, possiblePOS);
                if (fEnable)
                {
                    cda.CacheStringProp(hvo, tagFakeFlid, tss);
                }
                cda.CacheIntProp(hvo, tagEnable, (fEnable ? 1 : 0));
            }
        }
Пример #3
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.LostFocus"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param>
        /// ------------------------------------------------------------------------------------
        protected override void OnLostFocus(EventArgs e)
        {
            m_xmlVc.HasFocus = false;
            // Our selected objects are no longer treated as such.
            ISilDataAccess sda = Cache.MainCacheAccessor;
            IVwCacheDa     cda = Cache.VwCacheDaAccessor;

            foreach (int hvo in m_selectedObjects)
            {
                cda.CacheIntProp(hvo, m_xmlVc.IsObjectSelectedTag, 0);
                sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, hvo, m_xmlVc.IsObjectSelectedTag, 0, 1, 1);
            }
            base.OnLostFocus(e);
        }
Пример #4
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// When we get focus, start filtering messages to catch characters
        /// </summary>
        /// <param name="e"></param>
        /// ------------------------------------------------------------------------------------
        protected override void OnGotFocus(EventArgs e)
        {
            m_xmlVc.HasFocus = true;
            if (!m_selectedObjects.Contains(XmlVc.FocusHvo))
            {
                m_selectedObjects.Add(XmlVc.FocusHvo);
            }
            // Whatever any other view may have done while we don't have focus, our selected objects
            // are now treated as selected. And, all of them need propChanged, to force redrawing.
            ISilDataAccess sda = Cache.MainCacheAccessor;
            IVwCacheDa     cda = Cache.VwCacheDaAccessor;

            foreach (int hvo in m_selectedObjects)
            {
                cda.CacheIntProp(hvo, m_xmlVc.IsObjectSelectedTag, 1);
                sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, hvo, m_xmlVc.IsObjectSelectedTag, 0, 1, 1);
            }

            base.OnGotFocus(e);
        }
Пример #5
0
        int MakeObject(XmlNode elt)
        {
            string className = elt.Name;
            int    clid      = m_mdc.GetClassId(className);

            if (clid == 0)
            {
                throw new Exception("class not found " + className);
            }
            int hvo = GetId(elt);

            m_cda.CacheIntProp(hvo, (int)CmObjectFields.kflidCmObject_Class, (int)clid);
            foreach (XmlNode child in elt.ChildNodes)
            {
                if (child is XmlComment)
                {
                    continue;
                }
                switch (child.Name)
                {
                case "seq":
                    AddOwningSeqProp(hvo, child);
                    break;

                case "ms":
                    AddMultiStringProp(hvo, child);
                    break;

                case "obj":
                    AddOwningAtomicProp(hvo, child);
                    break;

                default:
                    throw new Exception("unexpected element " + child.Name + " found in " + className);
                }
            }
            return(hvo);
        }
Пример #6
0
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Selections the changed.
        /// </summary>
        /// <param name="prootb">The prootb.</param>
        /// <param name="sel">The sel.</param>
        /// ------------------------------------------------------------------------------------
        public override void SelectionChanged(IVwRootBox prootb, IVwSelection sel)
        {
            CheckDisposed();

            if (m_fInChangeSelectedObjects)
            {
                return;
            }
            m_fInChangeSelectedObjects = true;
            try
            {
                int cvsli = 0;

                // Out variables for AllTextSelInfo.
                int          ihvoRoot      = 0;
                int          tagTextProp   = 0;
                int          cpropPrevious = 0;
                int          ichAnchor     = 0;
                int          ichEnd        = 0;
                int          ws            = 0;
                bool         fAssocPrev    = false;
                int          ihvoEnd       = 0;
                ITsTextProps ttpBogus      = null;
                SelLevInfo[] rgvsli        = new SelLevInfo[0];

                List <int> newSelectedObjects = new List <int>(4);
                newSelectedObjects.Add(XmlVc.FocusHvo);
                if (sel != null)
                {
                    cvsli = sel.CLevels(false) - 1;
                    // Main array of information retrived from sel that made combo.
                    rgvsli = SelLevInfo.AllTextSelInfo(sel, cvsli,
                                                       out ihvoRoot, out tagTextProp, out cpropPrevious, out ichAnchor, out ichEnd,
                                                       out ws, out fAssocPrev, out ihvoEnd, out ttpBogus);
                    for (int i = 0; i < cvsli; i++)
                    {
                        newSelectedObjects.Add(rgvsli[i].hvo);
                    }
                }
                ISilDataAccess sda = Cache.MainCacheAccessor;
                IVwCacheDa     cda = Cache.VwCacheDaAccessor;
                foreach (int hvo in m_selectedObjects)
                {
                    if (!newSelectedObjects.Contains(hvo))
                    {
                        cda.CacheIntProp(hvo, m_xmlVc.IsObjectSelectedTag, 0);
                        sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, hvo, m_xmlVc.IsObjectSelectedTag, 0, 1, 1);
                    }
                }
                foreach (int hvo in newSelectedObjects)
                {
                    if (!m_selectedObjects.Contains(hvo))
                    {
                        cda.CacheIntProp(hvo, m_xmlVc.IsObjectSelectedTag, 1);
                        sda.PropChanged(null, (int)PropChangeType.kpctNotifyAll, hvo, m_xmlVc.IsObjectSelectedTag, 0, 1, 1);
                    }
                }
                m_selectedObjects = newSelectedObjects;
                if (sel != null && !sel.IsValid)
                {
                    // we wiped it out by regenerating parts of the display in our PropChanged calls! Restore it if we can.
                    sel = m_rootb.MakeTextSelection(ihvoRoot, cvsli, rgvsli, tagTextProp,
                                                    cpropPrevious, ichAnchor, ichEnd, ws, fAssocPrev, ihvoEnd, ttpBogus, true);
                }
            }

            finally
            {
                m_fInChangeSelectedObjects = false;
            }
            base.SelectionChanged(prootb, sel);
        }
Пример #7
0
		private void LoadSecDataForEntry(ILexEntry entryReal, ILexSense senseReal, int hvoSbWord, IVwCacheDa cda, int wsVern,
			int hvoMbSec, int fGuessing, ISilDataAccess sdaMain, ITsStrFactory tsf)
		{
			int hvoEntry = m_caches.FindOrCreateSec(entryReal.Hvo, kclsidSbNamedObj,
				hvoSbWord, ktagSbWordDummy);
			// try to determine if the given entry is a variant of the sense we passed in (ie. not an owner)
			ILexEntryRef ler = null;
			int hvoEntryToDisplay = entryReal.Hvo;
			if (senseReal != null)
			{
				if ((entryReal as ILexEntry).IsVariantOfSenseOrOwnerEntry(senseReal, out ler))
					hvoEntryToDisplay = senseReal.EntryID;
			}

			ITsString tssLexEntry = LexEntryVc.GetLexEntryTss(Cache, hvoEntryToDisplay, wsVern, ler);
			cda.CacheStringAlt(hvoEntry, ktagSbNamedObjName, wsVern, tssLexEntry);
			cda.CacheObjProp(hvoMbSec, ktagSbMorphEntry, hvoEntry);
			cda.CacheIntProp(hvoEntry, ktagSbNamedObjGuess, fGuessing);
			List<int> writingSystems = m_choices.OtherWritingSystemsForFlid(InterlinLineChoices.kflidLexEntries, 0);
			if (writingSystems.Count > 0)
			{
				// Sigh. We're trying for some reason to display other alternatives of the entry.
				int hvoLf = sdaMain.get_ObjectProp(hvoEntryToDisplay, LexEntryTags.kflidLexemeForm);
				if (hvoLf != 0)
					CopyStringsToSecondary(writingSystems, sdaMain, hvoLf,
						MoFormTags.kflidForm, cda, hvoEntry, ktagSbNamedObjName, tsf);
				else
					CopyStringsToSecondary(writingSystems, sdaMain, hvoEntryToDisplay,
						LexEntryTags.kflidCitationForm, cda, hvoEntry, ktagSbNamedObjName, tsf);
			}
		}
Пример #8
0
		/// <summary>
		/// Query is a bit of sql that returns a set of triples, a CmBaseAnnotation id, begin offset, and end offset.
		/// Run the query and return an array of the ids.
		/// Also cache the offsets and that these annotations have m_para.Hvo as their BeginObject.
		/// </summary>
		private int[] ReadAnnotationInfo(IVwCacheDa cda, int hvoAnnType, Dictionary<int, List<int>> paragraphAnnotationMap)
		{
			string query = "select cba.id, cba.BeginOffset, cba.EndOffset, cba.BeginObject " +
				"from CmBaseAnnotation cba " +
				"join CmAnnotation ca on cba.id = ca.id and ca.AnnotationType = {0} " +
				"{1} " +
				"order by cba.BeginObject, cba.BeginOffset";
			string queryFilter = "";
			string joinedIds = "";
			if (m_hvosStTxtPara != null)
			{
				joinedIds = CmObject.JoinIds(m_hvosStTxtPara, ",");
			}
			else if (m_hvosStText != null)
			{
				joinedIds = ""; // in this case, we'll just load for all texts.
			}
			else if (m_hvoText != 0)
			{
				// limit the query to the paragraphs in the given StText
				StText stText = new StText(Cache, m_hvoText);
				joinedIds = CmObject.JoinIds(stText.ParagraphsOS.HvoArray, ",");
			}
			else
			{
				// limit the query to the paragraph.
				joinedIds = m_para.Hvo.ToString();
			}
			if (!String.IsNullOrEmpty(joinedIds))
				queryFilter = string.Format("where cba.BeginObject in ({0})", joinedIds);
			query = String.Format(query, hvoAnnType, queryFilter);
			int[] annotations;
			List<int[]> annotationInfo;
			if (m_cache.DatabaseAccessor == null)
			{
				// testing without a database: no existing annotations (unless pre-created by test)
				annotationInfo = new List<int[]>();
			}
			else
			{
				// normal case
				annotationInfo = DbOps.ReadIntArray(m_cache, query, null, 4);
			}
			annotations = new int[annotationInfo.Count];
			if (annotations.Length == 0)
				return annotations;

			paragraphAnnotationMap.Clear();
			List<int> paragraphAnnotations = null;
			int hvoPara = 0;
			int hvoParaPrev = 0;
			for (int i = 0; i < annotations.Length; i++)
			{
				int[] rowInfo = annotationInfo[i];
				int hvoAnnotation = rowInfo[0];
				hvoPara = rowInfo[3];
				if (hvoPara != hvoParaPrev || hvoPara == 0)
				{
					// start building a new set of ids.
					paragraphAnnotations = new List<int>();
					paragraphAnnotationMap[hvoPara] = paragraphAnnotations;
					hvoParaPrev = hvoPara;
				}
				paragraphAnnotations.Add(hvoAnnotation);
				annotations[i] = hvoAnnotation;
				cda.CacheObjProp(hvoAnnotation,
					(int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginObject, hvoPara);
				cda.CacheIntProp(hvoAnnotation,
					(int)CmBaseAnnotation.CmBaseAnnotationTags.kflidBeginOffset, rowInfo[1]);
				cda.CacheIntProp(hvoAnnotation,
					(int)CmBaseAnnotation.CmBaseAnnotationTags.kflidEndOffset, rowInfo[2]);
			}

			return annotations;
		}
Пример #9
0
		/// <summary>
		/// The value of this property is the length of the string property on which it is based.
		/// </summary>
		/// <param name="hvo"></param>
		/// <param name="tag"></param>
		/// <param name="ws"></param>
		/// <param name="cda"></param>
		public override void Load(int hvo, int tag, int ws, IVwCacheDa cda)
		{
			ISilDataAccess sda = cda as ISilDataAccess;
			ITsString tss;
			int wsId = this.WsId(m_cache, hvo, ws != 0 ? ws : m_ws);
			if (wsId == 0)
				tss = sda.get_StringProp(hvo, m_flid);
			else
				tss = sda.get_MultiStringAlt(hvo, m_flid, wsId);
			cda.CacheIntProp(hvo, tag, tss.Length);
		}
Пример #10
0
		/// <summary>
		///
		/// </summary>
		/// <param name="hvo"></param>
		/// <param name="tag"></param>
		/// <param name="ws"></param>
		/// <param name="cda"></param>
		public override void Load(int hvo, int tag, int ws, IVwCacheDa cda)
		{
			cda.CacheIntProp(hvo, tag, 0);
		}
Пример #11
0
		/// <summary>
		///
		/// </summary>
		/// <param name="hvo"></param>
		/// <param name="tag"></param>
		/// <param name="ws"></param>
		/// <param name="cda"></param>
		public override void Load(int hvo, int tag, int ws, IVwCacheDa cda)
		{
			if (BaseVirtualHandler.ForceBulkLoadIfPossible &&
				m_bulkMethodInfo != null && m_bulkValues == null)
			{
				SetLoadForAllOfClass(true);
				BaseVirtualHandler.m_rgvhBulkForced.Add(this);
			}
			ICmObject fdoObj = null;
			if (m_cache.IsDummyObject(hvo))
			{
				RequestConversionToRealEventArgs args = new RequestConversionToRealEventArgs(hvo, tag, m_configuration, false);
				OnRequestConversionToReal(this, args);
				fdoObj = args.RealObject;	// null, if no conversion took place.
			}
			if (fdoObj == null)
			{
				fdoObj = CmObject.CreateFromDBObject(m_cache, hvo);
			}
			int nVal = 0;
			if (m_bulkMethodInfo != null && m_bulkValues != null)
			{
				if (!m_fBulkLoaded)
				{
					m_bulkMethodInfo.Invoke(null, new object[] { m_cache, m_bulkValues });
					m_fBulkLoaded = true;
				}
				if (!m_bulkValues.TryGetValue(hvo, out nVal))
					nVal = 0;
			}
			else
			{
				nVal = (int)m_propertyInfo.GetValue(fdoObj, null);
			}
			cda.CacheIntProp(hvo, tag, nVal);
		}