public static Result <DateTime, Error> IsOutOfSQLDateRange(this IGuard guard, DateTime input, string parameter, DateTime rangeFrom, DateTime rangeTo) { const long sqlMinDateTicks = 552877920000000000; const long sqlMaxDateTicks = 3155378975999970000; return(IsOutOfRange <DateTime>(input, parameter, new DateTime(sqlMinDateTicks), new DateTime(sqlMaxDateTicks))); }
/*******************************************************************************************/ #region extract guard condition from KP rule for standard variables public static ICondition extractGuardConditionFromKPRule(KpCore.Rule rule) { IGuard guard = rule.Guard; ICondition condition = extractGuardConditionFromKpGuard(guard); return(condition); }
private static ICondition extractConditionFromKpGuard(Module sourceModule, IGuard guard) { ICondition condition = null; if (guard is BasicGuard) { BasicGuard basicGuard = (BasicGuard)guard; condition = getBoolExpression(sourceModule, basicGuard); } else if (guard is NegatedGuard) { NegatedGuard negatedGuard = (NegatedGuard)guard; Console.Error.WriteLine("NegatedGuard is not applicable."); // ICondition negatedBooleanExpression = getNegatedGuard(negatedGuard); } else if (guard is CompoundGuard) { CompoundGuard compoundGuard = (CompoundGuard)guard; CompoundBoolExpression compoundBoolExpr = null; compoundBoolExpr.LeftCondition = extractConditionFromKpGuard(sourceModule, compoundGuard.Lhs); compoundBoolExpr.BinaryOperator = SMVUtil.getBinaryOperator(compoundGuard.Operator); compoundBoolExpr.RightCondition = extractConditionFromKpGuard(sourceModule, compoundGuard.Rhs); condition = compoundBoolExpr; } return(condition); }
public IResult CheckLeaveDirection(IMobileObject mobileObject, Direction direction) { //check if there is a guard in the room blocking the direction the mob is trying to leave IRoom room = mobileObject.Room; foreach (INonPlayerCharacter npc in room.NonPlayerCharacters) { if (npc.Personalities.Count > 0) { foreach (IPersonality personality in npc.Personalities) { IGuard guard = personality as IGuard; if (guard != null) { if (guard.GuardDirections.Contains(direction)) { return(new Result(guard.BlockLeaveMessage, true)); } } } } } return(null); }
private static ICondition extractGuardConditionFromKpGuard(IGuard guard) { ICondition condition = null; if (guard is BasicGuard) { BasicGuard basicGuard = (BasicGuard)guard; condition = getBoolExpression(basicGuard); } else if (guard is NegatedGuard) { NegatedGuard negatedGuard = (NegatedGuard)guard; Console.Error.WriteLine("KP NegatedGuard to SMV translation has not been implemented yet!"); } else if (guard is CompoundGuard) { CompoundGuard compoundGuard = (CompoundGuard)guard; CompoundBoolExpression compoundBoolExpr = new CompoundBoolExpression(); compoundBoolExpr.LeftCondition = extractGuardConditionFromKpGuard(compoundGuard.Lhs); compoundBoolExpr.BinaryOperator = SMVUtil.getBinaryOperator(compoundGuard.Operator); compoundBoolExpr.RightCondition = extractGuardConditionFromKpGuard(compoundGuard.Rhs); condition = compoundBoolExpr; } return(condition); }
public RenameService(IErrorDialogService errorDialogService, IGuard guard, IRenamerFactory renamerFactory, ILocalizationService localizationService, IProjectService projectService) { this.errorDialogService = errorDialogService; this.guard = guard; this.renamerFactory = renamerFactory; this.localizationService = localizationService; this.projectService = projectService; }
/// <summary> /// Throws an <see cref="ArgumentOutOfRangeException" /> if <paramref name="guardClause.Value" /> is not in the range of valid SqlDateTime values. /// </summary> /// <param name="guardClause"></param> /// <param name="parameterName"></param> /// <returns><paramref name="guardClause" /> if the value is in the range of valid SqlDateTime values.</returns> /// <exception cref="ArgumentOutOfRangeException"></exception> public static IGuard <DateTime> AgainstOutOfSQLDateRange([NotNull, JetBrainsNotNull] this IGuard <DateTime> guardClause, [NotNull, JetBrainsNotNull] string parameterName) { // System.Data is unavailable in .NET Standard so we can't use SqlDateTime. const long SqlMinDateTicks = 552877920000000000; const long SqlMaxDateTicks = 3155378975999970000; return(AgainstOutOfRange <DateTime>(guardClause, parameterName, new DateTime(SqlMinDateTicks), new DateTime(SqlMaxDateTicks))); }
public static string NotNullOrEmpty(this IGuard _, string value, string parameterName, string?message = null) { if (value.IsNullOrWhiteSpace()) { throw new BusinessException(message ?? $"{nameof(parameterName)}不能是空"); } return(value); }
public static Result <T, Error> IsOutOfRange <T>(this IGuard guard, T input, string parameter) where T : struct, Enum { if (Enum.IsDefined(typeof(T), input)) { return(new Success <T, Error>(input)); } return(new Failure <T, Error>(new ValidationError(422, $"Required input {parameter} was not a valid enum value for {typeof(T)}."))); }
void Start() { movement = GetComponent <Movement>(); attack = GetComponent <IAttack>(); guard = GetComponent <IGuard>(); player = PlayerCharacter.Instance; DOVirtual.DelayedCall(0.5f, () => StartCoroutine(LoopOnce())); playerPosDelayed = player.transform.position; }
public static T NotNullOrAny <T>(this IGuard _, T value, string parameterName, string?message = null) where T : ICollection { if (value is null || value.Count < 1) { throw new BusinessException(message ?? $"{nameof(parameterName)}不能是空"); } return(value); }
public static IGuard <string> AgainstFoo(this IGuard <string> guardClause, string parameterName) { if (guardClause.Value?.ToLower() == "foo") { throw new ArgumentException("Should not have been foo!", parameterName); } return(guardClause); }
public static Result <T, Error> IsDefault <T>(this IGuard guard, [AllowNull, NotNull] T input, string parameter) { if (EqualityComparer <T> .Default.Equals(input, default(T) !)) { return(new Failure <T, Error>(new ValidationError(422, $"Input [{parameter}] is default value for type {typeof(T).Name}"))); } return(new Success <T, Error>(input)); }
public static void ThrowIf(this IGuard _, Func <bool> predicate, string message) { var result = predicate.Invoke(); if (result) { throw new BusinessException(message); } }
/// <summary> /// Throws an <see cref="ArgumentException" /> if <paramref name="guardClause.Value" /> is default for that type. /// </summary> /// <param name="guardClause"></param> /// <param name="parameterName"></param> /// <returns><paramref name="guardClause" /> if the value is not default for that type.</returns> /// <exception cref="ArgumentException"></exception> public static IGuard <T> AgainstDefault <T>([NotNull, JetBrainsNotNull] this IGuard <T> guardClause, [NotNull, JetBrainsNotNull] string parameterName) { if (EqualityComparer <T> .Default.Equals(guardClause.Value, default)) { throw new ArgumentException($"Parameter [{parameterName}] is default value for type {typeof(T).Name}", parameterName); } return(guardClause); }
/// <summary> /// Throws an <see cref="ArgumentOutOfRangeException" /> if <paramref name="guardClause.Value"/> is not a valid enum value. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="guardClause"></param> /// <param name="parameterName"></param> /// <returns><paramref name="guardClause" /> if the value is not out of range.</returns> /// <exception cref="ArgumentOutOfRangeException"></exception> public static IGuard <T> AgainstOutOfRange <T>([NotNull, JetBrainsNotNull] this IGuard <T> guardClause, [NotNull, JetBrainsNotNull] string parameterName) where T : struct, Enum { if (!Enum.IsDefined(typeof(T), guardClause.Value)) { throw new ArgumentOutOfRangeException(parameterName, $"Required input {parameterName} was not a valid enum value for {typeof(T)}."); } return(guardClause); }
/// <summary> /// Adds a guard implementation. Commands that share a guard cannot execute concurrently.<br/> /// Commands can be given multiple guard implementations, though individual guard implementations /// can only be added once<br/> /// *CAUTION* Watch out for deadlock if you use the same Guard across multiple Pages.<br/> /// Recommendation: Implement IGuard in your ViewModel base class, e.g. by delegating to an instance of BasicGuard, so you can use the ViewModel as your Guard.<br/> /// </summary> /// <param name="guard">A guard implementation to add to the Command being built</param> /// <returns></returns> public CommandBuilder AddGuard(IGuard guard) { if (_guardList.Contains(guard)) { throw new ArgumentException("Cannot add the same guard to the same command twice"); } _guardList.Add(guard); return(this); }
/// <summary> /// Throws an <see cref="ArgumentException" /> if <paramref name="guardClause.Value" /> is Zero. /// </summary> /// <param name="guardClause"></param> /// <param name="parameterName"></param> /// <returns><paramref name="guardClause" /> if the value is not Zero.</returns> /// <exception cref="ArgumentException"></exception> private static IGuard <T> AgainstZero <T>([NotNull, JetBrainsNotNull] this IGuard <T> guardClause, [NotNull, JetBrainsNotNull] string parameterName) where T : struct { if (EqualityComparer <T> .Default.Equals(guardClause.Value, default)) { throw new ArgumentException($"Required input {parameterName} cannot be Zero.", parameterName); } return(guardClause); }
/// <summary> /// Throws an <see cref="ArgumentException"/> if <paramref name="guardClause.Value"/> is Negative or Zero. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="guardClause"></param> /// <param name="parameterName"></param> /// <returns><paramref name="guardClause" /> if the value is not Negative or Zero.</returns> private static IGuard <T> AgainstNegativeOrZero <T>([NotNull, JetBrainsNotNull] this IGuard <T> guardClause, [NotNull, JetBrainsNotNull] string parameterName) where T : struct, IComparable { if (guardClause.Value.CompareTo(default(T)) <= 0) { throw new ArgumentException($"Required input {parameterName} cannot be Zero or Negative.", parameterName); } return(guardClause); }
/// <summary> /// Throws an <see cref="ArgumentNullException" /> if <paramref name="guardClause.Value" /> is null. /// </summary> /// <param name="guardClause"></param> /// <param name="parameterName"></param> /// <returns><paramref name="guardClause" /> if the value is not null.</returns> /// <exception cref="ArgumentNullException"></exception> public static IGuard <T> AgainstNull <T>([NotNull, JetBrainsNotNull] this IGuard <T> guardClause, [NotNull, JetBrainsNotNull] string parameterName) { if (guardClause.Value is null) { throw new ArgumentNullException(parameterName); } return(guardClause); }
/// <summary> /// Throws an <see cref="ArgumentException" /> if <paramref name="guardClause.Value" /> is an empty guid. /// </summary> /// <param name="guardClause"></param> /// <param name="parameterName"></param> /// <returns><paramref name="guardClause" /> if the value is not an empty guid or null.</returns> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentException"></exception> public static IGuard <Guid> AgainstEmpty([NotNull, JetBrainsNotNull] this IGuard <Guid> guardClause, [NotNull, JetBrainsNotNull] string parameterName) { if (guardClause.Value == Guid.Empty) { throw new ArgumentException($"Required input {parameterName} was empty.", parameterName); } return(guardClause); }
public static T NotNull <T>(this IGuard _, T value, [NotNull] string parameterName, string?message = null) where T : class { if (value is null) { throw new BusinessException(message ?? $"{nameof(parameterName)}不能是空"); } return(value); }
/// <summary> /// Throws an <see cref="ArgumentNullException" /> if <paramref name="guardClause.Value" /> is null. /// Throws an <see cref="ArgumentException" /> if <paramref name="guardClause.Value" /> is an empty or white space string. /// </summary> /// <param name="guardClause"></param> /// <param name="parameterName"></param> /// <returns><paramref name="guardClause" /> if the value is not an empty or whitespace string.</returns> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentException"></exception> public static IGuard <string> AgainstNullOrWhiteSpace([NotNull, JetBrainsNotNull] this IGuard <string> guardClause, [NotNull, JetBrainsNotNull] string parameterName) { guardClause.AgainstNullOrEmpty(parameterName); if (string.IsNullOrWhiteSpace(guardClause.Value)) { throw new ArgumentException($"Required input {parameterName} was empty.", parameterName); } return(guardClause); }
/// <summary> /// Throws an <see cref="ArgumentNullException" /> if <paramref name="guardClause.Value" /> is null. /// Throws an <see cref="ArgumentException" /> if <paramref name="guardClause.Value" /> is an empty enumerable. /// </summary> /// <param name="guardClause"></param> /// <param name="parameterName"></param> /// <returns><paramref name="guardClause" /> if the value is not an empty enumerable or null.</returns> /// <exception cref="ArgumentNullException"></exception> /// <exception cref="ArgumentException"></exception> public static IGuard <IEnumerable <T> > AgainstNullOrEmpty <T>([NotNull, JetBrainsNotNull] this IGuard <IEnumerable <T> > guardClause, [NotNull, JetBrainsNotNull] string parameterName) { guardClause.AgainstNull(parameterName); if (!guardClause.Value.Any()) { throw new ArgumentException($"Required input {parameterName} was empty.", parameterName); } return(guardClause); }
public static Result <IEnumerable <T>, Error> IsNullOrEmpty <T>(this IGuard guard, IEnumerable <T> input, string parameter) { var _ = IsNull(input, parameter); if (_ is Failure <string, Error> ) { return(_); } return(IsEmpty(input, parameter)); }
public static Result <string, Error> IsNullOrWhiteSpace(this IGuard guard, string input, string parameter) { var _ = IsNullOrEmpty(guard, input, parameter); if (_ is Failure <string, Error> ) { return(_); } return(IsWhiteSpace(input, parameter)); }
private void Guard(List <int> list, IGuard guard, bool negated = false) { if (guard is BasicGuard) { BasicGuard basicGuard = (BasicGuard)guard; int rel = 0; switch (basicGuard.Operator) { case RelationalOperator.LT: rel = 0; break; case RelationalOperator.LEQ: rel = 1; break; case RelationalOperator.EQUAL: rel = 2; break; case RelationalOperator.NOT_EQUAL: rel = 3; break; case RelationalOperator.GT: rel = 4; break; case RelationalOperator.GEQ: rel = 5; break; } if (negated) { rel += 8; } list.Add(rel); Multiset multiset = basicGuard.Multiset; string o = multiset.Objects.ToList()[0]; list.Add(objectsId[o]); list.Add(multiset[o]); } else if (guard is NegatedGuard) { NegatedGuard negatedGuard = (NegatedGuard)guard; Guard(list, negatedGuard.Operand, true); } else if (guard is CompoundGuard) { CompoundGuard compoundGuard = (CompoundGuard)guard; int op; if (compoundGuard.Operator == BinaryGuardOperator.AND) { op = 0; } else { op = 1; } Guard(list, compoundGuard.Lhs, negated); list.Add(op); Guard(list, compoundGuard.Rhs, negated); } }
public static T GTZero <T>(this IGuard _, T value, string parameterName, string?message = null) where T : struct, IConvertible, IComparable <T> { var target = default(T); if (value.CompareTo(target) < 1) { throw new BusinessException(message ?? $"{nameof(parameterName)}不能小于0"); } return(value); }
public void writeGuard(IGuard g) { if (g == null) { return; } owt.Write("{"); if (g is BasicGuard) { BasicGuard bg = g as BasicGuard; owt.Write("\"operator\":"); switch (bg.Operator) { case RelationalOperator.EQUAL: owt.Write("\"eq\""); break; case RelationalOperator.GEQ: owt.Write("\"geq\""); break; case RelationalOperator.GT: owt.Write("\"gt\""); break; case RelationalOperator.LT: owt.Write("\"lt\""); break; case RelationalOperator.LEQ: owt.Write("\"leq\""); break; case RelationalOperator.NOT_EQUAL: owt.Write("\"neq\""); break; } owt.Write(", \"multiset\":"); writeMultiset(bg.Multiset); } else if (g is NegatedGuard) { NegatedGuard ng = g as NegatedGuard; owt.Write("\"operator\":\"not\""); owt.Write(", \"operatnd\":"); writeGuard(ng.Operand); } else if (g is CompoundGuard) { CompoundGuard cg = g as CompoundGuard; owt.Write("\"operator\":"); switch (cg.Operator) { case BinaryGuardOperator.AND: owt.Write("\"and\""); break; case BinaryGuardOperator.OR: owt.Write("\"or\""); break; } owt.Write(", \"lhs\":"); writeGuard(cg.Lhs); owt.Write(", \"rhs\":"); writeGuard(cg.Rhs); } owt.Write("}"); }
private IGuard readCompoundGuard(XPathNodeIterator it, BinaryGuardOperator op) { IGuard g = readSelectedGuard(it.Current); if (it.MoveNext()) { return(new CompoundGuard(op, g, readCompoundGuard(it, op))); } else { return(g); } }
public GuardPaymentController(IGuardPayment guardPaymentComponent, IGuard guardComponent, IDailyLog dailyLogComponent) { _guardPaymentComponent = guardPaymentComponent; _guardComponent = guardComponent; _dailyLogComponent = dailyLogComponent; }
public ReportsController(ICustomer customerComponent, IGuard guardComponent) { _customerComponent = customerComponent; _guardComponent = guardComponent; }
public GuardController(IGuard gaurdComponent) { _gaurdComponent = gaurdComponent; }