public void ValidatePhEnvironment_StringRepresentation()
        {
            // Add a character to the set of phoneme representations so that the environment below
            // will pass muster.
            IPhPhonemeSet phset = Cache.ServiceLocator.GetInstance <IPhPhonemeSetFactory>().Create();

            Cache.LanguageProject.PhonologicalDataOA.PhonemeSetsOS.Add(phset);
            AddPhone(phset, "a");
            AddPhone(phset, "b");
            AddPhone(phset, "c");
            AddPhone(phset, "d");
            AddPhone(phset, "e");

            ConstraintFailure failure = null;
            int            strRepFlid = PhEnvironmentTags.kflidStringRepresentation;
            IPhEnvironment env        = Cache.ServiceLocator.GetInstance <IPhEnvironmentFactory>().Create();

            Cache.LangProject.PhonologicalDataOA.EnvironmentsOS.Add(env);
            IEnumerable <ICmBaseAnnotation> os = GetAnnotationsForObject(env);

            Assert.AreEqual(0, os.Count(), "Wrong starting count of annotations.");

            env.StringRepresentation = Cache.TsStrFactory.MakeString(@"/ [BADCLASS] _", Cache.DefaultAnalWs);
            Assert.IsFalse(env.CheckConstraints(strRepFlid, true, out failure, true));
            Assert.IsNotNull(failure, "Didn't get an object back from the CheckConstraints method.");
            os = GetAnnotationsForObject(env);
            Assert.AreEqual(1, os.Count(), "Wrong invalid count of annotations.");

            env.StringRepresentation = Cache.TsStrFactory.MakeString(@"/ d _", Cache.DefaultAnalWs);
            Assert.IsTrue(env.CheckConstraints(strRepFlid, true, out failure, true));
            Assert.IsNull(failure, "Got an object back from the CheckConstraints method.");
            os = GetAnnotationsForObject(env);
            Assert.AreEqual(0, os.Count(), "Wrong valid count of annotations.");
        }
            private void DoValidation(bool refresh)
            {
                Form frm = FindForm();
                // frm may be null, if the record has been switched
                WaitCursor wc = null;

                try
                {
                    if (frm != null)
                    {
                        wc = new WaitCursor(frm);
                    }
                    ConstraintFailure failure;
                    m_env.CheckConstraints(PhEnvironmentTags.kflidStringRepresentation, true, out failure, /* adjust the squiggly line */ true);
                    // This will make the record list update to the new value.
                    if (refresh)
                    {
                        Mediator.BroadcastMessage("Refresh", null);
                    }
                }
                finally
                {
                    if (wc != null)
                    {
                        wc.Dispose();
                    }
                }
            }
Exemple #3
0
        public void ValidatePhEnvironment_StringRepresentation()
        {
            // Add a character to the set of phoneme representations so that the environment below
            // will pass muster.
            IPhPhonemeSet phset = Cache.ServiceLocator.GetInstance <IPhPhonemeSetFactory>().Create();

            Cache.LanguageProject.PhonologicalDataOA.PhonemeSetsOS.Add(phset);
            AddPhone(phset, "a");
            AddPhone(phset, "b");
            AddPhone(phset, "c");
            AddPhone(phset, "d");
            AddPhone(phset, "e");

            ConstraintFailure failure = null;
            int            strRepFlid = PhEnvironmentTags.kflidStringRepresentation;
            IPhEnvironment env        = Cache.ServiceLocator.GetInstance <IPhEnvironmentFactory>().Create();

            Cache.LangProject.PhonologicalDataOA.EnvironmentsOS.Add(env);
            IEnumerable <ICmBaseAnnotation> os = GetAnnotationsForObject(env);

            Assert.AreEqual(0, os.Count(), "Wrong starting count of annotations.");

            env.StringRepresentation = TsStringUtils.MakeString(@"/ [BADCLASS] _", Cache.DefaultAnalWs);

            m_actionHandler.EndUndoTask();             // so we can verify it makes its own as needed, and doesn't do unnecessary ones.

            Assert.IsFalse(env.CheckConstraints(strRepFlid, true, out failure, true));
            Assert.IsNotNull(failure, "Didn't get an object back from the CheckConstraints method.");
            os = GetAnnotationsForObject(env);
            Assert.AreEqual(1, os.Count(), "Wrong invalid count of annotations.");

            int cUndoTasks = m_actionHandler.UndoableActionCount;

            Assert.IsFalse(env.CheckConstraints(strRepFlid, true, out failure, true));
            Assert.That(m_actionHandler.UndoableActionCount, Is.EqualTo(cUndoTasks), "should not make database changes when situation is unchanged");

            NonUndoableUnitOfWorkHelper.Do(m_actionHandler, () =>
                                           env.StringRepresentation = TsStringUtils.MakeString(@"/ d _", Cache.DefaultAnalWs));
            Assert.IsTrue(env.CheckConstraints(strRepFlid, true, out failure, true));
            Assert.IsNull(failure, "Got an object back from the CheckConstraints method.");
            os = GetAnnotationsForObject(env);
            Assert.AreEqual(0, os.Count(), "Wrong valid count of annotations.");

            cUndoTasks = m_actionHandler.UndoableActionCount;
            Assert.IsTrue(env.CheckConstraints(strRepFlid, true, out failure, true));
            Assert.That(m_actionHandler.UndoableActionCount, Is.EqualTo(cUndoTasks), "should not make database changes when situation is unchanged");
        }
