Example #1
0
 public static void Behaviors([ValidatedNotNull] IBehaviors someBehaviors)
 {
     if (someBehaviors == null)
     {
         throw new ActorException("Null someBehaviors");
     }
 }
Example #2
0
        protected async Task <IEnumerable <ItemResult> > CsvSaveImplementation(
            string csv,
            IDataSource <T> dataSource,
            IBehaviors <T> behaviors,
            bool hasHeader = true)
        {
            // Get list from CSV
            var list       = IntelliTect.Coalesce.Helpers.CsvHelper.ReadCsv <TDto>(csv, hasHeader);
            var resultList = new List <ItemResult>();

            foreach (var dto in list)
            {
                var parameters = new DataSourceParameters()
                {
                    Includes = "none"
                };

                // Security: SaveImplementation is responsible for checking specific save/edit attribute permissions.
                var result = await SaveImplementation(dto, parameters, dataSource, behaviors);

                resultList.Add(new ItemResult {
                    WasSuccessful = result.WasSuccessful, Message = result.Message
                });
            }
            return(resultList);
        }
Example #3
0
 public static ActorInjection Cast(IBehaviors bhvs)
 {
     return(new ActorInjection()
     {
         Actor = new BaseActor(bhvs)
     });
 }
Example #4
0
        public override IViolation <IParserResult> Check(IParserResult subject, IBehaviors context = null)
        {
            if (!subject.IsSet(Target))
            {
                return(NonViolation <IParserResult> .Instance);
            }

            try {
                Target.Parse(subject.GetValue((IArgument)Target), true);
            } catch (Exception exc) {
                return(new Violation <IParserResult>(
                           this,
                           new List <ISolution <IParserResult> > {
                    new Solution <IParserResult>(
                        new[] {
                        new PromptValue <T>(Target)
                    })
                }.Union(
                               Target.HasDefaultValue || Target.ValueType.IsValueType
                              ? new List <ISolution <IParserResult> > {
                    new Solution <IParserResult>(
                        new IAction <IParserResult>[] {
                        new SetValue <T>(
                            Target,
                            Target.HasDefaultValue
                                                            ? Target.DefaultValue
                                                            : Activator.CreateInstance <T>( ))
                    })
                }
                              : Enumerable.Empty <ISolution <IParserResult> >( )),
                           $"invalid value: {exc.Message}"));
            }

            return(NonViolation <IParserResult> .Instance);
        }
        //public Flags Flag { get { return this.flag; } }
        public Bullet(GameEngine B, Texture2D I, Vector2 S, IBehaviors b, Vector2 V = default(Vector2), Vector2 P = default(Vector2)) : base(I, S, b, P, V)
        {
            /*  Need to know the following:
             *      1. Each bullet is "Bullet" !!! it knows what to do
             *      2. check if hit anything by static "board"
             *      3. inventing new kinds of bullets by inventing new "IBehaviors"
             *      4. each bullet knows the unique Character/Owner it belongs to
             *      5. its velocity can be zero (making barrier)
             */

            // find its launching point
            if (B is Player)
            {
                this.Flag = Flags.Player;
                UpdatePosition(new Vector2(B.Position.X + (B.Size.X - Size.X) / 2, B.Position.Y));
            }
            else if (P == default(Vector2))
            {
                this.Flag = Flags.Enemy;
                UpdatePosition(new Vector2(B.Position.X + (B.Size.X - Size.X) / 2, B.Position.Y + I.Height));
            }
            else
            {
                this.Flag = Flags.Enemy;
                UpdatePosition(P);
            }
            blong = B;

            if (b == null)
            {
                UpdateBehavior(new Movement());
            }
        }
Example #6
0
 protected void AddBehavior(IBehaviors someBehaviors)
 {
     CheckArg.Behaviors(someBehaviors);
     someBehaviors.LinkToActor(this);
     fListBehaviors.AddRange(someBehaviors.AllBehaviors());
     AddMissedMessages();
     TrySetInTask();
 }
Example #7
0
        public void Apply(IParserResult subject, IBehaviors context)
        {
            ICliConfig config = context.Get <ConfigBehavior>( ).Config;

            (subject as ParserResult)?.SetArgument(
                Target,
                config.Prompt(config, subject, Target));
        }
