示例#1
0
        public bool ConditionMet(IDataModel subject)
        {
            if (string.IsNullOrEmpty(Field) || string.IsNullOrEmpty(Value) || string.IsNullOrEmpty(Type))
                return false;

            var inspect = GeneralHelpers.GetPropertyValue(subject, Field);
            if (inspect == null)
                return false;

            // Put the subject in a list, allowing Dynamic Linq to be used.
            if (Type == "String")
            {
                return _interpreter.Eval<bool>($"subject.{Field}.ToLower(){Operator}(value)",
                    new Parameter("subject", subject.GetType(), subject),
                    new Parameter("value", Value.ToLower()));
            }

            Parameter rightParam = null;
            switch (Type)
            {
                case "Enum":
                    var enumType = GeneralHelpers.GetPropertyValue(subject, Field).GetType();
                    rightParam = new Parameter("value", Enum.Parse(enumType, Value));
                    break;
                case "Boolean":
                    rightParam = new Parameter("value", bool.Parse(Value));
                    break;
                case "Int32":
                    rightParam = new Parameter("value", int.Parse(Value));
                    break;
            }

            return _interpreter.Eval<bool>($"subject.{Field} {Operator} value",
                new Parameter("subject", subject.GetType(), subject), rightParam);
        }
示例#2
0
        public static List <ItemViewModel> ConstructTreeFromDataModel(IDataModel itemDataModel)
        {
            RootViewModel.Root = null;
            Type type = itemDataModel.GetType();

            if (type == typeof(TestPlan))
            {
                RootViewModel.Root = new TestPlanViewModel((TestPlan)itemDataModel);
            }
            else if (type == typeof(TestSuite))
            {
                RootViewModel.Root = new TestSuiteViewModel((TestSuite)itemDataModel);
            }

            if (RootViewModel.Root != null)
            {
                RootViewModel.Root.initialize();
                RootViewModel.Root.IsInitiallySelected = true;
                RootViewModel.Root.IsChecked           = new bool?(true);
            }

            return(new List <ItemViewModel>
            {
                RootViewModel.Root
            });
        }
示例#3
0
		public IEnumerable<IView> LocateViews(IDataModel model) {
			var modelType = model.GetType();
			foreach (var viewType in viewMap) {
				if (!viewType.Key.IsAssignableFrom(modelType))
					continue;
				foreach (var view in viewType.Value)
					yield return view;
			}
		}
示例#4
0
        public bool ConditionMet(IDataModel subject)
        {
            if (string.IsNullOrEmpty(Field) || string.IsNullOrEmpty(Value) || string.IsNullOrEmpty(Type))
            {
                return(false);
            }

            var inspect = GeneralHelpers.GetPropertyValue(subject, Field);

            if (inspect == null)
            {
                return(false);
            }

            // Put the subject in a list, allowing Dynamic Linq to be used.
            if (Type == "String")
            {
                return(_interpreter.Eval <bool>($"subject.{Field}.ToLower(){Operator}(value)",
                                                new Parameter("subject", subject.GetType(), subject),
                                                new Parameter("value", Value.ToLower())));
            }

            Parameter rightParam = null;

            switch (Type)
            {
            case "Enum":
                var enumType = GeneralHelpers.GetPropertyValue(subject, Field).GetType();
                rightParam = new Parameter("value", Enum.Parse(enumType, Value));
                break;

            case "Boolean":
                rightParam = new Parameter("value", bool.Parse(Value));
                break;

            case "Int32":
                rightParam = new Parameter("value", int.Parse(Value));
                break;
            }

            return(_interpreter.Eval <bool>($"subject.{Field} {Operator} value",
                                            new Parameter("subject", subject.GetType(), subject), rightParam));
        }
示例#5
0
        public IEnumerable <IView> LocateViews(IDataModel model)
        {
            var modelType = model.GetType();

            foreach (var viewType in viewMap)
            {
                if (!viewType.Key.IsAssignableFrom(modelType))
                {
                    continue;
                }
                foreach (var view in viewType.Value)
                {
                    yield return(view);
                }
            }
        }
示例#6
0
        public static bool UpdateToDb(this IDataModel obj)
        {
            try
            {
                using (var helper = new AccessDbHelper())
                {
                    string updateParams = GetUpdateString(obj);
                    helper.ExecuteSQLNonQuery(string.Format("UPDATE [{0}] SET {1}", obj.GetType().Name, updateParams));
                }
                return(true);
            }
            catch (Exception ex)
            {
                ApplicationContext.Current.Logger.Error("DeleteFromDb failed.", ex);
            }

            return(false);
        }
示例#7
0
        public static bool SaveToDb(this IDataModel obj)
        {
            try
            {
                using (var helper = new AccessDbHelper())
                {
                    string insertParams = GetInsertString(obj);
                    helper.ExecuteSQLNonQuery(string.Format("INSERT INTO [{0}] {1}", obj.GetType().Name, insertParams));
                }
                return(true);
            }
            catch (Exception ex)
            {
                ApplicationContext.Current.Logger.Error("DeleteFromDb failed.", ex);
            }

            return(false);
        }
示例#8
0
        public static bool DeleteFromDb(this IDataModel obj)
        {
            try
            {
                using (AccessDbHelper helper = new AccessDbHelper())
                {
                    helper.ExecuteSQLNonQuery(string.Format("UPDATE [{0}] SET ISDELETED =1 WHERE ID={1}", obj.GetType().Name, ((IDataModel)obj).Id));
                }
                return(true);
            }
            catch (Exception ex)
            {
                ApplicationContext.Current.Logger.Error("DeleteFromDb failed.", ex);
            }

            return(false);
        }