Esempio n. 1
0
        private ViewBuilder AddMlsClientRun(Func <IViewMultiString> fetcher, MlsClientRun run, int ws)
        {
            ParaBox para = InsertParaOrRun(run);

            var mls          = fetcher();
            var stringHookup = new MlsHookup(null, fetcher(), ws,
                                             hookup => mls.StringChanged += hookup.MlsPropChanged,
                                             hookup => mls.StringChanged += hookup.MlsPropChanged,
                                             para);

            AddHookupToRun(run, stringHookup);

            // Try to hook an event for notification of changes to the property.
            //MemberExpression mexp = (fetchString.Body as MemberExpression);
            //var argExp = Expression.Lambda<Func<object>>(mexp.Expression);
            //Type type = mexp.Member.DeclaringType;
            //string name = mexp.Member.Name;
            //EventInfo einfo = type.GetEvent(name + "Changed");
            //var target = argExp.Compile().Invoke();
            //if (einfo == null)
            //{
            //    MakeHookupForString(fetcher, run, name, target, para);
            //}
            //else
            //{
            //    var stringHookup = new MlsHookup(target, fetcher(), ws,
            //        hookup => einfo.AddEventHandler(target, new EventHandler<MlsChangedEventArgs>(hookup.MlsPropChanged)),
            //        hookup => einfo.RemoveEventHandler(target, new EventHandler<MlsChangedEventArgs>(hookup.MlsPropChanged)), para);
            //    AddHookupToRun(run, stringHookup);
            //    var propInfo = type.GetProperty(name);
            //}
            return(this);
        }
Esempio n. 2
0
        public void HookupMlString()
        {
            MockData1 data1 = new MockData1(m_wsFrn, m_wsEng);

            data1.MlSimpleOne.VernacularDefaultWritingSystem = m_tsf.MakeString("foo", m_wsFrn);

            MockParaBox mockPara = new MockParaBox();
            MlsHookup   mlHook   = new MlsHookup(data1, data1.MlSimpleOne, m_wsFrn, MockData1Props.MlSimpleOne(data1), mockPara);

            mlHook.ClientRunIndex = 7;

            data1.MlSimpleOne.SetVernacularDefaultWritingSystem("bar");

            data1.RaiseMlSimpleOneChanged(m_wsFrn);
            Assert.AreEqual(7, mockPara.TheIndex, "Should have fired the event and passed the string index");
            Assert.AreEqual("bar", mockPara.TheMlString.get_String(((MultiAccessor)data1.MlSimpleOne).VernWs).Text, "Should have informed para of new string");

            mockPara.TheTsString = m_tsf.MakeString("foo", m_wsFrn);

            data1.MlSimpleOne.SetAnalysisDefaultWritingSystem("eng");

            data1.RaiseMlSimpleOneChanged(m_wsEng);
            Assert.AreEqual("foo", mockPara.TheTsString.Text, "Should not have informed para of new string, since we are monitoring French and mocking English event");
            mlHook.Dispose();
        }