Example #1
0
 public SqlFileProcessor(IRuleVisitor ruleVisitor, IPluginHandler pluginHandler, IReporter reporter, IFileSystem fileSystem)
 {
     this.ruleVisitor   = ruleVisitor;
     this.pluginHandler = pluginHandler;
     this.reporter      = reporter;
     this.fileSystem    = fileSystem;
 }
Example #2
0
        private int runCount = 0; // number of times run has been called

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="Bot"/> class.
        /// </summary>
        /// <param name="client">The client.</param>
        /// <param name="userInteraction">The user interaction manager..</param>
        /// <param name="console">The console.</param>
        /// <param name="settings">The settings.</param>
        /// <param name="listener">The listener.</param>
        /// <param name="pluginHandler">The plugin handler.</param>
        /// <param name="moduleLoader">The module loader.</param>
        /// <param name="authorization">The authorization manager.</param>
        public Bot(
            Client client, 
            IUserInteraction userInteraction, 
            IConsole console, 
            IBotSettings settings, 
            IListener listener, 
            IPluginHandler pluginHandler,
            IModuleLoader moduleLoader,
            IAuthorization authorization)
        {
            Guard.Against(client.IsNull(), "client");
            Guard.Against(userInteraction.IsNull(), "userInteraction");
            Guard.Against(console.IsNull(), "console");
            Guard.Against(settings.IsNull(), "settings");
            Guard.Against(listener.IsNull(), "listener");
            Guard.Against(pluginHandler.IsNull(), "pluginHandler");
            Guard.Against(moduleLoader.IsNull(), "moduleLoader");
            Guard.Against(authorization.IsNull(), "authorization");

            this.client = client;
            this.userInteraction = userInteraction;
            this.console = console;
            this.settings = settings;
            this.listener = listener;
            this.pluginHandler = pluginHandler;
            this.moduleLoader = moduleLoader;
            this.authorization = authorization;
            this.SessionStart = DateTime.Now;
        }
Example #3
0
        internal static FileItem Create(
            IFileSystem fileSystem,
            string pathFile,
            IPluginHandler pluginHandler)
        {
            // There is a problem with `GetDirectoryName` as it cuts the drive name if there is no directory or file.
            // That should not be a problem here though as we always get a file.
            // https://docs.microsoft.com/en-us/dotnet/api/system.io.path.getdirectoryname
            // TODO:Can/should we change to Abstraction.
            string path = System.IO.Path.GetDirectoryName(pathFile);

            // TODO:Can/should we change to Abstraction.
            string filename = System.IO.Path.GetFileName(pathFile);

            //// We cannot use new FileInfo(...).Length as it throws an exception.
            //// See here: https://stackoverflow.com/questions/44029830/how-do-i-mock-the-fileinfo-information-for-a-file
            //long length = fileSystem.FileInfo.FromFileName(pathFile).Length;

            //// GetLastWriteTime always returns the value as local kind
            //// so we change it to UTC to alway have... UTC.
            //var lastWriteTime = fileSystem.File.GetLastWriteTime(pathFile).ToUniversalTime();

            var results = pluginHandler.Execute(pathFile);

            return(new FileItem(path, filename, results)); //, length, lastWriteTime);
        }
Example #4
0
 public PluginsViewModel(IPluginHandler handler)
 {
     plugins = new ObservableCollection <PluginItemViewModel>();
     Plugins = CollectionViewSource.GetDefaultView(plugins);
     Plugins.CurrentChanged += OnCurrentItemChanged;
     this.handler            = handler;
 }
Example #5
0
        public void Run()
        {
            configReader.LoadConfig(commandLineOptions.ConfigFile);

            var fragmentBuilder    = new FragmentBuilder(configReader.CompatabilityLevel);
            var ruleVisitorBuilder = new RuleVisitorBuilder(configReader, this.reporter);
            var ruleVisitor        = new SqlRuleVisitor(ruleVisitorBuilder, fragmentBuilder, reporter);

            pluginHandler = new PluginHandler(reporter);
            fileProcessor = new SqlFileProcessor(ruleVisitor, pluginHandler, reporter, new FileSystem());

            pluginHandler.ProcessPaths(configReader.GetPlugins());
            var response = commandLineOptionHandler.Handle(new CommandLineRequestMessage(commandLineOptions));

            if (response.ShouldLint)
            {
                fileProcessor.ProcessList(commandLineOptions.LintPath);
            }

            if (fileProcessor.FileCount > 0)
            {
                reporter.ReportResults(timer.Stop(), fileProcessor.FileCount);
            }

            if (!response.Success)
            {
                Environment.ExitCode = 1;
            }
        }
Example #6
0
 public SqlFileProcessor(IRuleVisitor ruleVisitor, IPluginHandler pluginHandler, IReporter reporter, IFileSystem fileSystem)
 {
     _ruleVisitor   = ruleVisitor;
     _pluginHandler = pluginHandler;
     _reporter      = reporter;
     _fileSystem    = fileSystem;
 }