Example #8
0
        public static void Behaviors([ValidatedNotNull] IBehaviors someBehaviors)
        {
            if (someBehaviors != null)
            {
                return;
            }

            throw new ActorException(MessageNullSomeBehaviors);
        }
 public Entity(int _id, Texture2D _I, Vector2 _S, Vector2 _V, IBehaviors _b, int __Lives)
 {
     id     = _id;
     I      = _I;
     S      = _S;
     V      = _V;
     b      = _b;
     _Lives = __Lives;
 }
Example #10
0
        public bool Resolve(IParserResult prIn, out IParserResult prOut, IBehaviors context)
        {
            IEnumerable <IRule <IParserResult> > rules =
                _rules.Union(
                    RuleDeriver.Instance.DeriveRules(prIn.CliSpecification))
                .ToList( );

            HelpOption hlpOpt = (HelpOption)prIn.CliSpecification.Options.FirstOrDefault(opt => opt is HelpOption);

            if (hlpOpt != null)
            {
                rules = rules.Select(
                    r => new HelpIsSetOr(hlpOpt, r));
            }

            RuleCheckerBase <IParserResult> rc = new RuleCheckerBase <IParserResult>(rules);

            if (rc.Check(prIn, context) == NonViolation <IParserResult> .Instance)
            {
                prOut = prIn;
                return(true);
            }

            IViolation <IParserResult> violation;

            prOut = (IParserResult)prIn.Clone( );
            while ((violation = rc.Check(prOut, context)) != NonViolation <IParserResult> .Instance)
            {
                _config.Out.WriteLine( );
                _config.Out.WriteLine(prOut);
                _config.Out.WriteLine($"> {violation.Description}");
                if (!violation.HasSolution)
                {
                    _config.Out.WriteLine("> conflict has no solution");
                    prOut = null;
                    return(false);
                }

                switch (Prompt(violation.Solutions, out ISolution <IParserResult> chosenSolution))
                {
                case UserAction.Cancel:
                    prOut = null;
                    return(false);

                case UserAction.AutoSolve:
                    AutoSolve(prOut, out prOut, rules, context);
                    break;

                case UserAction.ApplySolution:
                    ApplySolution(prOut, out prOut, chosenSolution, context);
                    break;
                }
            }

            return(true);
        }
Example #11
0
        private static void AutoSolve(
            IParserResult prIn,
            out IParserResult prOut,
            IEnumerable <IRule <IParserResult> > rules,
            IBehaviors context)
        {
            prOut = (IParserResult)prIn.Clone( );
            GenericRuleChecker <IParserResult> grc = new GenericRuleChecker <IParserResult>(rules, prOut, true, context);

            prOut = grc.Subject;
        }
Example #12
0
        public override IViolation <IList <T> > Check(IList <T> subject, IBehaviors context)
        {
            if (subject.Contains(Target))
            {
                return(NonViolation <IList <T> > .Instance);
            }

            return(new Violation <IList <T> >(
                       this,
                       MakeValid( )));
        }
Example #13
0
        public override IViolation <IParserResult> Check(IParserResult subject, IBehaviors context = null)
        {
            if (subject.IsSet(Target))
            {
                return(NonViolation <IParserResult> .Instance);
            }

            return(new Violation <IParserResult>(
                       this,
                       MakeValid( )));
        }
Example #14
0
 private static void ApplySolution(
     IParserResult prIn,
     out IParserResult prOut,
     ISolution <IParserResult> chosenSolution,
     IBehaviors context)
 {
     prOut = (IParserResult)prIn.Clone( );
     foreach (IAction <IParserResult> action in chosenSolution.Actions)
     {
         action.Apply(prOut, context);
     }
 }
Example #15
0
        public override IViolation <T> Check(T subject, IBehaviors context = null)
        {
            IViolation <T> violation = Target.Check(subject, context);

            return(violation == NonViolation <T> .Instance
               ? (IViolation <T>) new Violation <T>(
                       this,
                       Reduce(
                           MakeValid( ),
                           subject))
               : NonViolation <T> .Instance);
        }
