Example #1
0
        public void Populate(ICommandSet commandSet, IContext context)
        {
            if (commandSet == null)
            {
                throw new ArgumentNullException(nameof(commandSet));
            }

            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            // Administration
            commandSet.Register("load $filename", filename => new Response(filename, ResponseType.Load));
            commandSet.Register("quit", () => new Response(ResponseType.Quit));
            commandSet.Register("reset", () => context.CurrentTopic.Reset());
            commandSet.Register("trace", () => ResponseType.Trace);

            // Topics and concepts
            commandSet.Register("create topic $name", name => { context.CreateTopic(name); });
            commandSet.Register("clear topic", () => context.SetTopic(string.Empty));
            commandSet.Register("set topic $name", name => context.SetTopic(name));

            commandSet.Register("define $name", name => context.CurrentTopic.CreateConcept(name));
            commandSet.Register("define $child as a type of $parent", (child, parent) =>
                                context.CurrentTopic.AddRelation(
                                    context.CurrentTopic.CreateConcept(child),
                                    context.CurrentTopic.FindConceptOrThrow(parent),
                                    Relationship.Parent));
            commandSet.Register("define $unit as a unit of $measurable", (unit, measurable) =>
                                context.CurrentTopic.AddRelation(
                                    context.CurrentTopic.CreateConcept(unit),
                                    context.CurrentTopic.FindConceptOrThrow(measurable),
                                    Relationship.Unit));

            commandSet.Register("$child is a type of $parent", (child, parent) =>
                                context.CurrentTopic.AddRelation(
                                    context.CurrentTopic.FindConceptOrThrow(child),
                                    context.CurrentTopic.FindConceptOrThrow(parent),
                                    Relationship.Parent));

            commandSet.Register("is $child a type of $parent", (child, parent) => {
                var topic      = context.CurrentTopic;
                var descendant = topic.FindConceptOrThrow(child);
                var ancestor   = topic.FindConceptOrThrow(parent);

                return(new Response(descendant.IsDescendantOf(ancestor)? "Yes": "No"));
            });

            commandSet.Register("$unit is a unit of $measurable", (unit, measurable) =>
                                context.CurrentTopic.AddRelation(
                                    context.CurrentTopic.FindConceptOrThrow(unit),
                                    context.CurrentTopic.FindConceptOrThrow(measurable),
                                    Relationship.Unit));
        }
Example #2
0
        public CommandLineProcessor([NotNull] IFactory factory)
        {
            if (factory == null)
            {
                throw new ArgumentNullException(nameof(factory));
            }
            _commandSet = factory.GetInstance <ICommandSet>();

            Context = factory.GetInstance <IContext>();

            var builder = factory.GetInstance <ICommandLineDirectives>();

            builder.Populate(_commandSet, Context);
        }
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="query"></param>
 /// <param name="updator"></param>
 /// <returns></returns>
 public static async Task <List <T> > UpdateSelectAsync <T>(this ICommandSet <T> query, Expression <Func <T, T> > updator)
 {
     return(await UpdateSelectAsync(query as CommandSet <T>, updator));
 }
 /// <summary>
 ///
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="query"></param>
 /// <param name="updator"></param>
 /// <returns></returns>
 public static List <T> UpdateSelect <T>(this ICommandSet <T> query, Expression <Func <T, T> > updator)
 {
     return(UpdateSelect(query as CommandSet <T>, updator));
 }
 /// <summary>
 /// 获取自定义仓储
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="commandSet"></param>
 /// <returns></returns>
 public static IBaseRepository <T> GetRepository <T>(this ICommandSet <T> commandSet)
 {
     return((commandSet as CommandSet <T>).GetRepository());
 }
 /// <summary>
 /// 排除在工作单元外
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="commandSet"></param>
 /// <returns></returns>
 public static ICommandSet <T> NotUnitOfWork <T>(this ICommandSet <T> commandSet)
 {
     NotUnitOfWork(commandSet as CommandSet <T>);
     return(commandSet);
 }