Example #7
0
 public SqlFileProcessor(IRuleVisitor ruleVisitor, IPluginHandler pluginHandler, IReporter reporter, IFileSystem fileSystem)
 {
     this.ruleVisitor    = ruleVisitor;
     this.pluginHandler  = pluginHandler;
     this.reporter       = reporter;
     this.fileSystem     = fileSystem;
     ruleExceptionFinder = new RuleExceptionFinder();
 }
Example #8
0
 internal ProgramImpl(
     IPluginHandler pluginHandler,
     IFileSystem fileSystem,
     IAssemblyFactory assemblyFactory,
     IOutputter outputter)
 {
     this.pluginHandler   = pluginHandler;
     this.fileSystem      = fileSystem;
     this.assemblyFactory = assemblyFactory;
     this.outputter       = outputter;
 }
Example #9
0
        public Application(string[] args, IReporter reporter)
        {
            timer = new ConsoleTimer();
            timer.Start();

            this.reporter            = reporter;
            commandLineOptions       = new CommandLineOptions.CommandLineOptions(args);
            configReader             = new ConfigReader(reporter);
            commandLineOptionHandler = new CommandLineOptionHandler(commandLineOptions, new ConfigFileGenerator(), configReader, reporter);
            var          fragmentBuilder    = new FragmentBuilder();
            var          ruleVisitorBuilder = new RuleVisitorBuilder(configReader, this.reporter);
            IRuleVisitor ruleVisitor        = new SqlRuleVisitor(ruleVisitorBuilder, fragmentBuilder, reporter);

            pluginHandler = new PluginHandler(reporter);
            fileProcessor = new SqlFileProcessor(ruleVisitor, pluginHandler, reporter, new FileSystem());
        }
Example #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PluginContext"/> class.
 /// Is marked as internal so external clients cannot instantiate.
 /// </summary>
 /// <param name="client">The client.</param>
 /// <param name="console">The console.</param>
 /// <param name="authorizer">The authorizer.</param>
 /// <param name="chatrooms">The chatrooms.</param>
 /// <param name="listener">The listener.</param>
 /// <param name="botSettings">The bot settings.</param>
 /// <param name="pluginHandler">The plugin handler.</param>
 /// <param name="dispatcher">The system dispatcher.</param>
 /// <param name="packet">The current packet to be processed.</param>
 /// <param name="chatHelper">The chat helper.</param>
 public PluginContext(Client client, IConsole console,
     IAuthorization authorizer, IChatRoomContainer chatrooms,
     IListener listener, IBotSettings botSettings, 
     IPluginHandler pluginHandler, IDispatcher dispatcher, 
     EventPacket packet, IChatHelper chatHelper)
 {
     this.Client = client;
     this.Console = console;
     this.Authorizer = authorizer;
     this.ChatRooms = chatrooms;
     this.Listener = listener;
     this.BotSettings = botSettings;
     this.Plugins = pluginHandler;
     this.Dispatcher = dispatcher;
     this.ThisRoom = chatHelper;
 }
Example #11
0
        public void Run()
        {
            configReader.LoadConfig(commandLineOptions.ConfigFile);

            var          fragmentBuilder    = new FragmentBuilder(configReader.CompatabilityLevel);
            var          ruleVisitorBuilder = new RuleVisitorBuilder(configReader, this.reporter);
            IRuleVisitor ruleVisitor        = new SqlRuleVisitor(ruleVisitorBuilder, fragmentBuilder, reporter);

            pluginHandler = new PluginHandler(reporter);
            fileProcessor = new SqlFileProcessor(ruleVisitor, pluginHandler, reporter, new FileSystem());

            pluginHandler.ProcessPaths(configReader.GetPlugins());
            commandLineOptionHandler.HandleCommandLineOptions(commandLineOptions);
            fileProcessor.ProcessList(commandLineOptions.LintPath);

            if (fileProcessor.FileCount > 0)
            {
                reporter.ReportResults(timer.Stop(), fileProcessor.FileCount);
            }
        }
        private void LoadPlugins(RecurringJobManager manager)
        {
            var pluginSection   = ConfigurationManager.GetSection("pluginConfiguration") as PluginHandlerConfigurationSection;
            var cronExpressions = pluginSection.Plugins.Cast <PluginHandlerConfigurationElement>().ToDictionary(k => k.PluginName, v => v.CronExpression);

            foreach (var handler in _handlers)
            {
                IPluginHandler handlerInterface = handler.Value;

                var job = Job.FromExpression(() => handler.Value.Handle());

                var cronExpression = string.Empty;
                if (!cronExpressions.TryGetValue(handler.Metadata.Name, out cronExpression))
                {
                    logger.Warn($"Could not find cron expression for handler named {handler.Metadata.Name}.  Handler will not be loaded.");
                    continue;
                }

                logger.Info($"Loading handler {handler.Metadata.Name} using expression {cronExpression}");
                manager.AddOrUpdate(handler.Metadata.Name, job, cronExpression);
            }
        }
