コード例 #1
0
        public void Watch()
        {
            var person = new Person("Adult1", 50);

            _source.AddOrUpdate(person);

            var result = new List <Change <Person, string> >(3);
            var watch  = _watcher.Watch("Adult1").Subscribe(result.Add);

            _scheduler.AdvanceBy(TimeSpan.FromMilliseconds(50).Ticks);
            Assert.AreEqual(1, result.Count, "Should be 1 updates");
            Assert.AreEqual(person, result[0].Current, "Should be 1 item in the cache");

            _source.Edit(updater => updater.Remove(("Adult1")));
            _scheduler.AdvanceBy(TimeSpan.FromMilliseconds(500).Ticks);

            watch.Dispose();
        }
コード例 #2
0
ファイル: Bootstrap.cs プロジェクト: approvers/twatch
 protected override Task ExecuteAsync(CancellationToken stoppingToken)
 {
     return(Task.Run(() =>
     {
         foreach (var message in _watcher.Watch())
         {
             _reporter.Report(message).Wait(stoppingToken);
         }
     }, stoppingToken));
 }
コード例 #3
0
        private void CreateDstStateWatcher()
        {
            if (!_bindingWayType.HasFlag(BindingWayType.DestinationToSource))
            {
                return;
            }

            _dstWatcher = new StateWatcher <MonoPropertyReference>(_destination, o => o.Get());
            _dstWatcher.Watch().Subscribe(DstStateChanged);
        }
コード例 #4
0
        private void CreateSrcStateWatcher()
        {
            if (!_bindingWayType.HasFlag(BindingWayType.SourceToDestination))
            {
                return;
            }

            _srcWatcher = new StateWatcher <MonoPropertyReference>(_source, o => o.Get());
            _srcWatcher.Watch().Subscribe(SrcStateChanged);
        }
コード例 #5
0
        protected virtual void Watch(ServiceRegistryMetta metta)
        {
            if (_watcher == null)
            {
                return;
            }

            _watcher.Watch(metta.ServerAddress, new WatcherOptions
            {
                ServiceMetta = metta
            });
        }
コード例 #6
0
        public void SetUp()
        {
            _scheduler = new TestScheduler();
            _source    = new SourceCache <Person, string>(p => p.Key);
            _watcher   = _source.Connect().AsWatcher(_scheduler);

            _results = new ChangeSetAggregator <SelfObservingPerson, string>
                       (
                _source.Connect()
                .Transform(p => new SelfObservingPerson(_watcher.Watch(p.Key).Select(w => w.Current)))
                .DisposeMany()
                       );

            _cleanUp = Disposable.Create(() =>
            {
                _results.Dispose();
                _source.Dispose();
                _watcher.Dispose();
            });
        }
コード例 #7
0
        public void SetUp()
        {
            _scheduler = new TestScheduler();
            _source = new SourceCache<Person, string>(p => p.Key);
            _watcher = _source.Connect().AsWatcher(_scheduler);

            _results = new ChangeSetAggregator<SelfObservingPerson, string>
                (
                _source.Connect()
                    .Transform(p => new SelfObservingPerson(_watcher.Watch(p.Key).Select(w => w.Current)))
                    .DisposeMany()
                );

            _cleanUp = Disposable.Create(() =>
            {
                _results.Dispose();
                _source.Dispose();
                _watcher.Dispose();
            });
        }
コード例 #8
0
        public void PingReachableHostTest()
        {
            const bool   expectedStatus = true;
            const string targetHost     = "google.com";
            const bool   anyStatus      = true;

            IWatcher pingWatcher = GetPingWatcher(anyStatus, targetHost);

            pingWatcher.LoggingService =
                ServicesContainer.ServicesProvider.GetLoggingService(nameof(PingStatusWatcher));

            var watcherResult = pingWatcher.Watch();

            Assert.IsNotNull(watcherResult);
            Assert.IsTrue(watcherResult.Result);
            Assert.IsTrue(watcherResult.WatchingArguments.HasArgument(PingStatusWatcherResultArgs.IsReachable));
            Assert.IsInstanceOfType(watcherResult.WatchingArguments[PingStatusWatcherResultArgs.IsReachable], typeof(bool));
            var status = watcherResult.WatchingArguments.GetValue <bool>(PingStatusWatcherResultArgs.IsReachable);

            Assert.AreEqual(expectedStatus, status);
        }
コード例 #9
0
ファイル: Runner.cs プロジェクト: vhil/Leprechaun
        public void Run(IRuntimeArgs parsedArgs)
        {
            // RUN LEPRECHAUN
            if (!parsedArgs.NoSplash)
            {
                Ascii.Leprechaun();
            }

            var appRunTimer = new Stopwatch();

            appRunTimer.Start();

            var configuration = BuildConfiguration(parsedArgs);

            // start pre-compiling templates (for Roslyn provider anyway)
            // this lets C# be compiling in the background while we read the files to generate from disk
            // and saves time
            var preload = Task.Run(() =>
            {
                foreach (var config in configuration.Configurations)
                {
                    config.Resolve <ICodeGenerator>();
                }
            });

            // the orchestrator controls the overall codegen flow
            var orchestrator = configuration.Shared.Resolve <IOrchestrator>();

            var metadata = GenerateMetadata(orchestrator, configuration);

            // make sure we're done preloading the compiled codegen templates
            preload.Wait();

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine($"Code generator has loaded in {appRunTimer.ElapsedMilliseconds}ms.");
            Console.ResetColor();

            GenerateCode(metadata);

            if (parsedArgs.Watch)
            {
                IWatcher watcher = configuration.Shared.Resolve <IWatcher>();
                if (watcher == null)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Unable to watch because no IWatcher was defined!");
                }
                else
                {
                    Console.WriteLine();
                    Console.WriteLine("Leprechaun is now watching for file changes and rebuilding at need.");
                    Console.WriteLine("Press Ctrl-C to exit.");
                    watcher.Watch(configuration, new ConsoleLogger(), () => GenerateWatch(orchestrator, configuration));
                    var exit = new ManualResetEvent(false);
                    exit.WaitOne();
                }
            }

            appRunTimer.Stop();
            Console.WriteLine();
            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine($"Leprechaun has completed in {appRunTimer.ElapsedMilliseconds}ms.");
            Console.ResetColor();
        }
コード例 #10
0
 public void Start()
 {
     _watcher.Watch();
     _watcher.ItemRead += WatcherItemRead;
 }
コード例 #11
0
 public EXPRESSIONTYPE WatchWith([NotNull] IWatcher watcher)
 {
     watcher.Watch(_element);
     return(ThisExpression());
 }