/// <summary>
        /// instantiates a new instance of the host interface control
        /// </summary>
        public HostInterface(HostInterfaceMode mode = HostInterfaceMode.Interactive)
        {
            // initialize user control

            BackColor   = Constants.COLOR_BACKGROUND;
            BorderStyle = System.Windows.Forms.BorderStyle.None;
            Height      = 200;
            Width       = 200;

            // initialize RTB

            RTB           = new HostRtb();
            RTB.Dock      = DockStyle.Fill;
            RTB.Font      = Constants.FONT_STANDARD;
            RTB.BackColor = Constants.COLOR_BACKGROUND;
            RTB.ForeColor = Constants.COLOR_STANDARD_FOREGROUND;
            Controls.Add(RTB);

            // initialize input filters

            InputFilters = new InputEventsFilterCollection(this);
            InputFilters.SetFilterMode(FilterMode.Execution);
            InputFilters.RegisterSubscription(HandleKeyInputResultAction);

            // initialize the commands collection

            Commands = new CommandCollection();

            // initialize host writers

            Out = new HostWriterCollection(OnHostWriterActionHandler, GetBuffer());

            // initialize prompt

            _writePromptAction = outWriters => { outWriters.Standard.Write("> "); };

            // initialize mode

            Mode = mode;

            // initialize modules collection

            Modules = new ModuleCollection(Commands);
            Modules.Install(typeof(BitPantry.Theta.Modules.Core.Module), Out);

            // initialize auto complete

            _autoComplete = new AutoCompleteController(this);

            // initialize submit history

            _submitHistory = new List <string>();

            // initialize command execution prompt

            _commandExecutionPrompt = new CommandExecutionPrompt(this);

            // initialize invoker

            _invoker = new CommandInvoker(this);
        }
Example #2
0
        public void Load(Package package, ModuleCollection modules, IWriterCollection writers)
        {
            if (PackageLogic.Instance.LoadedPackages.Contains(package))
            {
                throw new Exception(string.Format("The package {0} is already loaded", package.Name));
            }

            Dictionary <string, System.Reflection.Assembly> asmDic = new Dictionary <string, System.Reflection.Assembly>();

            bool isErrors = false;

            if (package.Modules.Count > 0)
            {
                foreach (var module in package.Modules)
                {
                    Type moduleType = null;
                    System.Reflection.Assembly asm = null;

                    try
                    {
                        if (!asmDic.ContainsKey(module.Assembly))
                        {
                            asmDic.Add(module.Assembly, Util.LoadAssembly(module.Assembly));
                        }
                        asm = asmDic[module.Assembly];

                        moduleType = asm.GetType(module.ModuleType);
                        if (!modules.Install(moduleType, writers) && isErrors == false)
                        {
                            isErrors = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        writers.Error.WriteLine(string.Format("An error occured while installing module '{0}' from assembly '{1}' :: {2}\r\n{3}"
                                                              , moduleType, asm.CodeBase.Replace("file:///", string.Empty), ex.Message, ex.StackTrace));

                        if (moduleType != null && modules.Any(m => m.GetType() == moduleType))
                        {
                            modules.Uninstall(moduleType, writers);
                        }

                        writers.Error.WriteLine("The module has been uninstalled.");

                        isErrors = true;
                    }
                }
            }
            else
            {
                writers.Warning.WriteLine("The package has been loaded but no modules were installed - the package does not define any modules.");
            }

            _loadedPackageNames.Add(package.Name);

            if (isErrors)
            {
                writers.Warning.WriteLine("The package has been loaded with errors.");
            }
            else
            {
                writers.Standard.WriteLine("Package loaded");
            }
        }