/// <summary> /// Check to see if the add list of the action can potentially be used to fulfill a goal /// </summary> /// <param name="goal">The goal to be fulfilled</param> /// <param name="currentBeliefs">The current beliefs that we have at the moment</param> /// <returns>Returns a fact that can be found in the add list that has the same name as the end goal/fact in the goal /// and where an assignment can be found that fulfills the goal and does not violate the constraints of the action.</returns> internal virtual Fact IsApplicableForAdd(SimpleGoal goal, List <Fact> currentBeliefs) { //only facts that have the same name as the goal are considered but also only those that are more general (or equally general) than the goal //this means that a substitution (or empty substitution) exists that transforms the fact of the addlist into the fact of the goal var possibeAdds = AddList.Where(y => y.Name.Equals(goal.Fact.Name) && y.IsMoreGeneralThanOrEqualTo(goal.Fact)); //if no such facts can be found, quickly return null if (!possibeAdds.Any()) { return(null); } //if there are no constraints, quickly return the first fact that can fulfill the goal if (!Constraints.Any()) { return(possibeAdds.FirstOrDefault()); } //return the first fact of the possible facts of the addlist where an assignment can be found that also //does not violate the constraints of the action foreach (var possibleGoal in possibeAdds) { var tuples = GetAssignment(possibleGoal, goal, currentBeliefs); if (CheckConstraints(tuples)) { return(possibleGoal); } } return(null); }
public override RouteData GetRouteData(HttpContextBase httpContext) { if (httpContext == null) { throw new ArgumentNullException("httpContext"); } var url = httpContext.Request.AppRelativeCurrentExecutionFilePath.Substring(1) + httpContext.Request.PathInfo; var match = m_Pattern.Match(url); if (match.Success) { var data = new RouteData(this, RouteHandler); foreach (string groupName in m_Pattern.GetGroupNames()) { if (!data.Values.ContainsKey(groupName)) { Group group = match.Groups[groupName]; if ((group != null) && group.Success) { data.Values.Add(groupName, group.Value); } } } if (Constraints != null) { if (Constraints.Any(pair => !ProcessConstraint(httpContext, pair.Value, pair.Key, data.Values, RouteDirection.IncomingRequest))) { return(null); } } foreach (KeyValuePair <string, object> pair in Defaults) { if (!data.Values.ContainsKey(pair.Key)) { data.Values.Add(pair.Key, pair.Value); } } if (DataTokens != null) { foreach (KeyValuePair <string, object> pair in DataTokens) { data.DataTokens[pair.Key] = pair.Value; } } return(data); } return(null); }
private bool MatchTypeMapping(string parameterName, string typeFullName, TypeMapping typeMapping) { parameterName = parameterName ?? Parameter.Name; var doesTypeNameMatch = typeFullName.StartsWith(typeMapping.WebApiTypeName); var doesAttributeMatch = typeMapping.TreatAsAttribute && Helpers.HasCustomAttribute(Parameter, $"{typeMapping.WebApiTypeName}Attribute"); var doesConstraintMatch = typeMapping.TreatAsConstraint && Constraints.Any(c => c == Helpers.ToCamelCaseFromPascalCase(typeMapping.WebApiTypeName)); var typeMatches = doesTypeNameMatch || doesAttributeMatch || doesConstraintMatch; var matchExists = !string.IsNullOrEmpty(typeMapping.Match); var doesPatternMatch = matchExists && new Regex(typeMapping.Match).IsMatch(parameterName); return((typeMatches && !matchExists) || (typeMatches && doesPatternMatch)); }
public bool ContainsConstraint(string name) => Constraints.Any(constraint => constraint.Name.Equals(name));
public override string ToString() { var sb = new StringBuilder(string.Format("; {0}\n\n(import (rnrs) (emodl cmslib))\n\n(start-model \"{0}\")\n\n", Name)); if (Constraints.Any()) { foreach (var constraint in Constraints) { sb.AppendLine(constraint.ToString()); } sb.AppendLine(); } if (ScheduledEvents.Any()) { foreach (var evt in ScheduledEvents) { sb.AppendLine(evt.ToString()); } sb.AppendLine(); } if (TriggeredEvents.Any()) { foreach (var evt in TriggeredEvents) { sb.AppendLine(evt.ToString()); } sb.AppendLine(); } var expressions = Expressions.Where(e => (e.Name != null && e.Name != "rand")); if (expressions.Any()) { foreach (var expression in expressions) { sb.AppendLine(expression.ToString()); } sb.AppendLine(); } if (Observables.Any()) { foreach (var observable in Observables) { sb.AppendLine(observable.ToString()); } sb.AppendLine(); } var parameters = Parameters.Where(p => (p.Name != "time" && p.Name != "pi")); if (parameters.Any()) { foreach (var parameter in parameters) { sb.AppendLine(parameter.ToString()); } sb.AppendLine(); } var predicates = Predicates.Where(p => p.Name != null); if (predicates.Any()) { foreach (var predicate in predicates) { sb.AppendLine(predicate.ToString()); } sb.AppendLine(); } foreach (var locale in Locales) { if (locale.Name != "global") { sb.AppendLine(locale.ToString()); sb.AppendLine(string.Format("(set-locale {0})\n", locale.Name)); } var currentLocale = locale; foreach (var species in Species.Where(s => s.Locale == currentLocale)) { sb.AppendLine(species.ToString()); } sb.AppendLine(); } if (Reactions.Any()) { foreach (var reaction in Reactions) { sb.AppendLine(reaction.ToString()); } sb.AppendLine(); } sb.Append("(end-model)"); return(sb.ToString()); }
/// <summary> /// Devuelve el schema de la tabla en formato SQL. /// </summary> public string ToSql(Boolean showFK) { Database database = null; ISchemaBase current = this; while (database == null && current.Parent != null) { database = current.Parent as Database; current = current.Parent; } if (database == null) { return(string.Empty); } var isAzure10 = database.Info.Version == DatabaseInfo.VersionTypeEnum.SQLServerAzure10; string sql = ""; string sqlPK = ""; string sqlUC = ""; string sqlFK = ""; if (Columns.Any()) { sql += "CREATE TABLE " + FullName + "\r\n(\r\n"; sql += Columns.ToSql(); if (Constraints.Any()) { sql += ",\r\n"; Constraints.AsQueryable() // Add the constraint if it's not in DropStatus .Where(c => !c.HasState(ObjectStatus.Drop)) .ToList() .ForEach(item => { if (item.Type == Constraint.ConstraintType.PrimaryKey) { sqlPK += "\t" + item.ToSql() + ",\r\n"; } if (item.Type == Constraint.ConstraintType.Unique) { sqlUC += "\t" + item.ToSql() + ",\r\n"; } if (showFK && item.Type == Constraint.ConstraintType.ForeignKey) { sqlFK += "\t" + item.ToSql() + ",\r\n"; } }); sql += sqlPK + sqlUC + sqlFK; sql = sql.Substring(0, sql.Length - 3) + "\r\n"; } else { sql += "\r\n"; if (!String.IsNullOrEmpty(CompressType)) { sql += "WITH (DATA_COMPRESSION = " + CompressType + ")\r\n"; } } sql += ")"; if (!isAzure10) { if (!String.IsNullOrEmpty(FileGroup)) { sql += " ON [" + FileGroup + "]"; } if (!String.IsNullOrEmpty(FileGroupText)) { if (HasBlobColumn) { sql += " TEXTIMAGE_ON [" + FileGroupText + "]"; } } if ((!String.IsNullOrEmpty(FileGroupStream)) && (HasFileStream)) { sql += " FILESTREAM_ON [" + FileGroupStream + "]"; } } sql += "\r\n"; sql += "GO\r\n"; Constraints.ForEach(item => { if (item.Type == Constraint.ConstraintType.Check) { sql += item.ToSqlAdd() + "\r\n"; } }); if (HasChangeTracking) { sql += ToSqlChangeTracking(); } sql += Indexes.ToSql(); sql += FullTextIndex.ToSql(); sql += Options.ToSql(); sql += Triggers.ToSql(); } return(sql); }
public override bool Match(object @object) { return(Constraints.Any(constraint => ((IInternalConstraint)constraint).Match(@object))); }