#region License Information /* HeuristicLab * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HeuristicLab.Common.Resources; using HeuristicLab.Scripting; using System.Collections.Generic; using System.Drawing; namespace HeuristicLab.OptimizationExpertSystem.Menu { internal class NewCSharpScriptMenuItem : MenuItemBase { public override Image Image { get { return VSImageLibrary.NewDocument; } } #region CodeTemplate private static readonly string CodeTemplate = @" // use 'vars' to access variables in the script's variable store (e.g. vars.x = 5) // use 'vars[string]' to access variables via runtime strings (e.g. vars[""x""] = 5) // use 'vars.Contains(string)' to check if a variable exists // use 'vars.Clear()' to remove all variables // use 'foreach (KeyValuePair v in vars) { ... }' to iterate over all variables // use 'variables' to work with IEnumerable extension methods on the script's variable store using System; using System.Linq; using System.Collections.Generic; using QueryClient = HeuristicLab.Clients.OKB.Query.QueryClient; using RunCreationClient = HeuristicLab.Clients.OKB.RunCreation.RunCreationClient; using AdministrationClient = HeuristicLab.Clients.OKB.Administration.AdministrationClient; using HeuristicLab.Core; using HeuristicLab.Common; using HeuristicLab.Collections; using HeuristicLab.Data; using HeuristicLab.Optimization; using HeuristicLab.OptimizationExpertSystem; using HeuristicLab.OptimizationExpertSystem.Common; using HeuristicLab.Random; public class MyScript : HeuristicLab.Scripting.CSharpScriptBase { public KnowledgeCenter Instance { get { return ((OptimizationKnowledgeCenter)HeuristicLab.MainForm.MainFormManager.MainForm).ExpertSystem; } } public override void Main() { // type your code here } // implement further classes and methods }"; #endregion public override string Name { get { return "New"; } } public override IEnumerable Structure { get { return new[] { "Tools", "C# Script" }; } } public override int Position { get { return 910; } } public override string ToolTipText { get { return "Create a new C# Script"; } } public override void Execute() { MainForm.ShowContent(new CSharpScript(CodeTemplate)); } } }