Exemplo n.º 1
0
    /// <summary>
    /// Called to execute the supplied Macro.
    /// </summary>
    /// <param name="commandList">The command list.</param>
    /// <param name="variables">Variable List from calling code.</param>
    /// <param name="procCommand">Callback to the command handler from the calling code.</param>
    public static void ExecuteMacro(string[] commandList, VariableList variables, ProcessCommandCallback procCommand)
    {
      for (int position = 0; position < commandList.Length; position++)
      {
        string command = commandList[position];

        if (command.StartsWith(Common.CmdPrefixIf, StringComparison.OrdinalIgnoreCase))
        {
          string[] commands = Common.SplitIfCommand(command.Substring(Common.CmdPrefixIf.Length));

          if (commands[0].StartsWith(Common.VariablePrefix, StringComparison.OrdinalIgnoreCase))
            commands[0] = variables.GetVariable(commands[0].Substring(Common.VariablePrefix.Length));
          commands[0] = Common.ReplaceSpecialVariables(commands[0]);

          if (commands[2].StartsWith(Common.VariablePrefix, StringComparison.OrdinalIgnoreCase))
            commands[2] = variables.GetVariable(commands[2].Substring(Common.VariablePrefix.Length));
          commands[2] = Common.ReplaceSpecialVariables(commands[2]);

          if (EvaluateIfCommand(commands))
            position = GetLabelPosition(commandList, commands[3]);
          else if (!String.IsNullOrEmpty(commands[4]))
            position = GetLabelPosition(commandList, commands[4]);
        }
        else if (command.StartsWith(Common.CmdPrefixLabel, StringComparison.OrdinalIgnoreCase))
        {
          continue;
        }
        else if (command.StartsWith(Common.CmdPrefixGotoLabel, StringComparison.OrdinalIgnoreCase))
        {
          string label = command.Substring(Common.CmdPrefixGotoLabel.Length);
          position = GetLabelPosition(commandList, label);
        }
        else if (command.StartsWith(Common.CmdPrefixSetVar, StringComparison.OrdinalIgnoreCase))
        {
          string[] commands = Common.SplitSetVarCommand(command.Substring(Common.CmdPrefixSetVar.Length));

          string variable = commands[0].Substring(Common.VariablePrefix.Length);
          string value = Common.ReplaceSpecialVariables(commands[1]);

          variables.SetVariable(variable, value);
        }
        else if (command.Equals(Common.CmdPrefixClearVars, StringComparison.OrdinalIgnoreCase))
        {
          variables.Clear();
        }
        else if (command.StartsWith(Common.CmdPrefixSaveVars, StringComparison.OrdinalIgnoreCase))
        {
          variables.Save(command.Substring(Common.CmdPrefixSaveVars.Length));
        }
        else if (command.StartsWith(Common.CmdPrefixLoadVars, StringComparison.OrdinalIgnoreCase))
        {
          variables.Load(command.Substring(Common.CmdPrefixLoadVars.Length));
        }
        else
        {
          procCommand(command);
        }
      }
    }
Exemplo n.º 2
0
 /// <summary>
 /// Called to execute the supplied Macro.
 /// </summary>
 /// <param name="fileName">Macro file to process (absolute path).</param>
 /// <param name="variables">Variable List from calling code.</param>
 /// <param name="procCommand">Callback to the command handler from the calling code.</param>
 public static void ExecuteMacro(string fileName, VariableList variables, ProcessCommandCallback procCommand)
 {
   string[] commandList = ReadFromFile(fileName);
   ExecuteMacro(commandList, variables, procCommand);
 }
 /// <summary>
 /// Execute this command.
 /// </summary>
 /// <param name="variables">The variable list of the calling code.</param>
 public override void Execute(VariableList variables)
 {
   string[] processed = ProcessParameters(variables, Parameters);
   Keyboard.ProcessCommand(processed[0]);
 }
