Beispiel #1
0
 /// <summary>
 /// Create a IExitHook list from a class names list using the provided configuration and service
 /// </summary>
 /// <param name="hookClassNames"></param>
 /// <param name="settings"></param>
 /// <param name="service"></param>
 public HookRepository(String hookClassNames, XmlConfig.XmlConfig settings, IRunAsService service)
 {
     _hookClassNames = hookClassNames;
     _settings = settings;
     _service = service;
     Reset();
 }
Beispiel #2
0
        /// <summary>
        /// Build a command using the settings and a name (for instance "Microsoft Word" for word.exe)
        /// </summary>
        /// <param name="settings">The available settings</param>
        /// <param name="commandName">The command name</param>
        /// <returns></returns>
        public virtual ICommand BuildCommand(XmlConfig.XmlConfig settings, String commandName)
        {
            if (settings == null)
            {
                Log.Error("Settings must be well set in the config file before trying to start the command.");
                throw new InvalidOperationException(
                    "Settings must be well set in the config file before trying to start the command.");
            }

            Log.Debug("Reading command configuration...");

            string executable = settings.GetItem("executable").Value;

            if (String.IsNullOrEmpty(executable))
            {
                Log.Error("Executable is mandatory to start the command.");
                throw new XmlConfigException("Executable is mandatory to start the command.");
            }

            // Parameter default value is empty
            string parameters = settings.GetItem("parameters").Value;

            // killProcessTree default value is false
            var item = settings.GetItem("killProcessTree");
            bool killChildren = String.IsNullOrEmpty(item.Value)
                                    ? false
                                    : item.BoolValue;

            return new Command(_processManager, commandName, executable, parameters, killChildren);
        }
Beispiel #3
0
        public RunAsService(XmlConfig.XmlConfig settings, HookRepository repository, CommandBuilder builder)
        {
            _repository = repository;
            _builder = builder;
            _settings = settings;

            InitProperties();
        }
Beispiel #4
0
 public void ShouldNotOpenAnUnknownFile()
 {
     _settings = new x.XmlConfig("unknown.files");
 }
Beispiel #5
0
 public void Init()
 {
     _settings = new x.XmlConfig();
     _settings.LoadXmlFromString("<a><b>" + BValue + "</b><c value=\"" + CValue + "\"/><d foo=\"bar\"/><e value=\"e1\" /><e value=\"e2\" /></a>");
 }
Beispiel #6
0
        private bool Init()
        {
            Log.Debug("Initialize from configuration file...");

            try
            {
                var currentDir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
                if (currentDir == null)
                    throw new IOException("Cannot retrieve the current assembly directory name.");
                _settings =
                    new XmlConfig.XmlConfig(
                        Path.Combine(currentDir,
                                     "configuration.xml"));

                InitProperties();

                _repository = new HookRepository(_settings.GetItem("exitHooks").Value, _settings, this);
                _builder = new CommandBuilder(new ProcessManager());

                return true;
            }
            catch (Exception ex)
            {
                Log.Error("Service can't be initialized", ex);
            }

            return false;
        }