1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
4 | *
|
---|
5 | * This file is part of HeuristicLab.
|
---|
6 | *
|
---|
7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
8 | * it under the terms of the GNU General Public License as published by
|
---|
9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
10 | * (at your option) any later version.
|
---|
11 | *
|
---|
12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | * GNU General Public License for more details.
|
---|
16 | *
|
---|
17 | * You should have received a copy of the GNU General Public License
|
---|
18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
19 | */
|
---|
20 | #endregion
|
---|
21 |
|
---|
22 | using HeuristicLab.Common.Resources;
|
---|
23 | using HeuristicLab.Scripting;
|
---|
24 | using System.Collections.Generic;
|
---|
25 | using System.Drawing;
|
---|
26 |
|
---|
27 | namespace HeuristicLab.OptimizationExpertSystem.Menu {
|
---|
28 | internal class NewCSharpScriptMenuItem : MenuItemBase {
|
---|
29 | public override Image Image { get { return VSImageLibrary.NewDocument; } }
|
---|
30 |
|
---|
31 | #region CodeTemplate
|
---|
32 | private static readonly string CodeTemplate = @"
|
---|
33 | // use 'vars' to access variables in the script's variable store (e.g. vars.x = 5)
|
---|
34 | // use 'vars[string]' to access variables via runtime strings (e.g. vars[""x""] = 5)
|
---|
35 | // use 'vars.Contains(string)' to check if a variable exists
|
---|
36 | // use 'vars.Clear()' to remove all variables
|
---|
37 | // use 'foreach (KeyValuePair<string, object> v in vars) { ... }' to iterate over all variables
|
---|
38 | // use 'variables' to work with IEnumerable<T> extension methods on the script's variable store
|
---|
39 |
|
---|
40 | using System;
|
---|
41 | using System.Linq;
|
---|
42 | using System.Collections.Generic;
|
---|
43 |
|
---|
44 | using QueryClient = HeuristicLab.Clients.OKB.Query.QueryClient;
|
---|
45 | using RunCreationClient = HeuristicLab.Clients.OKB.RunCreation.RunCreationClient;
|
---|
46 | using AdministrationClient = HeuristicLab.Clients.OKB.Administration.AdministrationClient;
|
---|
47 | using HeuristicLab.Core;
|
---|
48 | using HeuristicLab.Common;
|
---|
49 | using HeuristicLab.Collections;
|
---|
50 | using HeuristicLab.Data;
|
---|
51 | using HeuristicLab.Optimization;
|
---|
52 | using HeuristicLab.OptimizationExpertSystem;
|
---|
53 | using HeuristicLab.OptimizationExpertSystem.Common;
|
---|
54 | using HeuristicLab.Random;
|
---|
55 |
|
---|
56 | public class MyScript : HeuristicLab.Scripting.CSharpScriptBase {
|
---|
57 | public KnowledgeCenter Instance { get { return ((OptimizationKnowledgeCenter)HeuristicLab.MainForm.MainFormManager.MainForm).ExpertSystem; } }
|
---|
58 |
|
---|
59 | public override void Main() {
|
---|
60 | // type your code here
|
---|
61 | }
|
---|
62 |
|
---|
63 | // implement further classes and methods
|
---|
64 |
|
---|
65 | }";
|
---|
66 | #endregion
|
---|
67 |
|
---|
68 | public override string Name {
|
---|
69 | get { return "New"; }
|
---|
70 | }
|
---|
71 |
|
---|
72 | public override IEnumerable<string> Structure {
|
---|
73 | get { return new[] { "Tools", "C# Script" }; }
|
---|
74 | }
|
---|
75 |
|
---|
76 | public override int Position {
|
---|
77 | get { return 910; }
|
---|
78 | }
|
---|
79 |
|
---|
80 | public override string ToolTipText { get { return "Create a new C# Script"; } }
|
---|
81 |
|
---|
82 | public override void Execute() {
|
---|
83 | MainForm.ShowContent(new CSharpScript(CodeTemplate));
|
---|
84 | }
|
---|
85 | }
|
---|
86 | }
|
---|