Example #16
0
        public GenericRuleChecker(
            IEnumerable <IRule <T> > rules = null,
            T subject = null,
            bool acceptInvalidSubject = false,
            IBehaviors context        = null,
            bool interactive          = false)
        {
            _context     = context ?? EmptyBehaviors.Instance;
            _interactive = interactive;

            if (rules != null)
            {
                foreach (IRule <T> rule in rules)
                {
                    Add(rule);
                }
            }

            if (subject == null)
            {
                ConstructorInfo ci;
                try {
                    ci = typeof(T).GetConstructor(Type.EmptyTypes);
                } catch (Exception exc) {
                    throw new ApplicationException(
                              $"{nameof( subject )} is null and there is no default ctor for {typeof( T ).FullName}",
                              exc);
                }

                Subject = (T)ci.Invoke(new object[0]);
            }
            else
            {
                Subject = subject;
            }

            ApplicationResult <T> ar = Apply(
                acceptInvalidSubject
                     ? (Func <IViolation <T>, ISolution <T> >)null
                     : v => throw new ApplicationException("invalid subject in ctor"));

            if (ar.Successful)
            {
                ar.Accept( );
            }
            else
            {
                throw new ApplicationException(
                          $"unsolvable violation for subject in ctor: {ar.UnsolvableViolation.Description}");
            }
        }
Example #17
0
        public IViolation <T> Check(T subject, IBehaviors context = null)
        {
            context ??= EmptyBehaviors.Instance;
            foreach (IRule <T> rule in _rules)
            {
                IViolation <T> violation = rule.Check(subject, context);
                if (violation != NonViolation <T> .Instance)
                {
                    return(violation);
                }
            }

            return(NonViolation <T> .Instance);
        }
Example #18
0
        public bool Check(T subject, out IEnumerable <IViolation <T> > violations, IBehaviors context = null)
        {
            context ??= EmptyBehaviors.Instance;
            violations = new List <IViolation <T> >( );
            foreach (IRule <T> rule in _rules)
            {
                IViolation <T> violation = rule.Check(subject, context);
                if (violation != NonViolation <T> .Instance)
                {
                    ((List <IViolation <T> >)violations).Add(violation);
                }
            }

            return(((List <IViolation <T> >)violations).Count == 0);
        }
Example #19
0
      public override IViolation<ICliSpecification> Check(
            ICliSpecification subject,
            IBehaviors context = null ) {
         ConfigBehavior cb = null;
         context?.TryGet( out cb );
         ICliConfig conf = cb?.Config;

         foreach( Func<UniqueNames, ICliSpecification, ICliConfig, IViolation<ICliSpecification>> check
               in __checks ) {
            IViolation<ICliSpecification> violation = check( this, subject, conf );
            if( violation != NonViolation<ICliSpecification>.Instance )
               return violation;
         }

         return NonViolation<ICliSpecification>.Instance;
      }
Example #20
0
        public override IViolation <IParserResult> Check(IParserResult subject, IBehaviors context = null)
        {
            try {
                if (!subject.IsSet(Target) ||
                    Comparer <T> .Default.Compare(subject.GetValue(Target), MaxVal) <= 0)
                {
                    return(NonViolation <IParserResult> .Instance);
                }
            } catch (Exception) {
                // the value might simply be invalid at this point
                return(NonViolation <IParserResult> .Instance);
            }

            return(new Violation <IParserResult>(
                       this,
                       MakeValid( )));
        }
Example #21
0
        public override IViolation <IParserResult> Check(IParserResult subject, IBehaviors context = null)
        {
            if (!subject.IsSet(Target))
            {
                return(NonViolation <IParserResult> .Instance);
            }

            string         path = subject.GetValue((IArgument)Target);
            FileSystemInfo fsi;

            try {
                fsi = CreateFileSystemItem(path);
            } catch (Exception) {
                // invalid path format
                return(new Violation <IParserResult>(
                           this,
                           new[] {
                    new Solution <IParserResult>(
                        new[] {
                        new PromptValue <FileSystemInfo>(Target)
                    })
                }));
            }

            if (fsi.Exists)
            {
                return(NonViolation <IParserResult> .Instance);
            }

            return(new Violation <IParserResult>(
                       this,
                       new[] {
                new Solution <IParserResult>(
                    new[] {
                    new CreateFileSystemItem(Target, Target.Interactive)
                }),
                new Solution <IParserResult>(
                    new[] {
                    new PromptValue <FileSystemInfo>(Target)
                }),
                new Solution <IParserResult>(
                    new[] {
                    new RemoveArgument(Target)
                })
            }));
        }
