private void TestPropertyClassEqControl(Pair pair)
        {
            string partOfConfig = pair.ConfigItem;
            string control      = pair.Control;


            var propertiesControl = CUtilReflex.GetPropertiesList(GetControlTypeSt(control));

            var fieldsControl = CUtilReflex.GetFiedsList(GetControlTypeSt(control));



            var propertiesConfig = CUtilReflex.GetPropertiesList(GetPropertyTypeSt(partOfConfig));

            propertiesConfig.ForEach(property =>
            {
                string propertyName       = property.Name;
                string dependencyPropName = propertyName + "Property";

                if (propertiesControl.FirstOrDefault(a => a.Name == propertyName) == null)
                {
                    Error(String.Format("Control {0} doesn't contain property {1}  ",
                                        control, propertyName));
                }

                if (fieldsControl.FirstOrDefault(a => a.Name == dependencyPropName) == null)
                {
                    Error(String.Format("Control {0} doesn't contain dependency property {1}  ",
                                        control, dependencyPropName));
                }
            }
                                     );
        }
Esempio n. 2
0
        private static void LoadOneClassProperties <TypeViewModel>(object classWithProps, TypeViewModel marketViewmodel)
        {
            classWithProps.GetType().GetProperties().ToList().ForEach(
                propertyConfig =>
            {
                try
                {
                    var valueConfig = propertyConfig.GetValue(classWithProps, null);
                    if (valueConfig != null)
                    {
                        marketViewmodel.GetType().GetProperties().ToList().ForEach(
                            propertyViewMdl =>
                        {
                            if (propertyViewMdl.Name == propertyConfig.Name)
                            {
                                //string stVal = val.ToString();
                                //propertyConfig.SetValue(classWithProps, stVal, null);
                                //propertyViewMdl.SetValue(marketViewmodel, valueConfig, null);
                                CUtilReflex.SetPropertyValue(marketViewmodel, propertyViewMdl, valueConfig);
                            }
                        }

                            );
                    }
                }
                catch (Exception e)
                {
                    CKernelTerminal.ErrorStatic("LoadOneClassProperties", e);
                }
            }
                );
        }
Esempio n. 3
0
        private void ModelVMSynchro <TModel, TVM>(List <TModel> lstModels,
                                                  ObservableCollection <TVM> collectionVM,
                                                  Func <TModel, TVM> createVMElement)
        {
            //number of lines changed that means
            //delete or insert occured
            if (lstModels.Count != collectionVM.Count)
            {
                collectionVM.Clear();
                lstModels.ForEach(modelElement =>
                {
                    collectionVM.Add(createVMElement.Invoke(modelElement));
                }
                                  );
            }
            else
            {
                //note: at this point assume amount of elements in lstModels is
                //equal of collectionVM

                for (int i = 0; i < lstModels.Count; i++)
                {
                    List <PropertyInfo> sourceProperties = lstModels[i].GetType().GetProperties().ToList();
                    List <PropertyInfo> destProperties   = collectionVM[i].GetType().GetProperties().ToList();

                    if (sourceProperties.Count != destProperties.Count)
                    {
                        throw new ApplicationException("ModelVMSyncro. sourceProperties.Count != destProperties.Count");
                    }

                    sourceProperties.ForEach
                        (srcProp =>
                    {
                        bool bfound = false;
                        destProperties.ForEach
                            (dstProp =>
                        {
                            if (srcProp.Name == dstProp.Name)
                            {
                                bfound       = true;
                                object dstEl = dstProp.GetValue(collectionVM[i], null);
                                object srcEl = srcProp.GetValue(lstModels[i], null);

                                if (!CUtilReflex.IsEqualValues(srcEl, dstEl))
                                {
                                    dstProp.SetValue(collectionVM[i], srcEl, null);
                                }
                            }
                        }
                            );

                        if (!bfound)
                        {
                            Error("ModelVMSyncro. " + srcProp.Name + "not found");
                        }
                    }
                        );
                }
            }
        }
