public void PopulateExecutionCommands(List <ScriptAction> commandDetails) { foreach (ScriptAction item in commandDetails) { if (item.ScriptCommand != null) { _selectedTabScriptActions.Items.Add(CreateScriptCommandListViewItem(item.ScriptCommand)); } else { var brokenCodeCommentCommand = new BrokenCodeCommentCommand(); brokenCodeCommentCommand.v_Comment = item.SerializationError; _selectedTabScriptActions.Items.Add(CreateScriptCommandListViewItem(brokenCodeCommentCommand)); } if (item.AdditionalScriptCommands?.Count > 0) { PopulateExecutionCommands(item.AdditionalScriptCommands); } } if (pnlCommandHelper.Visible) { uiScriptTabControl.SelectedTab.Controls.Remove(pnlCommandHelper); uiScriptTabControl.SelectedTab.Controls[0].Show(); } else if (!uiScriptTabControl.SelectedTab.Controls[0].Visible) { uiScriptTabControl.SelectedTab.Controls[0].Show(); } }
public void CreateOpenBotsProject(string mainScriptName, string mainScriptPath) { //create OpenBots specific project UIListView mainScriptActions = NewLstScriptActions(mainScriptName); List <ScriptVariable> mainScriptVariables = new List <ScriptVariable>(); List <ScriptArgument> mainScriptArguments = new List <ScriptArgument>(); List <ScriptElement> mainScriptElements = new List <ScriptElement>(); Dictionary <string, List <AssemblyReference> > mainImportedNamespaces = new Dictionary <string, List <AssemblyReference> >(ScriptDefaultNamespaces.DefaultNamespaces); try { dynamic helloWorldCommand = TypeMethods.CreateTypeInstance(AContainer, "ShowMessageCommand"); helloWorldCommand.v_Message = "\"Hello World\""; mainScriptActions.Items.Insert(0, CreateScriptCommandListViewItem(helloWorldCommand)); } catch (Exception) { var brokenHelloWorldCommand = new BrokenCodeCommentCommand(); brokenHelloWorldCommand.v_Comment = "Hello World"; mainScriptActions.Items.Insert(0, CreateScriptCommandListViewItem(brokenHelloWorldCommand)); } //begin saving as main.xml ClearSelectedListViewItems(); try { //serialize main script EngineContext engineContext = new EngineContext { Variables = mainScriptVariables, Arguments = mainScriptArguments, Elements = mainScriptElements, ImportedNamespaces = mainImportedNamespaces, FilePath = mainScriptPath, Container = AContainer }; var mainScript = Script.SerializeScript(mainScriptActions.Items, engineContext); _mainFileName = ScriptProject.Main; OpenOpenBotsFile(mainScriptPath); } catch (Exception ex) { Notify("An Error Occurred: " + ex.Message, Color.Red); } }
private void tsmiNewScriptFile_Click(object sender, EventArgs e) { try { string newName = ""; var newNameForm = new frmInputBox("Enter the name of the new file WITH extension", "New File"); switch (ScriptProject.ProjectType) { case ProjectType.OpenBots: newNameForm.txtInput.Text = ".obscript"; break; case ProjectType.Python: newNameForm.txtInput.Text = ".py"; break; case ProjectType.TagUI: newNameForm.txtInput.Text = ".tag"; break; case ProjectType.CSScript: newNameForm.txtInput.Text = ".cs"; break; } newNameForm.ShowDialog(); if (newNameForm.DialogResult == DialogResult.OK) { newName = newNameForm.txtInput.Text; newNameForm.Dispose(); } else if (newNameForm.DialogResult == DialogResult.Cancel) { newNameForm.Dispose(); return; } if (!Path.HasExtension(newName)) { throw new FileFormatException($"No extension provided for '{newName}'"); } string selectedNodePath = tvProject.SelectedNode.Tag.ToString(); string newFilePath = Path.Combine(selectedNodePath, newName); string extension = Path.GetExtension(newFilePath); if (File.Exists(newFilePath)) { int count = 1; string newerFilePath = newFilePath; while (File.Exists(newerFilePath)) { string newDirectoryPath = Path.GetDirectoryName(newFilePath); string newFileNameWithoutExtension = Path.GetFileNameWithoutExtension(newFilePath); newerFilePath = Path.Combine(newDirectoryPath, $"{newFileNameWithoutExtension} ({count}){extension}"); count += 1; } newFilePath = newerFilePath; } switch (extension.ToLower()) { case ".obscript": UIListView newScriptActions = NewLstScriptActions(); List <ScriptVariable> newScriptVariables = new List <ScriptVariable>(); List <ScriptArgument> newScriptArguments = new List <ScriptArgument>(); List <ScriptElement> newScriptElements = new List <ScriptElement>(); try { dynamic helloWorldCommand = TypeMethods.CreateTypeInstance(AContainer, "ShowMessageCommand"); helloWorldCommand.v_Message = "Hello World"; newScriptActions.Items.Insert(0, CreateScriptCommandListViewItem(helloWorldCommand)); } catch (Exception) { var brokenHelloWorldCommand = new BrokenCodeCommentCommand(); brokenHelloWorldCommand.v_Comment = "Hello World"; newScriptActions.Items.Insert(0, CreateScriptCommandListViewItem(brokenHelloWorldCommand)); } EngineContext engineContext = new EngineContext { Variables = newScriptVariables, Arguments = newScriptArguments, Elements = newScriptElements, FilePath = newFilePath, Container = AContainer }; Script.SerializeScript(newScriptActions.Items, engineContext); NewNode(tvProject.SelectedNode, newFilePath, "file"); OpenOpenBotsFile(newFilePath); break; case ".py": File.WriteAllText(newFilePath, _helloWorldTextPython); NewNode(tvProject.SelectedNode, newFilePath, "file"); OpenTextEditorFile(newFilePath, ProjectType.Python); break; case ".tag": File.WriteAllText(newFilePath, _helloWorldTextTagUI); NewNode(tvProject.SelectedNode, newFilePath, "file"); OpenTextEditorFile(newFilePath, ProjectType.TagUI); break; case ".cs": File.WriteAllText(newFilePath, _helloWorldTextCSScript); NewNode(tvProject.SelectedNode, newFilePath, "file"); OpenTextEditorFile(newFilePath, ProjectType.CSScript); break; default: File.Create(newFilePath).Close(); NewNode(tvProject.SelectedNode, newFilePath, "file"); return; } } catch (Exception ex) { Notify("An Error Occured: " + ex.Message, Color.Red); } }