コード例 #1
0
        public CommandResult Execute()
        {
            _fileSystemMigrator.Migrate();

            _console.WriteLine("scriptcs (ctrl-c to exit)");
            _logger.InfoFormat("Running script '{0}' and watching for changes...", _commandArgs.ScriptName);

            while (true)
            {
                using (var fileChanged = new ManualResetEventSlim())
                using (var watcher = new FileWatcher(_commandArgs.ScriptName, 500, _fileSystem))
                {
                    _logger.DebugFormat("Creating app domain '{0}'...", _commandArgs.ScriptName);
                    var appDomain = AppDomain.CreateDomain(_commandArgs.ScriptName, null, _setup);
                    try
                    {
                        watcher.Changed += (sender, e) =>
                        {
                            _logger.DebugFormat("Script '{0}' changed.", _commandArgs.ScriptName);
                            EnsureUnloaded(appDomain);
                            fileChanged.Set();
                        };

                        watcher.Start();
                        _logger.DebugFormat("Executing script '{0}' and watching for changes...", _commandArgs.ScriptName);
                        fileChanged.Reset();
                        try
                        {
                            appDomain.DoCallBack(_executeScriptCommand.Execute);
                        }
                        catch (AppDomainUnloadedException ex)
                        {
                            _logger.DebugFormat("App domain '{0}' has been unloaded.", ex, _commandArgs.ScriptName);
                        }
                    }
                    finally
                    {
                        EnsureUnloaded(appDomain);
                    }

                    fileChanged.Wait();
                    _logger.InfoFormat("Script changed. Reloading...", _commandArgs.ScriptName);
                }
            }
        }
コード例 #2
0
        public CommandResult Execute()
        {
            _console.WriteLine("scriptcs (ctrl-c to exit)");
            _logger.InfoFormat("Running script '{0}' and watching for changes...", _config.ScriptName);

            while (true)
            {
                using (var fileChanged = new ManualResetEventSlim())
                    using (var watcher = new FileWatcher(_config.ScriptName, 500, _fileSystem))
                    {
                        _logger.DebugFormat("Creating app domain '{0}'...", _config.ScriptName);
                        var appDomain = AppDomain.CreateDomain(_config.ScriptName, null, _setup);
                        try
                        {
                            watcher.Changed += (sender, e) =>
                            {
                                _logger.DebugFormat("Script '{0}' changed.", _config.ScriptName);
                                EnsureUnloaded(appDomain);
                                fileChanged.Set();
                            };

                            watcher.Start();
                            _logger.DebugFormat("Executing script '{0}' and watching for changes...", _config.ScriptName);
                            fileChanged.Reset();
                            try
                            {
                                appDomain.DoCallBack(_executeScriptCommand.Execute);
                            }
                            catch (AppDomainUnloadedException ex)
                            {
                                _logger.DebugFormat("App domain '{0}' has been unloaded.", ex, _config.ScriptName);
                            }
                        }
                        finally
                        {
                            EnsureUnloaded(appDomain);
                        }

                        fileChanged.Wait();
                        _logger.InfoFormat("Script changed. Reloading...", _config.ScriptName);
                    }
            }
        }