public static string Condition2Text(IResource condition) { string result; ConditionOp op = (ConditionOp)condition.GetIntProp("ConditionOp"); if (op == ConditionOp.InRange) { result = "larger than " + condition.GetStringProp("ConditionValLower") + " and smaller than " + condition.GetStringProp("ConditionValUpper"); } else if (op == ConditionOp.Gt) { result = "larger than " + condition.GetStringProp("ConditionVal"); } else if (op == ConditionOp.Lt) { result = "smaller than " + condition.GetStringProp("ConditionVal"); } else { throw new InvalidOperationException("Can not parse operation for an interval condition"); } return(result); }
public static IResource Template2Action(IResource template, object param, string representation) { if (template.Type != FilterManagerProps.RuleActionTemplateResName) { throw new ArgumentException("FilterRegistry -- Invalid type of parameter - RuleActionTemplate is expected"); } IResource action; ConditionOp op = (ConditionOp)template.GetProp("ConditionOp"); if (op == ConditionOp.In) { if (param is IResourceList) { action = FilterRegistry.RegisterRuleActionProxy(template, (IResourceList)param); } else if (param is string) { action = FilterRegistry.RegisterRuleActionProxy(template, (string)param); } else { throw new ArgumentException("Illegal parameter type for the operation - string or Resource List expected"); } } else if (op == ConditionOp.Eq) { if (param is string) { action = FilterRegistry.RegisterRuleActionProxy(template, (string)param); } else { throw new ArgumentException("Illegal parameter type for the operation - string expected"); } } else { throw new InvalidOperationException("Not all Operations are supported now"); } if (!String.IsNullOrEmpty(representation)) { new ResourceProxy(action).SetProp("SurfaceConditionVal", representation); } return(action); }
public static string Condition2Text(IResource condition) { Debug.Assert(ResourceTypeHelper.IsDateProperty(condition.GetStringProp("ApplicableToProp")), "Can not apply IResource->string transformation to inappropriate condition"); string description; ConditionOp op = (ConditionOp)condition.GetIntProp("ConditionOp"); if (op == ConditionOp.Lt) { description = "before " + condition.GetStringProp("ConditionVal"); } else if (op == ConditionOp.Gt) { description = "after " + condition.GetStringProp("ConditionVal"); } else if (op == ConditionOp.Eq) { description = condition.GetStringProp("ConditionVal"); } else if (op == ConditionOp.InRange) { string srcLower = condition.GetStringProp("ConditionValLower"), srcUpper = condition.GetStringProp("ConditionValUpper"); string lower = srcLower.ToLower(), upper = srcUpper.ToLower(); if ((lower == "tomorrow") && (upper == "1" || upper == "+1")) { description = "Tomorrow"; } else if ((lower == "yesterday") && (upper == "today" || upper == "1" || upper == "+1")) { description = "Yesterday"; } else if ((lower == "weekstart") && (upper == "7" || upper == "+7")) { description = "This week"; } else if ((lower == "weekstart") && (upper == "-7")) { description = "Last week"; } else if ((lower == "nextweekstart") && (upper == "+7")) { description = "Next week"; } else if ((lower == "monthstart") && (upper == "30" || upper == "31" || upper == "+30" || upper == "+31")) { description = "This month"; } else if ((lower == "monthstart") && (upper == "-30")) { description = "Last month"; } else if (lower == "today" && (upper == "1" || upper == "+1")) { description = "Today"; } else if (lower == "tomorrow") { if (upper == "1" || upper == "+1") { description = "Today"; } else { string unit = "days"; char charUnit = upper[upper.Length - 1]; if (Char.IsLetter(charUnit)) { if (charUnit == 'h') { unit = "hours"; } else if (charUnit == 'd') { unit = "days"; } else if (charUnit == 'w') { unit = "weeks"; } else if (charUnit == 'm') { unit = "months"; } else if (charUnit == 'y') { unit = "years"; } upper = upper.Remove(upper.Length - 1, 1); } if (upper[0] == '-') { upper = upper.Remove(0, 1); } description = "last " + upper + " " + unit; } } else { description = "before " + srcLower + " and after " + srcUpper; } } else { throw new Exception("Unexpecter type of operation in back parsing of condition into string"); } return(description); }
public static IResource InstantiateTemplate(IResource template, object param, string representation, string[] resTypes) { #region Preconditions if (template.Type != FilterManagerProps.ConditionTemplateResName) { throw new InvalidOperationException("Input parameter must be of ConditionTemplate resource type"); } #endregion Preconditions string propName = template.GetStringProp("ApplicableToProp"); ConditionOp op = (ConditionOp)template.GetProp("ConditionOp"); //----------------------------------------------------------------- IResource condition; if (op == ConditionOp.Eq && ResourceTypeHelper.IsDateProperty(propName)) { condition = TimeSpan2Condition((string)param, propName, resTypes); } else if (op == ConditionOp.QueryMatch) { string sectionName = null; if (template.HasProp("SectionOrder")) { sectionName = DocSectionHelper.FullNameByOrder((uint)template.GetIntProp("SectionOrder")); } condition = fMgr.CreateQueryConditionAux(resTypes, (string)param, sectionName); } else if (op == ConditionOp.Eq || op == ConditionOp.Has) { condition = fMgr.CreateStandardConditionAux(resTypes, propName, op, (string)param); } else if (op == ConditionOp.In) { condition = fMgr.CreateStandardConditionAux(resTypes, propName, op, (IResourceList)param); } else if (op == ConditionOp.InRange) { condition = IntRange2Condition((string)param, propName); } else { throw new InvalidOperationException("Not all Operations are supported now"); } FilterRegistry.ReferCondition2Template(condition, template); //----------------------------------------------------------------- // Do not forget to set additional parameters from the template // and representation, e.g. if the template has "custom" style, // propagate it to the aux condition. //----------------------------------------------------------------- ResourceProxy proxy = new ResourceProxy(condition); proxy.BeginUpdate(); if (template.GetStringProp("ConditionType") == "custom") { proxy.SetProp("ConditionType", "custom"); } if (!String.IsNullOrEmpty(representation)) { proxy.SetProp("SurfaceConditionVal", representation); } proxy.EndUpdate(); return(condition); }
public static ConditionOpObj Find(ConditionOp symbol) { return(Operators.FirstOrDefault(op => op.Symbol == symbol)); }