Exemplo n.º 1
0
        public static TestItemVM GetTestItemVM(TestItem tr)
        {
            if (ViewModelDict.Keys.Contains(tr))
            {
                return(ViewModelDict[tr] as TestItemVM);
            }
            else
            {
                // var res = Interface.GetViewModelFromModel(tr.GetType());
                var res = Interface.GetItemViewModelFromModel(tr.GetType());
                if (res == null)
                {
                    if (tr is PointTestItem)
                    {
                        PointTestItemVM ptVM = new PointTestItemVM();
                        ptVM.TestItem = tr;
                        ViewModelDict.Add(tr, ptVM);
                        return(ptVM);
                    }
                    if (tr is TestTrace)
                    {
                        TestTraceVM trVM = new TestTraceVM();
                        trVM.TestItem = tr;
                        ViewModelDict.Add(tr, trVM);
                        return(trVM);
                    }
                    if (tr is TRTestItem)
                    {
                        TRTestItemVM trTestVM = new TRTestItemVM();
                        trTestVM.TestItem = tr;
                        ViewModelDict.Add(tr, trTestVM);
                        return(trTestVM);
                    }
                    return(null);
                }
                else
                {
                    TestItemVM trVM = res as TestItemVM;
                    trVM.TestItem = tr;
                    ViewModelDict.Add(tr, trVM);
                    return(trVM);
                }

                //if (trVM != null)
                //{
                //    trVM.TestItem = tr;
                //}
                //else
                //{
                //    trVM = new TestItemVM();
                //}
                //ViewModelDict.Add(tr, trVM);
                //return trVM;
            }
        }
Exemplo n.º 2
0
        public static object GetItemViewModelFromModel(Type modelType)
        {
            var        itemInfo = TestStepFactory.ItemTypelist.Where(x => x.Type.FullName == modelType.FullName).FirstOrDefault();
            TestItemVM itemVM   = null;

            if (itemInfo != null)
            {
                if (itemInfo.Att.ItemViewModelTypeStr == null || string.IsNullOrWhiteSpace(itemInfo.Att.ItemViewModelTypeStr))
                {
                    return(itemVM);
                }
                string   viewModelStr = itemInfo.Att.ItemViewModelTypeStr;
                string[] strs         = viewModelStr.Split(';');
                string   fileName     = AppDomain.CurrentDomain.BaseDirectory + strs[0];
                viewModelStr = viewModelStr.Remove(0, strs[0].Length + 1);
                Assembly ass           = Assembly.LoadFile(fileName);
                Type     typeViewModel = ass.GetType(viewModelStr);
                itemVM = Activator.CreateInstance(typeViewModel) as TestItemVM;
            }
            return(itemVM);
        }