Esempio n. 4
0
        private void CheckUpdateOrAdd(List <TModelElement> inpList)
        {
            foreach (var modelElement in inpList)
            {
                bool bFoundEqKeys = false;
                for (int i = 0; i < _collectionVm.Count; i++)
                {
                    List <PropertyInfo> sourceProperties = modelElement.GetType().GetProperties().ToList();
                    List <PropertyInfo> destProperties   = _collectionVm[i].GetType().GetProperties().ToList();

                    int cntEqKeysFound = 0;

                    //bool bNotEqKeyFnd = false;



                    //compare properties of two current elements
                    foreach (var srcPropInfo in sourceProperties)
                    {
                        foreach (var dstPropInfo in destProperties)
                        {
                            if (_lstKeys.Contains(srcPropInfo.Name) &&
                                srcPropInfo.Name == dstPropInfo.Name)
                            {
                                if (CUtilReflex.IsEqualValues(srcPropInfo.GetValue(modelElement, null),
                                                              dstPropInfo.GetValue(_collectionVm[i], null)))
                                {
                                    cntEqKeysFound++;
                                    //all of  keys are matched
                                    if (cntEqKeysFound == _lstKeys.Count)
                                    {
                                        _collectionVm[i] = _createVMElement(modelElement);

                                        //keys found
                                        //no need to iterate more properties
                                        bFoundEqKeys = true;
                                        break;
                                    }
                                }
                            }
                        }
                        //keys found no need to iterate more
                        if (bFoundEqKeys)
                        {
                            break;
                        }
                    }
                }

                //we iterated all _lstModelElements and not found element from source
                //so we need to add element to _lstModelElemets
                if (!bFoundEqKeys)
                {
                    _collectionVm.Add(_createVMElement.Invoke((modelElement)));
                }
            }
        }
Esempio n. 5
0
        public static void Test()
        {
            int i1 = 2;
            int i2 = 2;

            Assert.IsTrue(CUtilReflex.IsEqualValues((object)i1, (object)i2));

            i1 = 2;
            i2 = 3;
            Assert.IsFalse(CUtilReflex.IsEqualValues((object)i1, (object)i2));

            long l1 = 2;
            long l2 = 2;

            Assert.IsTrue(CUtilReflex.IsEqualValues((object)l1, (object)l2));

            l1 = 2;
            l2 = 3;

            Assert.IsFalse(CUtilReflex.IsEqualValues((object)l1, (object)l2));

            decimal d1 = 2.01m;
            decimal d2 = 2.01m;

            Assert.IsTrue(CUtilReflex.IsEqualValues((object)d1, (object)d2));

            d1 = 2.01m;
            d2 = 2.02m;

            Assert.IsFalse(CUtilReflex.IsEqualValues((object)d1, (object)d2));

            double dbl1 = 2.01;
            double dbl2 = 2.01;

            Assert.IsTrue(CUtilReflex.IsEqualValues((object)dbl1, (object)dbl2));

            dbl1 = 2.01;
            dbl2 = 2.02;

            Assert.IsFalse(CUtilReflex.IsEqualValues((object)dbl1, (object)dbl2));

            string st1 = "ab";
            string st2 = "ab";

            Assert.IsTrue(CUtilReflex.IsEqualValues((object)st1, (object)st2));

            st1 = "ab";
            st2 = "aB";

            Assert.IsFalse(CUtilReflex.IsEqualValues((object)st1, (object)st2));
        }
        private void TestConfigFileEqPropertyClass(XmlNode xmlNode, string partOfConfigFile)
        {
            var properties = CUtilReflex.GetPropertiesList(GetPropertyTypeSt(partOfConfigFile));



            //if element in config doesn't exists in property
            foreach (XmlNode node in xmlNode.ChildNodes)
            {
                var res = properties.FirstOrDefault(el => el.Name == node.Name);
                if (res == null)
                {
                    Error(String.Format("Element {0} doesn't exist in property class {1}", node.Name, GetPropertyTypeSt(partOfConfigFile)));
                }
            }
        }
