示例#1
0
        internal static IInteractiveWindowCommands GetInteractiveCommands(
            IServiceProvider serviceProvider,
            IInteractiveWindow window,
            IInteractiveEvaluator eval
            )
        {
            var model      = serviceProvider.GetComponentModel();
            var cmdFactory = model.GetService <IInteractiveWindowCommandsFactory>();
            var cmds       = model.GetExtensions <IInteractiveWindowCommand>();
            var roles      = eval.GetType()
                             .GetCustomAttributes(typeof(InteractiveWindowRoleAttribute), true)
                             .Select(r => ((InteractiveWindowRoleAttribute)r).Name)
                             .ToArray();

            var contentTypeRegistry = model.GetService <IContentTypeRegistryService>();
            var contentTypes        = eval.GetType()
                                      .GetCustomAttributes(typeof(ContentTypeAttribute), true)
                                      .Select(r => contentTypeRegistry.GetContentType(((ContentTypeAttribute)r).ContentTypes))
                                      .ToArray();

            return(cmdFactory.CreateInteractiveCommands(
                       window,
                       "$",
                       cmds.Where(x => IsCommandApplicable(x, roles, contentTypes))
                       ));
        }
示例#2
0
        internal static IInteractiveWindowCommands GetInteractiveCommands(
            IServiceProvider serviceProvider,
            IInteractiveWindow window,
            IInteractiveEvaluator eval
        ) {
            var model = serviceProvider.GetComponentModel();
            var cmdFactory = model.GetService<IInteractiveWindowCommandsFactory>();
            var cmds = model.GetExtensions<IInteractiveWindowCommand>();
            var roles = eval.GetType()
                .GetCustomAttributes(typeof(InteractiveWindowRoleAttribute), true)
                .Select(r => ((InteractiveWindowRoleAttribute)r).Name)
                .ToArray();

            var contentTypeRegistry = model.GetService<IContentTypeRegistryService>();
            var contentTypes = eval.GetType()
                .GetCustomAttributes(typeof(ContentTypeAttribute), true)
                .Select(r => contentTypeRegistry.GetContentType(((ContentTypeAttribute)r).ContentTypes))
                .ToArray();

            return cmdFactory.CreateInteractiveCommands(
                window,
                "$",
                cmds.Where(x => IsCommandApplicable(x, roles, contentTypes))
            );
        }