Example #22
0
        public override IViolation <T> Check(T subject, IBehaviors context = null)
        {
            IViolation <T> va = TargetA.Check(subject, context);
            IViolation <T> vb = TargetB.Check(subject, context);

            if (va == NonViolation <T> .Instance &&
                vb == NonViolation <T> .Instance)
            {
                return(NonViolation <T> .Instance);
            }

            return(new Violation <T>(
                       this,
                       Reduce(
                           MakeValid( ),
                           subject)));
        }
Example #23
0
        public override IViolation <ICliSpecification> Check(
            ICliSpecification subject,
            IBehaviors context = null)
        {
            IItem item = subject.Options.Cast <IItem>( )
                         .Union(subject.Flags)
                         .FirstOrDefault(i => i.Arguments.Count( ) > 1);

            if (item != null)
            {
                return(new Violation <ICliSpecification>(
                           this,
                           Enumerable.Empty <ISolution <ICliSpecification> >( ),
                           $"{( item is IOption? "option" : "flag" )} has more than one argument"));
            }

            return(NonViolation <ICliSpecification> .Instance);
        }
Example #24
0
        protected async Task <IEnumerable <ItemResult> > CsvUploadImplementation(
            Microsoft.AspNetCore.Http.IFormFile file,
            IDataSource <T> dataSource,
            IBehaviors <T> behaviors,
            bool hasHeader = true)
        {
            if (file == null || file.Length == 0)
            {
                throw new ArgumentException("No files uploaded");
            }

            using (var stream = file.OpenReadStream())
            {
                using (var reader = new System.IO.StreamReader(stream))
                {
                    var csv = await reader.ReadToEndAsync();

                    return(await CsvSaveImplementation(csv, dataSource, behaviors, hasHeader));
                }
            }
        }
Example #25
0
        public override IViolation <T> Check(T subject, IBehaviors context = null)
        {
            int nonViolationCount = 0;

            foreach (IRule <T> target in _targets)
            {
                IViolation <T> violation = target.Check(subject, context);
                if (violation == NonViolation <T> .Instance)
                {
                    nonViolationCount++;
                }
            }

            if (nonViolationCount == 1)
            {
                return(NonViolation <T> .Instance);
            }

            return(new Violation <T>(
                       this,
                       Reduce(
                           MakeValid( ),
                           subject)));
        }
Example #26
0
 public BaseActor(IBehaviors someBehaviors)
 {
     Tag = new ActorTag();
     Become(someBehaviors);
 }
Example #27
0
 public virtual Task <IEnumerable <ItemResult> > CsvUpload(
     IFormFile file,
     IDataSource <SendGridDemo.Data.Models.SmsMessage> dataSource,
     IBehaviors <SendGridDemo.Data.Models.SmsMessage> behaviors,
     bool hasHeader = true)
 => CsvUploadImplementation(file, dataSource, behaviors, hasHeader);
Example #28
0
 public virtual Task <ItemResult <SmsMessageDtoGen> > Delete(
     int id,
     IBehaviors <SendGridDemo.Data.Models.SmsMessage> behaviors,
     IDataSource <SendGridDemo.Data.Models.SmsMessage> dataSource)
 => DeleteImplementation(id, new DataSourceParameters(), dataSource, behaviors);
Example #29
0
 public virtual Task <ItemResult <SmsMessageDtoGen> > Save(
     SmsMessageDtoGen dto,
     [FromQuery] DataSourceParameters parameters,
     IDataSource <SendGridDemo.Data.Models.SmsMessage> dataSource,
     IBehaviors <SendGridDemo.Data.Models.SmsMessage> behaviors)
 => SaveImplementation(dto, parameters, dataSource, behaviors);
Example #30
0
 public virtual Task <IEnumerable <ItemResult> > CsvSave(
     string csv,
     IDataSource <SendGridDemo.Data.Models.SmsMessage> dataSource,
     IBehaviors <SendGridDemo.Data.Models.SmsMessage> behaviors,
     bool hasHeader = true)
 => CsvSaveImplementation(csv, dataSource, behaviors, hasHeader);