private void VerifyCurrentValue(int hvoRoot, ObjectListPublisher publisher, int[] values, string label)
 {
     int[] newValues = publisher.VecProp(hvoRoot, ObjectListFlid);
     Assert.AreEqual(values.Length, newValues.Length, label + "length from VecProp");
     for (int i = 0; i < values.Length; i++)
     {
         Assert.AreEqual(values[i], newValues[i], label + " item " + i + " from VecProp");
     }
 }
        public void SetAndAccessDummyList()
        {
            ILexDb      lexDb  = Cache.LangProject.LexDbOA;
            ILexEntry   entry1 = null;
            ICmResource res1   = null;

            NonUndoableUnitOfWorkHelper.Do(m_actionHandler, () =>
            {
                var leFactory    = Cache.ServiceLocator.GetInstance <ILexEntryFactory>();
                entry1           = leFactory.Create();
                ILexEntry entry2 = leFactory.Create();
                res1             = Cache.ServiceLocator.GetInstance <ICmResourceFactory>().Create();
                lexDb.ResourcesOC.Add(res1);
            });

            int hvoRoot = 10578;
            ObjectListPublisher publisher = new ObjectListPublisher(Cache.MainCacheAccessor as ISilDataAccessManaged, ObjectListFlid);
            var      values   = new int[] { 23, 56, 2048 };
            Notifiee recorder = new Notifiee();

            publisher.AddNotification(recorder);
            publisher.CacheVecProp(hvoRoot, values);
            Assert.AreEqual(values.Length, publisher.get_VecSize(hvoRoot, ObjectListFlid), "override of vec size");
            //Assert.AreEqual(Cache.LangProject.Texts.Count, publisher.get_VecSize(Cache.LangProject.Hvo, LangProjectTags.kflidTexts), "base vec size");

            Assert.AreEqual(23, publisher.get_VecItem(hvoRoot, ObjectListFlid, 0), "override of vec item");
            Assert.AreEqual(res1.Hvo, publisher.get_VecItem(lexDb.Hvo, LexDbTags.kflidResources, 0), "base vec item");
            Assert.AreEqual(56, publisher.get_VecItem(hvoRoot, ObjectListFlid, 1), "override of vec item, non-zero index");

            VerifyCurrentValue(hvoRoot, publisher, values, "original value");
            Assert.AreEqual(lexDb.ResourcesOC.Count(), publisher.VecProp(lexDb.Hvo, LexDbTags.kflidResources).Length, "base VecProp");

            recorder.CheckChanges(new ChangeInformationTest[] { new ChangeInformationTest(hvoRoot, ObjectListFlid, 0, values.Length, 0) },
                                  "expected PropChanged from caching HVOs");
            publisher.RemoveNotification(recorder);

            recorder = new Notifiee();
            publisher.AddNotification(recorder);
            publisher.Replace(hvoRoot, 1, new int[] { 97, 98 }, 0);
            VerifyCurrentValue(hvoRoot, publisher, new int[] { 23, 97, 98, 56, 2048 }, "after inserting 97, 98");
            recorder.CheckChanges(new ChangeInformationTest[] { new ChangeInformationTest(hvoRoot, ObjectListFlid, 1, 2, 0) },
                                  "expected PropChanged from caching HVOs");
            publisher.RemoveNotification(recorder);

            recorder = new Notifiee();
            publisher.AddNotification(recorder);
            publisher.Replace(hvoRoot, 1, new int[0], 2);
            VerifyCurrentValue(hvoRoot, publisher, new int[] { 23, 56, 2048 }, "after deleting 97, 98");
            recorder.CheckChanges(new ChangeInformationTest[] { new ChangeInformationTest(hvoRoot, ObjectListFlid, 1, 0, 2) },
                                  "expected PropChanged from caching HVOs");
            publisher.RemoveNotification(recorder);
        }
        /// ------------------------------------------------------------------------------------
        /// <summary>
        /// Create a view with multiple LexEntry objects.
        /// </summary>
        /// <param name="rghvoEntries"></param>
        /// <param name="cache"></param>
        /// <param name="styleSheet"></param>
        /// <returns></returns>
        /// ------------------------------------------------------------------------------------
        private XmlView CreateSummaryView(List <int> rghvoEntries, FdoCache cache, IVwStylesheet styleSheet)
        {
            // Make a decorator to publish the list of entries as a fake property of the LexDb.
            int kflidEntriesFound = 8999950;             // some arbitrary number not conflicting with real flids.
            var sda     = new ObjectListPublisher(cache.DomainDataByFlid as ISilDataAccessManaged, kflidEntriesFound);
            int hvoRoot = RootHvo;

            sda.CacheVecProp(hvoRoot, rghvoEntries.ToArray());
            // The name of this property must match the property used by the publishFound layout.
            sda.SetOwningPropInfo(LexDbTags.kflidClass, "LexDb", "EntriesFound");

            // Make an XmlView which displays that object using the specified layout.
            XmlView xv = new XmlView(hvoRoot, "publishFound", null, false, sda);

            xv.Cache      = cache;
            xv.Mediator   = m_mediator;
            xv.StyleSheet = styleSheet;
            return(xv);
        }
        private void InitBrowseView(string guiControl, List <DummyCmObject> mergeCandidates)
        {
            XmlNode configurationParameters = (XmlNode)m_mediator.PropertyTable.GetValue("WindowConfiguration");
            XmlNode toolNode = configurationParameters.SelectSingleNode("controls/parameters/guicontrol[@id='" + guiControl + "']/parameters");

            const int           kfakeFlid = 8999958;
            ObjectListPublisher sda       = new ObjectListPublisher((ISilDataAccessManaged)m_cache.DomainDataByFlid, kfakeFlid);

            int[] hvos = (from obj in mergeCandidates select obj.Hvo).ToArray();
            for (int i = 0; i < mergeCandidates.Count; i++)
            {
                m_candidates[mergeCandidates[i].Hvo] = mergeCandidates[i];
            }
            sda.SetOwningPropInfo(WfiWordformTags.kClassId, "LangProject", "Options");
            sda.SetOwningPropValue(hvos);

            m_bvMergeOptions                       = new BrowseViewer(toolNode, m_cache.LangProject.Hvo, ObjectListPublisher.OwningFlid, m_cache, m_mediator, null, sda);
            m_bvMergeOptions.StyleSheet            = Common.Widgets.FontHeightAdjuster.StyleSheetFromMediator(m_mediator);
            m_bvMergeOptions.SelectedIndexChanged += m_bvMergeOptions_SelectedIndexChanged;
            m_bvMergeOptions.Dock                  = DockStyle.Fill;
            m_bvPanel.Controls.Add(m_bvMergeOptions);
        }