Esempio n. 7
0
 public void SetDataFromConfigToTerminalViewModel()
 {
     lock (TerminalConfig)
     {
         foreach (var propertyFromList in _terminalConfig.TerminalProperties.TerminalGlobalProperties.GetType().GetProperties())
         {
             PropertyInfo VMProperty = ViewModelDispatcher.TerminalViewModel.GetType().GetProperty(propertyFromList.Name);
             if (VMProperty != null)
             {
                 CUtilReflex.SetPropertyValue(ViewModelDispatcher.TerminalViewModel,
                                              VMProperty,
                                              propertyFromList.GetValue(_terminalConfig.TerminalProperties.TerminalGlobalProperties, null));
             }
             //if (property.Name ==
         }
     }
 }
Esempio n. 8
0
        public static void BindAllFromViewModel <TypeOfViewModel>(TypeOfViewModel viewModel, DependencyObject dependencyObject)
        {
            viewModel.GetType().GetProperties().ToList().ForEach(
                property =>
            {
                try
                {
                    string propertyName = property.Name;

                    string dpName = property.Name + "Property";
                    PropertyInfo propertyViewModel = viewModel.GetType().GetProperty(propertyName);


                    Type typeDependObj = dependencyObject.GetType();



                    FieldInfo fieldDP = CUtilReflex.GetDependencyPropertyField(propertyName, typeDependObj);
                    if (fieldDP == null)
                    {
                        throw new ApplicationException("Field " + dpName + " not found in " + typeDependObj.Name);
                    }

                    DependencyProperty dp = (DependencyProperty)fieldDP.GetValue(dependencyObject);

                    /* Bind ViewModel property and DependencyProperty of Control.
                     * If ViewModel property is writable, use two way binding
                     *
                     */
                    CUtil.SetBinding(viewModel,
                                     propertyName,
                                     dependencyObject,
                                     dp,
                                     twoWayBinding: propertyViewModel.CanWrite);
                }
                catch (Exception e)
                {
                    CKernelTerminal.ErrorStatic("BindAllFromViewModel", e);
                }
            }
                );
        }
        private void TestPropertClassEqViewModel(Pair pair)
        {
            string partOfConfig = pair.ConfigItem;
            //string stType = "Terminal.Controls.Market.Contri";
            var propertiesViewModel = CUtilReflex.GetPropertiesList(_stMarketViewModelType);

            if (propertiesViewModel != null)
            {
                Thread.Sleep(0);
            }

            var propertiesConfig = CUtilReflex.GetPropertiesList(GetPropertyTypeSt(partOfConfig));

            propertiesConfig.ForEach(propertyConfig =>
            {
                if (propertiesViewModel.FirstOrDefault(a => a.Name == propertyConfig.Name) == null)
                {
                    Error(String.Format("ViewModel  doesn't contain property {0}", propertyConfig.Name));
                }
            }


                                     );
        }
Esempio n. 10
0
        private void CheckDelete(int stockExchId, List <TModelElement> inpList)
        {
            if (stockExchId == 0)
            {
                _client.Error("CBaseDataSyncher. CheckDelete. StockExchId == 0");
            }

            //Enumerate all elements in collectionVM. If element is not
            // exist in inpList (for the same StockExchId) do delete it from collectionVm
            for (int i = 0; i < _collectionVm.Count; i++)
            {
                List <PropertyInfo> destProperties = _collectionVm[i].GetType().GetProperties().ToList();
                PropertyInfo        dstPrpInf      = destProperties.Find(dstPrp => dstPrp.Name == KeysDependenciesTrdMgr.StockExchId);
                if ((int)dstPrpInf.GetValue(_collectionVm[i], null) != stockExchId)
                {
                    continue;
                }

                bool bFoundEqKeys = false;
                foreach (var modelElement in inpList)
                {
                    List <PropertyInfo> sourceProperties = modelElement.GetType().GetProperties().ToList();


                    int cntEqKeysFound = 0;

                    //bool bNotEqKeyFnd = false;



                    //compare properties of two current elements
                    foreach (var srcPropInfo in sourceProperties)
                    {
                        foreach (var dstPropInfo in destProperties)
                        {
                            if (_lstKeys.Contains(srcPropInfo.Name) &&
                                srcPropInfo.Name == dstPropInfo.Name)
                            {
                                if (CUtilReflex.IsEqualValues(srcPropInfo.GetValue(modelElement, null),
                                                              dstPropInfo.GetValue(_collectionVm[i], null)))
                                {
                                    cntEqKeysFound++;
                                    //all of  keys are matched
                                    if (cntEqKeysFound == _lstKeys.Count)
                                    {
                                        //keys found
                                        //no need to iterate more properties
                                        bFoundEqKeys = true;
                                    }
                                }
                            }
                        }
                        //keys found no need to iterate more
                        if (bFoundEqKeys)
                        {
                            break;
                        }
                    }
                }
                //we iterated all _lstModelElements and not found element from source
                //so we need to add element to _lstModelElemets
                if (!bFoundEqKeys)
                {
                    _collectionVm.RemoveAt(i);
                }
            }
        }