Exemplo n.º 4
0
    private static void Main(string[] args)
    {
      _connectionFailures = 0;
      _configFile = DefaultConfigFile;

      if (args.Length > 0)
      {
        try
        {
          if (ProcessCommandLine(args))
            return;
        }
        catch (CommandExecutionException ex)
        {
          MessageBox.Show(ex.Message, "Translator", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        catch (CommandStructureException ex)
        {
          MessageBox.Show(ex.Message, "Translator", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
        catch (Exception ex)
        {
          MessageBox.Show(ex.ToString(), "Translator - Error processing command line", MessageBoxButtons.OK,
                          MessageBoxIcon.Error);
        }
      }

      // Check for multiple instances.
      if (Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length != 1)
      {
        CopyDataWM.SendCopyDataMessage(Common.CmdPrefixShowTrayIcon);
        return;
      }

      Application.EnableVisualStyles();
      Application.SetCompatibleTextRenderingDefault(false);

      IrssLog.LogLevel = IrssLog.Level.Debug;
      IrssLog.Open("Translator.log");

      Application.ThreadException += Application_ThreadException;

      // Initialize Variable List.
      _variables = new VariableList();

      // Load configuration ...
      _config = Configuration.Load(_configFile);
      if (_config == null)
      {
        IrssLog.Warn("Failed to load configuration file ({0}), creating new configuration", _configFile);
        _config = new Configuration();
      }

      // Adjust process priority ...
      AdjustPriority(_config.ProcessPriority);


      //foreach (ProgramSettings progSettings in _config.Programs)
      //{
      //  AppProfile profile = new AppProfile();

      //  profile.Name = progSettings.Name;
      //  profile.MatchType = AppProfile.DetectionMethod.Executable;
      //  profile.MatchParameters = progSettings.FileName;
      //  profile.ButtonMappings.AddRange(progSettings.ButtonMappings);

      //  AppProfile.Save(profile, "C:\\" + profile.Name + ".xml");
      //}


      // Setup notify icon ...
      _container = new Container();
      _notifyIcon = new NotifyIcon(_container);
      _notifyIcon.ContextMenuStrip = new ContextMenuStrip();
      _notifyIcon.Icon = Resources.Icon16Connecting;
      _notifyIcon.Text = "Translator - Connecting ...";
      _notifyIcon.DoubleClick += ClickSetup;
      _notifyIcon.Visible = !_config.HideTrayIcon;

      // Setup the main form ...
      _mainForm = new MainForm();

      // Start server communications ...
      bool clientStarted = false;

      IPAddress serverIP = Network.GetIPFromName(_config.ServerHost);
      IPEndPoint endPoint = new IPEndPoint(serverIP, Server.DefaultPort);

      try
      {
        clientStarted = StartClient(endPoint);
      }
      catch (Exception ex)
      {
        IrssLog.Error(ex);
        clientStarted = false;
      }

      if (clientStarted)
      {
        // Setup event notification ...
        SystemEvents.SessionEnding += SystemEvents_SessionEnding;
        SystemEvents.PowerModeChanged += SystemEvents_PowerModeChanged;

        try
        {
          _copyDataWM = new CopyDataWM();
          _copyDataWM.Start();
        }
        catch (Win32Exception ex)
        {
          IrssLog.Error("Error enabling CopyData messages: {0}", ex.ToString());
        }

        Application.Run();

        if (_copyDataWM != null)
        {
          _copyDataWM.Dispose();
          _copyDataWM = null;
        }

        SystemEvents.SessionEnding -= SystemEvents_SessionEnding;
        SystemEvents.PowerModeChanged -= SystemEvents_PowerModeChanged;

        StopClient();
      }
      else
      {
        MessageBox.Show("Failed to start IR Server communications, refer to log file for more details.",
                        "Translator - Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

        _inConfiguration = true;

        _mainForm.ShowDialog();

        _inConfiguration = false;
      }

      // Dispose NotifyIcon ...
      _notifyIcon.Visible = false;
      _notifyIcon.Dispose();
      _notifyIcon = null;

      // Dispose Container ...
      _container.Dispose();
      _container = null;

      Application.ThreadException -= Application_ThreadException;

      IrssLog.Close();
    }
Exemplo n.º 5
0
        /// <summary>
        /// Called to execute the supplied Macro.
        /// </summary>
        /// <param name="commandList">The command list.</param>
        /// <param name="variables">Variable List from calling code.</param>
        /// <param name="procCommand">Callback to the command handler from the calling code.</param>
        public static void ExecuteMacro(string[] commandList, VariableList variables, ProcessCommandCallback procCommand)
        {
            for (int position = 0; position < commandList.Length; position++)
            {
                string command = commandList[position];

                if (command.StartsWith(Common.CmdPrefixIf, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitIfCommand(command.Substring(Common.CmdPrefixIf.Length));

                    if (commands[0].StartsWith(Common.VariablePrefix, StringComparison.OrdinalIgnoreCase))
                    {
                        commands[0] = variables.GetVariable(commands[0].Substring(Common.VariablePrefix.Length));
                    }
                    commands[0] = Common.ReplaceSpecialVariables(commands[0]);

                    if (commands[2].StartsWith(Common.VariablePrefix, StringComparison.OrdinalIgnoreCase))
                    {
                        commands[2] = variables.GetVariable(commands[2].Substring(Common.VariablePrefix.Length));
                    }
                    commands[2] = Common.ReplaceSpecialVariables(commands[2]);

                    if (EvaluateIfCommand(commands))
                    {
                        position = GetLabelPosition(commandList, commands[3]);
                    }
                    else if (!String.IsNullOrEmpty(commands[4]))
                    {
                        position = GetLabelPosition(commandList, commands[4]);
                    }
                }
                else if (command.StartsWith(Common.CmdPrefixLabel, StringComparison.OrdinalIgnoreCase))
                {
                    continue;
                }
                else if (command.StartsWith(Common.CmdPrefixGotoLabel, StringComparison.OrdinalIgnoreCase))
                {
                    string label = command.Substring(Common.CmdPrefixGotoLabel.Length);
                    position = GetLabelPosition(commandList, label);
                }
                else if (command.StartsWith(Common.CmdPrefixSetVar, StringComparison.OrdinalIgnoreCase))
                {
                    string[] commands = Common.SplitSetVarCommand(command.Substring(Common.CmdPrefixSetVar.Length));

                    string variable = commands[0].Substring(Common.VariablePrefix.Length);
                    string value    = Common.ReplaceSpecialVariables(commands[1]);

                    variables.SetVariable(variable, value);
                }
                else if (command.Equals(Common.CmdPrefixClearVars, StringComparison.OrdinalIgnoreCase))
                {
                    variables.Clear();
                }
                else if (command.StartsWith(Common.CmdPrefixSaveVars, StringComparison.OrdinalIgnoreCase))
                {
                    variables.Save(command.Substring(Common.CmdPrefixSaveVars.Length));
                }
                else if (command.StartsWith(Common.CmdPrefixLoadVars, StringComparison.OrdinalIgnoreCase))
                {
                    variables.Load(command.Substring(Common.CmdPrefixLoadVars.Length));
                }
                else
                {
                    procCommand(command);
                }
            }
        }
Exemplo n.º 6
0
 /// <summary>
 /// Called to execute the supplied Macro.
 /// </summary>
 /// <param name="fileName">Macro file to process (absolute path).</param>
 /// <param name="variables">Variable List from calling code.</param>
 /// <param name="procCommand">Callback to the command handler from the calling code.</param>
 public static void ExecuteMacro(string fileName, VariableList variables, ProcessCommandCallback procCommand)
 {
     string[] commandList = ReadFromFile(fileName);
     ExecuteMacro(commandList, variables, procCommand);
 }