/// <summary> /// The setup. /// </summary> protected override void Setup() { // log4net log4net.GlobalContext.Properties["Photon:ApplicationLogPath"] = Path.Combine(this.ApplicationRootPath, "log"); string path = Path.Combine(this.BinaryPath, "log4net.config"); var file = new FileInfo(path); if (file.Exists) { LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance); XmlConfigurator.ConfigureAndWatch(file); } try { if (PhotonSettings.Default.CounterPublisher.Enabled) { this.counterPublisher = new CounterPublisher(PhotonSettings.Default.CounterPublisher); this.counterPublisher.AddStaticCounterClass(typeof(SystemCounter), "System"); this.counterPublisher.AddStaticCounterClass(typeof(SocketServerCounter), "SocketServer"); if (log.IsDebugEnabled) { log.Debug("Starting counter publisher"); } this.counterPublisher.Start(); } } catch (Exception ex) { log.Error(ex); } }
/// <summary> /// The setup. /// </summary> protected override void Setup() { // log4net log4net.GlobalContext.Properties["Photon:ApplicationLogPath"] = Path.Combine(this.ApplicationRootPath, "log"); string path = Path.Combine(this.BinaryPath, "log4net.config"); var file = new FileInfo(path); if (file.Exists) { LogManager.SetLoggerFactory(Log4NetLoggerFactory.Instance); XmlConfigurator.ConfigureAndWatch(file); } try { this.counterPublisher = new CounterPublisher(PhotonSettings.Default.CounterPublisher); if (PhotonSettings.Default.CounterPublisher.Enabled) { CounterPublisher.DefaultInstance.AddStaticCounterClass(typeof(SystemCounter), "System"); CounterPublisher.DefaultInstance.AddStaticCounterClass(typeof(SocketServerCounter), "SocketServer"); foreach (KeyValuePair<string, PerformanceCounterReader> entry in SystemCounter.GetInstanceCounters()) { CounterPublisher.DefaultInstance.AddCounter(entry.Value, string.Format("System.{0}", entry.Key)); } CounterPublisher.DefaultInstance.Start(); } } catch (Exception ex) { log.Error(ex); } }
private async static Task Run(string wsuri, string realm) { Console.WriteLine("Connecting to {0}, realm {1}", wsuri, realm); WampChannelFactory factory = new WampChannelFactory(); IWampChannel channel = factory.ConnectToRealm(realm) .WebSocketTransport(wsuri) .JsonSerialization() .Build(); IWampClientConnectionMonitor monitor = channel.RealmProxy.Monitor; monitor.ConnectionBroken += OnClose; monitor.ConnectionError += OnError; await channel.Open().ConfigureAwait(false); IWampRealmServiceProvider services = channel.RealmProxy.Services; // SUBSCRIBE to a topic and receive events HelloSubscriber subscriber = new HelloSubscriber(); IAsyncDisposable subscriptionDisposable = await services.RegisterSubscriber(subscriber) .ConfigureAwait(false); Console.WriteLine("subscribed to topic 'onhello'"); // REGISTER a procedure for remote calling Add2Service callee = new Add2Service(); IAsyncDisposable registrationDisposable = await services.RegisterCallee(callee) .ConfigureAwait(false); Console.WriteLine("procedure add2() registered"); // PUBLISH and CALL every second... forever CounterPublisher publisher = new CounterPublisher(); IDisposable publisherDisposable = channel.RealmProxy.Services.RegisterPublisher(publisher); IMul2Service proxy = services.GetCalleeProxy <IMul2Service>(); int counter = 0; while (true) { // PUBLISH an event publisher.Publish(counter); Console.WriteLine("published to 'oncounter' with counter {0}", counter); counter++; // CALL a remote procedure try { int result = await proxy.Multiply(counter, 3) .ConfigureAwait(false); Console.WriteLine("mul2() called with result: {0}", result); } catch (WampException ex) { if (ex.ErrorUri != "wamp.error.no_such_procedure") { Console.WriteLine("call of mul2() failed: " + ex); } } await Task.Delay(TimeSpan.FromSeconds(1)) .ConfigureAwait(false); } }
/// <summary> /// The tear down. /// </summary> protected override void TearDown() { this.counterPublisher = null; }