Exemple #4
0
        /// <summary>
        /// Integrate changes in dummy cache to real cache and DB.
        /// </summary>
        public void ConnectToRealCache()
        {
            CheckDisposed();
            // We're saving any changes to the real cache, so can no longer Undo/Redo local edits.
            CommitLocalEdits();
            Form frm = FindForm();

            // frm will be null, if the record has been switched
            if (frm != null)
            {
                frm.Cursor = Cursors.WaitCursor;
            }
            // [NB: m_silCache is the same cache as m_vwCache,
            // but is is a different cache than m_fdoCache.
            // m_fdoCache has access to the database, and updates it,
            // but m_silCache does not.]
            if (DesignMode ||
                m_rootb == null
                // It may not be valid by now, since it may have been deleted.
                || !m_rootObj.IsValidObject())
            {
                if (frm != null)
                {
                    frm.Cursor = Cursors.Default;
                }
                return;
            }
            FdoOwningSequence <IPhEnvironment> phoneEnvs =
                m_fdoCache.LangProject.PhonologicalDataOA.EnvironmentsOS;
            int count = m_silCache.get_VecSize(m_rootObj.Hvo, kMainObjEnvironments);

            // We need one less than the size,
            // because the last 'env' is a dummy that lets the user type a new one.
            int[] hvos  = new int[count - 1];
            int   cvDel = 0;

            for (int i = hvos.Length - 1; i >= 0; --i)
            {
                IPhEnvironment env         = null;
                int            hvoDummyObj = m_silCache.get_VecItem(m_rootObj.Hvo, kMainObjEnvironments, i);
                ITsString      tss         = m_silCache.get_StringProp(hvoDummyObj, kEnvStringRep);
                ITsStrBldr     bldr        = tss.GetBldr();
                string         rep         = tss.Text;
                if (rep == null || rep.Length == 0)
                {
                    // The environment at 'i' is being deleted, so
                    // shrink the array of hvos that go into the real cache.
                    cvDel++;
                    m_realEnvs.Remove(hvoDummyObj);
                    // Remove it from the dummy cache.
                    int oldSelId = m_hvoOldSelection;
                    m_hvoOldSelection = hvoDummyObj;
                    RemoveFromDummyCache(i);
                    m_hvoOldSelection = oldSelId;
                }
                else
                {
                    foreach (IPhEnvironment envCurrent in phoneEnvs)
                    {
                        // Compare them without spaces, since they are not needed.
                        if (envCurrent.StringRepresentation.Text != null &&
                            envCurrent.StringRepresentation.Text.Replace(" ", null) ==
                            rep.Replace(" ", null))
                        {
                            env = envCurrent;
                            // Maybe the ws has changed, so change the real one, in case.
                            env.StringRepresentation.UnderlyingTsString = tss;
                            break;
                        }
                    }
                    if (env == null)
                    {
                        env = phoneEnvs.Append(new PhEnvironment());
                        env.StringRepresentation.UnderlyingTsString = tss;
                        m_fdoCache.PropChanged(null, PropChangeType.kpctNotifyAll, m_fdoCache.LangProject.PhonologicalDataOA.Hvo, (int)PhPhonData.PhPhonDataTags.kflidEnvironments, phoneEnvs.Count - 1, 1, 0);
                    }
                    ConstraintFailure failure;
                    if (env.CheckConstraints((int)PhEnvironment.PhEnvironmentTags.kflidStringRepresentation, out failure, /* adjust the squiggly line */ true))
                    {
                        ClearSquigglyLine(hvoDummyObj, ref tss, ref bldr);
                    }
                    else
                    {
                        MakeSquigglyLine(hvoDummyObj, failure.XmlDescription, ref tss, ref bldr);
                    }
                    hvos[i] = env.Hvo;
                    // Refresh
                    m_vwCache.CacheStringProp(hvoDummyObj, kEnvStringRep, bldr.GetString());
                    m_silCache.PropChanged(null, (int)PropChangeType.kpctNotifyAll,
                                           hvoDummyObj, kEnvStringRep, 0, tss.Length, tss.Length);
                }
            }
            int[] newHvos = new int[hvos.Length];
            hvos.CopyTo(newHvos, 0);
            if (cvDel > 0)
            {
                newHvos = new int[hvos.Length - cvDel];
                count   = 0;
                for (int i = 0; i < hvos.Length; ++i)
                {
                    int tempHvo = hvos[i];
                    if (tempHvo > 0)
                    {
                        newHvos[count++] = tempHvo;
                    }
                }
            }
            count = m_fdoCache.GetVectorSize(m_rootObj.Hvo, m_rootFlid);
            // Only reset the main property, if it has changed.
            // Otherwise, the parser gets too excited about needing to reload.
            if ((count != newHvos.Length) ||
                !equalArrays(m_fdoCache.GetVectorProperty(m_rootObj.Hvo, m_rootFlid, true), newHvos))
            {
                string fieldname =
                    (m_rootFlid == (int)MoAffixAllomorph.MoAffixAllomorphTags.kflidPhoneEnv)
                                        ? "PhoneEnv" : "Position";
                m_fdoCache.BeginUndoTask(
                    String.Format(DetailControlsStrings.ksUndoSet, fieldname),
                    String.Format(DetailControlsStrings.ksRedoSet, fieldname));
                m_fdoCache.ReplaceReferenceProperty(m_rootObj.Hvo, m_rootFlid, 0, count,
                                                    ref newHvos);
                m_fdoCache.EndUndoTask();
            }
            if (frm != null)
            {
                frm.Cursor = Cursors.Default;
            }
        }