Пример #1
0
        public static PoseMasterStep CreateFromInputString(IEntity entity, string inputString)
        {
            PosemasterPose pose   = PoseMasterStep.GetFromString(inputString);
            bool           remove = inputString.Contains(" --remove");

            return(new PoseMasterStep(entity, pose, remove));
        }
Пример #2
0
        public BaseStep BuildStep(string inputLine)
        {
            inputLine = inputLine.Trim();

            var split = inputLine.Split(' ').ToList();

            var args = split.Where(x => x.StartsWith("--"));

            var chunks = split
                         .Except(args)
                         .Where(chunk => chunk != "!!");

            var argsDict = args.ToDictionary(
                s => s.Trim('-').Split('=').ElementAtOrDefault(0) ?? "",
                s => s.Trim('-').Split('=').ElementAtOrDefault(1) ?? "");

            var types = System.Reflection.Assembly
                        .GetExecutingAssembly()
                        .GetTypes()
                        .Where(x => x.BaseType == typeof(BaseStep));

            StepInput input = new StepInput()
            {
                chunks   = chunks.ToList(),
                supplier = this.entitySupplier,
                args     = argsDict.ToDictionary(x => x.Key, x => x.Value.TrimEnd(',')),
                line     = inputLine
            };

            foreach (var item in argsDict)
            {
                System.Diagnostics.Debug.WriteLine(item.Key);
                System.Diagnostics.Debug.WriteLine(item.Value);
            }

            bool containsRef = argsDict.ContainsKey("ref");

            //System.Diagnostics.Debug.WriteLine("Contains ref :: " + containsRef.ToString());
            //System.Diagnostics.Debug.WriteLine("Ref ID :: " + argsDict["ref"]);

            foreach (var type in types)
            {
                var method = type.GetMethod("IsMatch");

                if (method != null)
                {
                    bool isMatch = (bool)method.Invoke(null, new [] { input as object });

                    if (isMatch)
                    {
                        var      constructor = type.GetConstructor(new[] { typeof(StepInput) });
                        BaseStep step        = (BaseStep)constructor.Invoke(new object[] { input });

                        step.RefID = argsDict.ContainsKey("ref") ? argsDict["ref"] : "";
                        step.Wait  = !inputLine.EndsWith("!!");
                        return(step);
                    }
                }
            }

            IEntity    entity = this.GetEntityFromInput(inputLine);
            StepAction action = this.GetActionFromInput(inputLine);

            switch (action)
            {
            case StepAction.Move:

                BaseMoveStep moveStep = MoveToPositionStep.CreateFromInputString(inputLine, this.entitySupplier);

                if (moveStep != null)
                {
                    return(moveStep);
                }

                throw new MisformedStepException(inputLine);

            case StepAction.Pose:
                return(PoseMasterStep.CreateFromInputString(entity, inputLine));
            }


            throw new MisformedStepException(inputLine);
        }