Example #13
0
        /// <summary>
        /// Helper object that stores the services available in this plug-in
        /// </summary>
        /// <param name="serviceProvider">IServiceProvider</param>
        /// <param name="plugin">Plugin handler</param>
        public LocalPluginContext(IServiceProvider serviceProvider, IPluginHandler plugin)
        {
            if (serviceProvider == null)
            {
                throw new ArgumentNullException(nameof(serviceProvider));
            }

            // Obtain the execution context service from the service provider.
            PluginExecutionContext = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));

            // Obtain the tracing service from the service provider.
            TracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));

            // Get the notification service from the service provider.
            NotificationService = (IServiceEndpointNotificationService)serviceProvider.GetService(typeof(IServiceEndpointNotificationService));

            // Obtain the organization factory service from the service provider.
            _factory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));

            // Set Event
            Event = PluginExecutionContext.GetEvent(plugin.RegisteredEvents);

            PluginTypeName = plugin.GetType().FullName;
        }
Example #14
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PluginService"/> class.
 /// </summary>
 /// <param name="pluginHandler">The plugin handler.</param>
 public PluginService(IPluginHandler pluginHandler)
 {
     Guard.Against<ArgumentNullException>(pluginHandler == null, "PluginHandler cannot be null.");
     this.pluginHandler = pluginHandler;
 }
Example #15
0
        public static void Initialize(IBuilder builder)
        {
            // start a thread which will handle the UI
            var thread = new Thread(() =>
            {
                var iconStream = Assembly.GetExecutingAssembly()
                    .GetManifestResourceStream("Oberon.SystemTray.Icon.ico");

                NotifyIcon trayIcon = new NotifyIcon();
                trayIcon.Text = "Oberon";
                trayIcon.Icon = new Icon(iconStream, 40, 40);

                ContextMenu trayMenu = new ContextMenu();
                trayMenu.MenuItems.Add("Actions", new [] {
                    new MenuItem("Version Info", About_Click),
                    new MenuItem("Check for Updates", MenuItem_Click),
                    new MenuItem("Manage Plugins", ManagePlugins_Click),
                    new MenuItem("Show Chat Interface", ShowChatInterface_Click)
                });
                trayMenu.MenuItems.Add("Restart Bot", Restart_Click);
                trayMenu.MenuItems.Add("Shutdown Bot", Exit_Click);
                trayMenu.MenuItems.Add(new MenuItem("Help", Help_Click) { BarBreak = true });

                trayIcon.ContextMenu = trayMenu;
                trayIcon.Visible = true;

                // start the messaging loop so the menu responds to events
                Application.Run();
            });
            thread.SetApartmentState(ApartmentState.STA);
            thread.IsBackground = true;
            thread.Start();

            // get a reference to the plugin handler
            pluginHandler = builder.Build<IPluginHandler>();

            // get a reference to the listener
            listener = builder.Build<IListener>();
        }
Example #16
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Dispatcher"/> class.
 /// </summary>
 /// <param name="pluginHandler">The plugin handler.</param>
 /// <param name="console">The console.</param>
 /// <param name="contextFactory">The plugin context factory.</param>
 public Dispatcher(IPluginHandler pluginHandler, IConsole console, IPluginContextFactory contextFactory)
 {
     this.pluginHandler = pluginHandler;
     this.console = console;
     this.contextFactory = contextFactory;
 }
Example #17
0
 /// <summary>This constructor takes all parameters needed to fully populate the object.
 /// </summary>
 /// <param name="fileSystem"></param>
 /// <param name="path"></param>
 /// <param name="pluginHandler"></param>
 private Logic(IFileSystem fileSystem, string path, IPluginHandler pluginHandler)
 {
     _fileSystem    = fileSystem;
     _pluginHandler = pluginHandler;
     Path           = path;
 }
Example #18
0
 /// <summary>This static constructor is the preferred.
 /// </summary>
 /// <param name="fileSystem"></param>
 /// <param name="path"></param>
 /// <param name="pluginHandler"></param>
 /// <returns></returns>
 internal static Logic Create(IFileSystem fileSystem, string path, IPluginHandler pluginHandler)
 {
     return(new Logic(fileSystem, path, pluginHandler));
 }
Example #19
0
 /// <summary>This method creates a <see cref="Logic"/> object for anywhere in a folder structure.
 /// </summary>
 /// <param name="fileSystem">The FileSystem object, typically System.IO.FileSystem for production.</param>
 /// <param name="path">Any path, rooted or not.</param>
 /// <param name="pluginHandler">A handler for plugins.</param>
 /// <returns></returns>
 public static Logic CreateForPath(IFileSystem fileSystem, string path, IPluginHandler pluginHandler)
 {
     return(Logic.Create(fileSystem, path, pluginHandler));
 }
Example #20
0
 public RuleVisitorBuilder(IConfigReader configReader, IReporter reporter, IPluginHandler pluginHandler) : this(configReader, reporter)
 {
     this.pluginHandler = pluginHandler;
 }