예제 #1
0
        public UInt64?GetAttachmentId()
        {
            if (!What.Contains(ATTACHMENTIDENTIFIER))
            {
                return(null);
            }

            return(UInt64.Parse(
                       What.Replace(ATTACHMENTIDENTIFIER, string.Empty)
                       .Replace(FLAGS, string.Empty)
                       .Trim()
                       ));
        }
예제 #2
0
파일: Use.cs 프로젝트: ohomola/gears
        public override object DoRun()
        {
            object instance  = null;
            var    arguments = new List <object>();

            if (Interpreter.Language.CanParse(What.ToLower()))
            {
                instance = Interpreter.Language.ParseKeyword(What.ToLower());
            }
            else
            {
                var type = TypeRegistry.Types.FirstOrDefault(x => x.Name.ToLower() == What.ToLower());
                if (type == null && What.Contains(" "))
                {
                    var firstPart = What.Split(' ')[0];
                    arguments.Add(What.Substring(firstPart.Length + 1));
                    type = TypeRegistry.Types.FirstOrDefault(x => x.Name.ToLower() == firstPart.ToLower());
                }
                if (type == null)
                {
                    throw new ArgumentException($"{What} is not recognized.");
                }

                instance = Activator.CreateInstance(type, args: arguments.ToArray());
            }

            Data.Add(instance);

            (instance as IAutoRegistered)?.Register(Interpreter);

            if (instance is IKeyword)
            {
                Interpreter.AddToPlan(instance as IKeyword);
            }

            return(new SuccessAnswer($"Added {instance} to Data Context."));
        }
예제 #3
0
        public bool IsMatching(Suspect suspect)
        {
            var hasOne = Where.Count == 1 && What.Count == 1 && How.Count == 1 && Why.Count == 1;

            return(hasOne && Where.Contains(suspect.Where) && What.Contains(suspect.What) && How.Contains(suspect.How) && Why.Contains(suspect.Why));
        }