Esempio n. 11
0
        /// <summary>
        /// For each property in property list find property with such name in ViewModel. If value was set use it as initial
        /// values. Then in control class find  dependency property static field with name "PropertyName"Property  (also find in parent UserControl class).
        /// If all OK bind ViewModel property with UserControl dependency property
        /// </summary>
        /// <typeparam name="TypeOfViewModel"></typeparam>
        /// <param name="viewModel"></param>
        /// <param name="dependencyObject"></param>
        /// <param name="propertyList">List of strings. Name of fields are name of properties. Values (if it was set) are initial values of properties. </param>
        public static void BindFromList <TypeOfViewModel>(TypeOfViewModel viewModel, DependencyObject dependencyObject, object propertyList)
        {
            propertyList.GetType().GetProperties().ToList().ForEach(
                propertyConfig =>
            {
                try
                {
                    string propertyName = propertyConfig.Name;

                    var p = viewModel.GetType().GetProperty(propertyConfig.Name);

                    PropertyInfo propertyViewModel = viewModel.GetType().GetProperty(propertyName);

                    if (propertyViewModel == null)
                    {
                        string msg = propertyName + " not found in ViewModel";
                        CKernelTerminal.ErrorStatic(msg);
                        throw new ApplicationException(msg);
                    }



                    //if value was set in config file
                    //set the value to ViewModel property
                    var value = propertyConfig.GetValue(propertyList, null);
                    if (value != null)
                    {
                        //SetValue(marketViewModel, propertyViewModel, value);
                        CUtilReflex.SetPropertyValue(viewModel, propertyViewModel, value);
                    }

                    string dpName = propertyConfig.Name + "Property";
                    Type type     = dependencyObject.GetType();


                    FieldInfo fieldDP = CUtilReflex.GetDependencyPropertyField(propertyConfig.Name, type);
                    //if not found do find in base FrameWorokElement class
                    if (fieldDP == null)
                    {
                        Type typeFrameWorkElement = type.BaseType.BaseType.BaseType;
                        fieldDP = CUtilReflex.GetField(dpName, typeFrameWorkElement);
                    }



                    //dependency property field must be in Control
                    if (fieldDP != null)     //found
                    {
                        DependencyProperty dp = (DependencyProperty)fieldDP.GetValue(dependencyObject);

                        /* Bind ViewModel property and DependencyProperty of Control.
                         * If ViewModel property is writable, use two way binding
                         *
                         */
                        CUtil.SetBinding(viewModel,
                                         propertyName,
                                         dependencyObject,
                                         dp,
                                         twoWayBinding: propertyViewModel.CanWrite);
                    }
                    else     //filed == null , field not found, error
                    {
                        string msg = "field not found: " + dpName;
                        CKernelTerminal.ErrorStatic(msg);
                        throw new ApplicationException(msg);
                    }
                }
                catch (Exception e)
                {
                    CKernelTerminal.ErrorStatic("BindFromList error", e);
                }
            });
        }