Esempio n. 1
0
        private void lbxImportedNamespaces_KeyDown(object sender, KeyEventArgs e)
        {
            ListBox listBox = (ListBox)sender;

            if (e.KeyCode == Keys.Delete)
            {
                List <string> removaList = new List <string>();
                foreach (var item in listBox.SelectedItems)
                {
                    var pair = (KeyValuePair <string, List <AssemblyReference> >)item;
                    removaList.Add(pair.Key);
                }

                removaList.ForEach(x => ScriptContext.ImportedNamespaces.Remove(x));
                var importedNameSpacesBinding = new BindingSource(ScriptContext.ImportedNamespaces, null);
                lbxImportedNamespaces.DataSource = importedNameSpacesBinding;

                TypeMethods.GenerateAllVariableTypes(NamespaceMethods.GetAssemblies(ScriptContext.ImportedNamespaces), TypeContext.GroupedTypes);
                ScriptContext.LoadCompilerObjects();

                //marks the script as unsaved with changes
                if (uiScriptTabControl.SelectedTab != null && !uiScriptTabControl.SelectedTab.Text.Contains(" *"))
                {
                    uiScriptTabControl.SelectedTab.Text += " *";
                }
            }
            else
            {
                dgvVariablesArguments_KeyDown(null, e);
            }
        }
        public static ContainerBuilder LoadBuilder(List <string> assemblyPaths, Dictionary <string, List <Type> > groupedTypes, Dictionary <string, List <AssemblyReference> > allNamespaces,
                                                   Dictionary <string, List <AssemblyReference> > importedNamespaces)
        {
            List <Assembly> existingAssemblies = new List <Assembly>();

            foreach (var path in assemblyPaths)
            {
                try
                {
                    var name = AssemblyName.GetAssemblyName(path).Name;

                    var assemblies       = AppDomain.CurrentDomain.GetAssemblies();
                    var existingAssembly = assemblies.Where(x => x.GetName().Name == name &&
                                                            x.GetName().Version.ToString() == AssemblyName.GetAssemblyName(path).Version.ToString())
                                           .FirstOrDefault();

                    if (existingAssembly == null && name != "RestSharp" && name != "WebDriver" && name != "OpenBots.Core")
                    {
                        //has to be LoadFile because package manager can't update/uninstall assemblies if LoadFrom
                        var assembly = Assembly.LoadFrom(path);
                        existingAssemblies.Add(assembly);
                    }
                    else if (existingAssembly != null)
                    {
                        existingAssemblies.Add(existingAssembly);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }

            //TODO: limit types to one in loaded assemblies. Previously getting all assemblies instead of just the ones in existingAssemblies because mscorlib was missing
            TypeMethods.GenerateAllNamespaces(AppDomain.CurrentDomain.GetAssemblies().ToList(), allNamespaces);
            TypeMethods.GenerateAllVariableTypes(NamespaceMethods.GetAssemblies(importedNamespaces), groupedTypes);


            //if no commands have been loaded, at least include OpenBots.Core to access the BrokenCodeCommand
            if (existingAssemblies.Count == 0)
            {
                existingAssemblies.Add(Assembly.GetAssembly(typeof(BrokenCodeCommentCommand)));
            }

            ContainerBuilder builder = new ContainerBuilder();

            builder.RegisterAssemblyTypes(existingAssemblies.ToArray())
            .Where(t => t.IsAssignableTo <ScriptCommand>())
            .Named <ScriptCommand>(t => t.Name)
            .AsImplementedInterfaces();
            return(builder);
        }
Esempio n. 3
0
        private void cbxAllNamespaces_SelectionChangeCommitted(object sender, EventArgs e)
        {
            var pair = (KeyValuePair <string, List <AssemblyReference> >)cbxAllNamespaces.SelectedItem;

            if (!ScriptContext.ImportedNamespaces.ContainsKey(pair.Key))
            {
                ScriptContext.ImportedNamespaces.Add(pair.Key, pair.Value);
                var importedNameSpacesBinding = new BindingSource(ScriptContext.ImportedNamespaces, null);
                lbxImportedNamespaces.DataSource = importedNameSpacesBinding;

                TypeMethods.GenerateAllVariableTypes(NamespaceMethods.GetAssemblies(ScriptContext.ImportedNamespaces), TypeContext.GroupedTypes);
                ScriptContext.LoadCompilerObjects();

                //marks the script as unsaved with changes
                if (uiScriptTabControl.SelectedTab != null && !uiScriptTabControl.SelectedTab.Text.Contains(" *"))
                {
                    uiScriptTabControl.SelectedTab.Text += " *";
                }
            }
        }
Esempio n. 4
0
        private void ResetVariableArgumentBindings()
        {
            dgvVariables.DataSource = new BindingList <ScriptVariable>(ScriptContext.Variables);
            dgvArguments.DataSource = new BindingList <ScriptArgument>(ScriptContext.Arguments);

            TypeMethods.GenerateAllVariableTypes(NamespaceMethods.GetAssemblies(ScriptContext.ImportedNamespaces), TypeContext.GroupedTypes);

            var defaultTypesBinding = new BindingSource(TypeContext.DefaultTypes, null);

            variableType.DataSource = defaultTypesBinding;
            argumentType.DataSource = defaultTypesBinding;

            var importedNameSpacesBinding = new BindingSource(ScriptContext.ImportedNamespaces, null);

            lbxImportedNamespaces.DataSource = importedNameSpacesBinding;

            var allNameSpacesBinding = new BindingSource(AllNamespaces, null);

            cbxAllNamespaces.DataSource = allNameSpacesBinding;
        }