private static void InitConfiguration() { #region SLAB var ObservableEventListener = new ObservableEventListener(); ObservableEventListener.EnableEvents(ControllerEvents.Log, EventLevel.LogAlways, Keywords.All); ObservableEventListener.EnableEvents(GlobalEvents.Log, EventLevel.LogAlways, Keywords.All); ObservableEventListener.EnableEvents(HubServerEvents.Log, EventLevel.LogAlways, Keywords.All); var formatter = new PrefixEventTextFormatter("-----------", null, "# ", @"yyyy-MM-dd hh\:mm\:ss\.fff"); ObservableEventListener.LogToConsole(formatter); #endregion //Hub孵化器 GlobalHost.DependencyResolver.Register(typeof(IHubActivator), () => new UnityHubActivator(UnityConfiguration.GetConfiguredContainer())); GlobalHost.HubPipeline.AddModule(new LoggingPipelineModule()); GlobalHost.HubPipeline.AddModule(new ErrorHandlingPipelineModule()); }
static void Main(string[] args) { #region SLAB var ObservableEventListener = new ObservableEventListener(); ObservableEventListener.EnableEvents(ControllerEvents.Log, EventLevel.LogAlways, Keywords.All); ObservableEventListener.EnableEvents(GlobalEvents.Log, EventLevel.LogAlways, Keywords.All); ObservableEventListener.EnableEvents(HubClientEvents.Log, EventLevel.LogAlways, Keywords.All); var formatter = new PrefixEventTextFormatter("-----------", null, "# ", @"yyyy-MM-dd hh\:mm\:ss\.fff"); ObservableEventListener.LogToConsole(formatter); #endregion string name = "AA"; var myHubClient = new MyHubClient(); while (true) { string key = Console.ReadLine(); if (key.ToUpper() == "A") { if (myHubClient.State == ConnectionState.Connected) { myHubClient.SendAllClient(name, "hello all"); } else { HubClientEvents.Log.Warning("Can't send message, connectionState= " + myHubClient.State); } } if (key.ToUpper() == "B") { if (myHubClient.State == ConnectionState.Connected) { myHubClient.SendToSingle(Console.ReadLine(), name, "hello world"); } else { HubClientEvents.Log.Warning("Can't send message, connectionState= " + myHubClient.State); } } if (key.ToUpper() == "H") { if (myHubClient.State == ConnectionState.Connected) { myHubClient.Heartbeat(); } else { HubClientEvents.Log.Warning("Can't send message, connectionState= " + myHubClient.State); } } if (key.ToUpper() == "S") { name = Console.ReadLine(); if (myHubClient.State == ConnectionState.Connected) { myHubClient.Subscribe(name); } else { HubClientEvents.Log.Warning("Can't send message, connectionState= " + myHubClient.State); } } if (key.ToUpper() == "Q") { if (myHubClient.State == ConnectionState.Connected) { myHubClient.Unsubscribe(name); } else { HubClientEvents.Log.Warning("Can't send message, connectionState= " + myHubClient.State); } } if (key.ToUpper() == "C") { myHubClient.CloseHub(); HubClientEvents.Log.Informational("Closed Hub"); } } }