public void Launch(string applicationPath, dynamic dynVault, dynamic dynListItems)
        {
            if (!Debugger.IsAttached)
            {
                Debugger.Launch();
            }

            // TODO: heard this is bad, but don't have another way to do it currently
            // Need to set the app path because it is used later on to get the bin
            //AppDomain.CurrentDomain.SetData( "APPBASE", Path.Combine( applicationPath, "bin" ) );
            // Sets AppDomain.CurrentDomain.BaseDirectory
            AppDomain.CurrentDomain.SetData("APPBASE", applicationPath);

            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;

            Console.WriteLine("Launching");

            this._console = new BufferedConsole();

            try
            {
                var config     = Config.Create(ScriptCsArgs.Parse(new string[] { }));
                var scriptArgs = new string[] { };
                config.Console = this._console;
                var scriptServicesBuilder = (ScriptServicesBuilder)ScriptServicesBuilderFactory.Create(config, scriptArgs);

                var clientApp       = new MFilesClientApplication();
                var clientVault     = clientApp.BindToVault((string)dynVault.Name, IntPtr.Zero, true, true);
                var props           = clientVault.PropertyDefOperations.GetPropertyDefs();
                var propsDictionary = new Dictionary <string, MFIdentifier>();
                foreach (PropertyDef propertyDef in props)
                {
                    // TODO: what if multiple have same name?
                    propsDictionary.Add(propertyDef.Name, new MFIdentifier(propertyDef.GUID));
                }
                var globs = new ScriptHostArguments
                {
                    Vault = clientVault,
                    // TODO: convert this list using clientVault to something useful
                    // TODO: move the script dashboard to non popup (that way we can pass the current listing)? what if there are multiple? (home page)
                    ListingItems = dynListItems,
                    Properties   = propsDictionary
                };
                var myFactory = new MFilesScriptHostFactory(globs, this._console);
                scriptServicesBuilder.SetOverride <IScriptHostFactory, MFilesScriptHostFactory>(myFactory);
                scriptServicesBuilder.SetOverride <IRepl, MFilesRepl>();
                var scriptServices = scriptServicesBuilder.Build();

                var runtimeServices = (RuntimeServices)scriptServicesBuilder.RuntimeServices;
                runtimeServices.Container.Resolve <Printers>().AddCustomPrinter <Vault>(vault => vault.Name);
                runtimeServices.Container.Resolve <Printers>().AddCustomPrinter <IVault>(vault => vault.Name);
                runtimeServices.Container.Resolve <Printers>().AddCustomPrinter <VaultClass>(vault => vault.Name);
                runtimeServices.Container.Resolve <Printers>().AddCustomPrinter <MFSearchBuilder>(search => $"Search for {search.Vault.Name} ({search.Conditions.Count})");

                this._command = new HtmlExecuteReplCommand(config.ScriptName, scriptArgs, scriptServices);
                this._command.Repl.Initialize();
                this._command.Execute();
            }
            catch (Exception e)
            {
                Console.WriteLine("Failed to set up script services");
                Console.WriteLine(e);
            }
        }
Example #2
0
 public MFilesScriptHost(IScriptPackManager scriptPackManager, ScriptEnvironment environment, ScriptHostArguments arguments)
     : base(scriptPackManager, environment)
 {
     ListingItems = arguments.ListingItems;
     Vault        = arguments.Vault;
     Properties   = arguments.Properties;
 }
 public MFilesScriptHostFactory(ScriptHostArguments globs, IConsole console)
 {
     this._globs   = globs;
     this._console = console;
 }