Esempio n. 1
0
 public Commands(Config cfg)
 {
     config = cfg;
     commands = new Dictionary<string, Type>();
     // Считаем что они все лежат в нашей сборке
     // MEF не применяем, т.к. нам нужен список типов, а не экземпляров (экземпляр сделаем по требованию)
     Type[] types = this.GetType().Assembly.GetTypes();
     foreach (var t in types)
     {
         if (t.GetInterface("ICommand") == typeof(ICommand))
         {
             // Получаем все ContractAttribute
             var attr = System.Attribute.GetCustomAttributes(t, false).Where(a => a.GetType() == typeof(KeywordAttribute));
             foreach (var a in attr)
             {
                 var name = ((KeywordAttribute)a).Name;
                 if (!commands.ContainsKey(name))
                     commands.Add(name, t);
             }
         }
     }
 }
Esempio n. 2
0
 /// <summary>
 /// Загрузить скрипты из файла
 /// </summary>
 /// <param name="cfg">Ссылка на объект конфигурации</param>
 /// <param name="commands">Ссылка на список команд</param>
 /// <returns>Список скриптов</returns>
 public static Script[] LoadScript(Config cfg, Commands commands)
 {
     InitScript(commands);
     var scripts = new List<Script>();
     var a = System.IO.File.ReadAllText(@"mine.script").Split('\n');
     Script current = null;
     foreach (var s in a)
     {
         if (!string.IsNullOrWhiteSpace(s))
         {
             var st = s.Trim();
             if (!(st.StartsWith("#") || st.StartsWith("//")))
             {
                 // Начало блока скрипта с переменной
                 if (st.StartsWith("@"))
                 {
                     var p = st.IndexOf(':');
                     if (p < 0)
                         Program.log.Error("Script name definition error {0}", s);
                     else
                     {
                         var sn = st.Substring(1, p - 1).Trim();
                         if (!scripts.Exists(m => m.Name == sn))
                         {
                             current = new Script(sn);
                             current.Parse(st.Substring(p + 1));
                             scripts.Add(current);
                         }
                         else
                         {
                             Program.log.Error("Duplicate script {0}", s);
                         }
                     }
                 }
                 else if (current == null)
                 {
                     // До первого скрипта - блок глобальных параметров
                     cfg.ReadConfig(st);
                 }
                 else
                     // После заголовка скрипта всё относится к нему
                     current.Parse(s);
             }
         }
     }
     return scripts.ToArray();
 }
Esempio n. 3
0
 public Window(Config config)
 {
     this.config = config;
 }
Esempio n. 4
0
 public SetModeCommand(string name, Config cfg)
 {
     Name = name; Cfg = cfg;
 }
Esempio n. 5
0
 public MatchCommand(string name, Config cfg)
 {
     Name = name; Cfg = cfg;
 }
Esempio n. 6
0
 public PressCommand(string name, Config cfg)
 {
     Name = name; Cfg = cfg; doubleClick = false;
 }
Esempio n. 7
0
 public PositionCommand(string name, Config cfg)
 {
     Name = name; Cfg = cfg; Pos = Position.Center;
 }
Esempio n. 8
0
 public FieldDetected(string name, Config cfg)
 {
     Name = name; Cfg = cfg;
 }
Esempio n. 9
0
 public FieldCells(string name, Config cfg)
 {
     Name = name; Cfg = cfg;
     nums = new GImage[10];
     nums[1] = ToGray(global::kmine.Properties.Resources._1);
     nums[2] = ToGray(global::kmine.Properties.Resources._2);
     nums[3] = ToGray(global::kmine.Properties.Resources._3);
 }