public static Exception Create(RuleProperty prop, string errorCodeNumber, params object[] parameters) { if (prop != null) return new NumberedEndUserPropertyException(prop, errorCodeNumber, parameters); return NumberedEndUserException.Create(errorCodeNumber, parameters); }
private string GetPropertyValue(RuleProperty property, MailItem mail) { string strProp; switch (property) { case RuleProperty.SenderAddress: strProp = mail.Sender.Address; break; case RuleProperty.Body: strProp = mail.Body; break; case RuleProperty.Subject: strProp = mail.Subject; break; case RuleProperty.ToAddress: strProp = mail.To; break; case RuleProperty.CCAddress: strProp = mail.CC; break; default: strProp = ""; break; } return(strProp); }
internal void SetPropertyAndRuleProp(string propName, string propValue, RuleProperty prop) { var property = this.GetType().GetProperty(propName); var rulePropProperty = this.GetType().GetProperty(propName + "Prop"); property.SetValue(this, propValue, null); rulePropProperty.SetValue(this, prop, null); }
/// <summary> /// Replace a single macro with its value. /// </summary> /// <param name="name">the macro name. If the macro is in the code as "{$foo}", <paramref name="name"/> would be 'foo'.</param> /// <param name="value">the macros value.</param> /// <returns>the <see cref="PropertySheet"/> after this macro has been replaced.</returns> public PropertySheet ExpandAMacro(string name, string value) { var rp = new RuleProperty {Name = name, LValue = value}; if (_macros.ContainsKey(name)) throw new MacroAlreadyDefinedException(name, _macros[name].LValue, value); _macros[name] = rp; _macroFreeDeclares.Add(rp); MacroExpansion(); return _ps; }
/// <summary> /// Creates a rule definition. /// </summary> /// <param name="name">Rule's name.</param> /// <param name="description">Rule's description.</param> /// <param name="priority">Rule's priority.</param> /// <param name="tags">Tags associated with the rule.</param> /// <param name="leftHandSide">Rule's left-hand side top group element.</param> /// <param name="rightHandSide">Rule's right-hand side group element.</param> /// <returns>Created rule definition.</returns> public static IRuleDefinition RuleDefinition(string name, string description, int priority, IEnumerable <string> tags, GroupElement leftHandSide, ActionGroupElement rightHandSide) { var ruleProperties = new RuleProperty[0]; var dependencyGroupElement = DependencyGroup(); var filterGroupElement = FilterGroup(); var ruleDefinition = RuleDefinition(name, description, priority, RuleRepeatability.Repeatable, tags, ruleProperties, dependencyGroupElement, leftHandSide, filterGroupElement, rightHandSide); return(ruleDefinition); }
public IRuleCriteria CreateRule(RuleProperty property, RulePropertyCondition condition, string expectedText, RuleAction action) { T rule = new T(); //{ // rule.Property = property; // rule.Condition = condition; // rule.Validation = expectedText; // rule.ResultingAction = action; //} return(rule); }
internal void AddToPropertyListAndRuleProp(string propName, RuleProperty prop, IEnumerable<string> vals) { var property = this.GetType().GetProperty(propName); var valOfProp = (ICollection<string>)property.GetValue(this, null); foreach (var v in vals) { valOfProp.Add(v); } //property.SetValue(this, concatted, null); //get the hash var ruleprop = this.GetType().GetProperty(propName + "Prop"); var dictionary = (Dictionary<string, RuleProperty>)ruleprop.GetValue(this, null); foreach (var v in vals) { dictionary[v] = prop; } }
/// <summary> /// 验证模型 /// 包括Attribute规则和Fluent规则 /// </summary> /// <typeparam name="T">模型类型</typeparam> /// <param name="model">模型实例</param> /// <returns></returns> public static ValidResult ValidFor <T>(T model) { if (model == null) { return(ValidResult.False("模型不能为null ..")); } var context = new ValidContext(model, RuleProperty.GetGetProperties(typeof(T))); foreach (var property in context.Properties) { var failureRule = property.GetFailureRule(context); if (failureRule != null) { var message = failureRule.FormatErrorMessage(null); return(ValidResult.False(message, property.Info)); } } return(ValidResult.True()); }
/// <summary> /// Loads from json. /// </summary> /// <param name="jsonProperty">The json property.</param> /// <param name="service">The service.</param> internal override void LoadFromJson(JsonObject jsonProperty, ExchangeService service) { if (jsonProperty.ContainsKey(XmlElementNames.FieldURI)) { this.ruleProperty = jsonProperty.ReadEnumValue <RuleProperty>(XmlElementNames.FieldURI); } if (jsonProperty.ContainsKey(XmlElementNames.ErrorCode)) { this.errorCode = jsonProperty.ReadEnumValue <RuleErrorCode>(XmlElementNames.ErrorCode); } if (jsonProperty.ContainsKey(XmlElementNames.ErrorMessage)) { this.errorMessage = jsonProperty.ReadAsString(XmlElementNames.ErrorMessage); } if (jsonProperty.ContainsKey(XmlElementNames.FieldValue)) { this.value = jsonProperty.ReadAsString(XmlElementNames.FieldValue); } }
bool TryReadElementFromXml(EwsServiceXmlReader reader) { switch (reader.LocalName) { case XmlElementNames.FieldURI: this.ruleProperty = reader.ReadElementValue <RuleProperty>(); return(true); case XmlElementNames.ErrorCode: this.errorCode = reader.ReadElementValue <RuleErrorCode>(); return(true); case XmlElementNames.ErrorMessage: this.errorMessage = reader.ReadElementValue(); return(true); case XmlElementNames.FieldValue: this.value = reader.ReadElementValue(); return(true); default: return(false); } }
private IEnumerable<Exception> ParseIcon(RuleProperty icon) { var exceptions = new List<Exception>(); if (ValidVal(icon)) { try { var iconFile = File.ReadAllBytes(icon.LValue); if (!Validator.IsIconValid(iconFile)) { exceptions.Add( NumberedEndUserPropertyException.Create(icon, 106, icon.LValue, REQUIRED_ICON_WIDTH, REQUIRED_ICON_HEIGHT)); } else { _package.Icon = Convert.ToBase64String(iconFile); } } catch (IOException) { exceptions.Add(NumberedEndUserPropertyException.Create(icon, 107, icon.LValue)); } } else { _package.Icon = Convert.ToBase64String(Resources.blankicon); } return exceptions; }
private IEnumerable<Exception> ParsePublishDate(RuleProperty publishDate) { var exceptions = new List<Exception>(); if (ValidVal(publishDate)) { try { // ReSharper disable ReturnValueOfPureMethodIsNotUsed _package.PublishDate = DateTime.Parse(publishDate.LValue).ToShortDateString(); // ReSharper restore ReturnValueOfPureMethodIsNotUsed } catch (FormatException) { exceptions.Add(NumberedEndUserPropertyException.Create(publishDate, 130, publishDate.LValue)); } } else { _package.PublishDate = DateTime.Now.ToShortDateString(); } return exceptions; }
/// <summary> /// Adds rule's property. /// </summary> /// <param name="name">Property name.</param> /// <param name="value">Property value.</param> public void Property(string name, object value) { var property = new RuleProperty(name, value); _properties.Add(property); }
private void ReplaceMacrosInProp(RuleProperty rp) { if (rp.IsValue) rp.LValue = FindMacrosRegex.Replace(rp.LValue, (m) => { var orig = m.Groups["macro"].Value; if (_macros.ContainsKey(orig) && _macroFreeDeclares.Contains(_macros[orig])) { return _macros[orig].LValue; } return m.ToString(); }); else if (rp.IsCompoundProperty) rp.RValue = FindMacrosRegex.Replace(rp.RValue, (m) => { var orig = m.Groups["macro"].Value; if (_macros.ContainsKey(orig) && _macroFreeDeclares.Contains(_macros[orig])) { return _macros[orig].LValue; } return m.ToString(); }); else if (rp.IsCompoundCollection || rp.IsCollection) rp.Values = from val in rp.Values select FindMacrosRegex.Replace(val, (m) => { var orig = m.Groups["macro"].Value; if (_macros.ContainsKey(orig) && _macroFreeDeclares.Contains(_macros[orig])) { return _macros[orig].LValue; } return m.ToString(); }); }
private IEnumerable<Exception> ParseDescription(RuleProperty desc, bool shortDesc = false) { var output = new List<Exception>(); if (ValidVal(desc)) { try { if (shortDesc) _package.ShortDescription = File.ReadAllText(desc.LValue); else _package.Description = File.ReadAllText(desc.LValue); if (shortDesc && !Validator.IsShortDescriptionValid(_package.ShortDescriptionPath)) { output.Add(NumberedEndUserPropertyException.Create(desc, 108, desc.LValue, MAX_SUMMARY_DESCRIPTION_LENGTH)); } } catch (NotSupportedException) { int error = shortDesc ? 109 : 111; output.Add(NumberedEndUserPropertyException.Create(desc, error, desc.LValue)); } catch (IOException) { int error = shortDesc ? 110 : 112; output.Add(NumberedEndUserPropertyException.Create(desc, error, desc.LValue)); } } return output; }
private IEnumerable<Exception> ParseDisplayName(RuleProperty displayName) { if (ValidVal(displayName)) { _package.DisplayName = displayName.LValue; } yield break; }
private int GetNumOfMacrosInProp(RuleProperty prop) { return MacrosInString(prop.LValue).Where(_macros.ContainsKey).Uniq().Count; }
private NumberedEndUserPropertyException(RuleProperty prop, string errorCodeNumber, params object[] parameters) : base(prop,"AP " + errorCodeNumber, typeof(Resources).GetProperty("AP" + errorCodeNumber, BindingFlags.NonPublic | BindingFlags.Static).GetValue(null, null).ToString(), parameters) { }
public static Exception Create(RuleProperty prop, int errorCodeNumber, params object[] parameters) { return Create(prop, errorCodeNumber + "", parameters); }
private IEnumerable<Exception> ParseLocation(RuleProperty location) { if (ValidVal(location)) { if (!Validator.IsUrlValid(location.LValue)) { yield return NumberedEndUserPropertyException.Create(location, 118, location.LValue); } else { _package.FeedUrl = _package.CreateUrl(location.LValue, "original_location"); } } }
private IEnumerable<Exception> ParseBugTracker(RuleProperty bugtracker) { if (ValidVal(bugtracker)) { if (!Validator.IsUrlValid(bugtracker.LValue)) { yield return NumberedEndUserPropertyException.Create(bugtracker, 167, bugtracker.LValue); } else { _package.BugTrackerUrl = _package.CreateUrl(bugtracker.LValue, "bug_tracker"); } } }
private IEnumerable<Exception> ParseFeed(RuleProperty feed) { if (ValidVal(feed)) { if (!Validator.IsUrlValid(feed.LValue)) { yield return NumberedEndUserPropertyException.Create(feed, 118, feed.LValue); } else { _package.FeedUrl = _package.CreateUrl(feed.LValue, "feed_location"); } } }
private IEnumerable<Exception> SetName(RuleProperty possibleName) { if (!ValidVal(possibleName)) { yield return NumberedEndUserException.Create(100); } else { if (!Validator.IsPackageNameValid(possibleName.LValue)) { yield return NumberedEndUserPropertyException.Create(possibleName, 101, possibleName.LValue); } else { _package.PackageName = possibleName.LValue; } } }
private void SetToPackageIfValid(string packagePropName, RuleProperty r) { if (ValidVal(r)) { _package.SetPropertyAndRuleProp(packagePropName, r); } }
private static bool ValidVal(RuleProperty r) { return r != null && r.IsValue; }
private IEnumerable<Exception> SetVersionAndArch(Rule possibleFirstBinRule, RuleProperty versionRuleProp, RuleProperty archRuleProp) { var thereIsAssm = possibleFirstBinRule != null; var reader = new ArchAndVersionParser(thereIsAssm ? possibleFirstBinRule.Parameter : null); var thereIsVersionRule = ValidVal(versionRuleProp); _package.PackageVersion = reader.GetVersion(thereIsVersionRule ? versionRuleProp.LValue : null); if (_package.PackageVersion == null) { if (thereIsAssm) { yield return NumberedEndUserException.Create(105, possibleFirstBinRule.Parameter); } else { yield return NumberedEndUserPropertyException.Create(versionRuleProp, 102, versionRuleProp.LValue); } } var thereIsArchRule = ValidVal(archRuleProp); _package.PackageArch = reader.GetArch(thereIsArchRule ? archRuleProp.LValue : null); if (_package.PackageArch == null) { if (thereIsAssm) { yield return NumberedEndUserException.Create(104, possibleFirstBinRule.Parameter); } else { yield return NumberedEndUserPropertyException.Create(archRuleProp, 104, archRuleProp.LValue); } } }
/// <summary> /// Since prop.LValue is almost always this, we just assume it with this one /// </summary> /// <param name="propName"></param> /// <param name="prop"></param> internal void SetPropertyAndRuleProp(string propName, RuleProperty prop) { SetPropertyAndRuleProp(propName, prop.LValue, prop); }
private Exception CreateEndUserPropertyException(RuleProperty prop, int errorCodeNumber, params object[] parameters) { return CreateEndUserPropertyException(prop, errorCodeNumber + "", parameters); }
public void ruleProperty(IList list) { Object exp = null; bool tf = true; String ver = null; bool remember1 = true; bool temporal = false; bool agenda = false; String direction1 = null; String date = null; if (jj_2_14(2147483647)) { exp = salience(); } else { ; } if (exp != null) { Int64 intsal = Int64.Parse(((Token) exp).image); RuleProperty sal = new RuleProperty(RuleProperty.SALIENCE, (int) intsal); list.Add(sal); } if (jj_2_15(2147483647)) { tf = autoFocus(); } else { ; } RuleProperty auto = new RuleProperty(RuleProperty.AUTO_FOCUS, tf); list.Add(auto); if (jj_2_16(2147483647)) { ver = ruleVersion(); } else { ; } RuleProperty rp = new RuleProperty(RuleProperty.VERSION, ver); list.Add(rp); if (jj_2_17(2147483647)) { remember1 = remember(); } else { ; } RuleProperty rmem = new RuleProperty(RuleProperty.REMEMBER_MATCH, remember1); list.Add(rmem); if (jj_2_18(2147483647)) { date = effectiveDate(); } else { ; } RuleProperty eff = new RuleProperty(RuleProperty.EFFECTIVE_DATE, date); list.Add(eff); if (jj_2_19(2147483647)) { date = expirationDate(); } else { ; } RuleProperty expr = new RuleProperty(RuleProperty.EXPIRATION_DATE, date); list.Add(expr); if (jj_2_20(2147483647)) { direction1 = direction(); } else { ; } RuleProperty dir = new RuleProperty(RuleProperty.DIRECTION, direction1); list.Add(dir); if (jj_2_21(2147483647)) { agenda = noAgenda(); } else { ; } RuleProperty noagenda = new RuleProperty(RuleProperty.NO_AGENDA, agenda); list.Add(noagenda); if (jj_2_22(2147483647)) { temporal = temporalAct(); } else { ; } RuleProperty tempprop = new RuleProperty(RuleProperty.TEMPORAL_ACTIVATION, temporal); list.Add(tempprop); }
private Exception CreateEndUserPropertyException(RuleProperty prop, string errorCodeNumber, params object[] parameters) { if (prop != null) return new EndUserPropertyException(prop, "AP " + errorCodeNumber, typeof(Resources).GetProperty("AP" + errorCodeNumber, BindingFlags.NonPublic | BindingFlags.Static).GetValue(null, null).ToString(), parameters); return CreateEndUserException(errorCodeNumber, parameters); }
/// <summary> /// Tries to read element from XML. /// </summary> /// <param name="reader">The reader.</param> /// <returns>True if element was read.</returns> internal override bool TryReadElementFromXml(EwsServiceXmlReader reader) { switch (reader.LocalName) { case XmlElementNames.FieldURI: this.ruleProperty = reader.ReadElementValue<RuleProperty>(); return true; case XmlElementNames.ErrorCode: this.errorCode = reader.ReadElementValue<RuleErrorCode>(); return true; case XmlElementNames.ErrorMessage: this.errorMessage = reader.ReadElementValue(); return true; case XmlElementNames.FieldValue: this.value = reader.ReadElementValue(); return true; default: return false; } }
private IEnumerable<Exception> ParseAuthorVersion(RuleProperty authorVersion) { if (ValidVal(authorVersion)) { _package.AuthorVersion = authorVersion.LValue; } yield break; }