Exemple #1
0
        public void LiveConfig_FileChanged_ChangedEventRaised()
        {
            bool success = false;
            var  config  = new LiveConfig <ConfigObject>(_file);

            config.Changed += () => success = true;

            config.Watch();

            File.WriteAllText(_file, @"{ ""Test"": ""Test"" }");

            Assert.IsTrue(success);
        }
Exemple #2
0
        public async Task LiveConfig_FileChanged_ConfigUpdated()
        {
            var tcs    = new TaskCompletionSource <bool>();
            var config = new LiveConfig <ConfigObject>(_file);

            config.Changed += () => tcs.SetResult(true);
            config.Watch();

            File.WriteAllText(_file, @"{ ""Test"": ""Test"" }");

            if (await Task.WhenAny(tcs.Task, Task.Delay(2000)) == tcs.Task)
            {
                Assert.IsTrue(config.Configuration.Test == "Test");
            }
            else
            {
                throw new Exception();
            }
        }
Exemple #3
0
        public BuildVM(IBuildRepository buildRepo, Logger.Logger logger)
        {
            if (buildRepo == null)
            {
                throw new ArgumentNullException(nameof(buildRepo));
            }
            if (logger == null)
            {
                throw new ArgumentNullException(nameof(logger));
            }

            _buildRepo = buildRepo;
            _logger    = logger;
            Items      = new ObservableCollection <BuildResult>();

            try
            {
                _liveConfig              = new LiveConfig <List <BuildConfig> >("config.json");
                _liveConfig.Changed     += initializeItems;
                _liveConfig.Unavailable += () =>
                {
                    Items.Clear();
                    _currentIndex = 0;
                };
                _liveConfig.Watch();

                var timer = new Timer();
                timer.Interval = 1000;
                timer.Elapsed += change;
                timer.Start();

                var dateTimer = new Timer();
                dateTimer.Interval = 1000;
                dateTimer.Elapsed += (s, e) => CurrentTime = DateTime.Now;
                dateTimer.Start();
            }
            catch (Exception ex)
            {
                _logger.Log(LogLevel.Info, ex);
            }
        }