当前位置: 首页>>代码示例>>C#>>正文


C# IHubProxy.On方法代码示例

本文整理汇总了C#中IHubProxy.On方法的典型用法代码示例。如果您正苦于以下问题:C# IHubProxy.On方法的具体用法?C# IHubProxy.On怎么用?C# IHubProxy.On使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IHubProxy的用法示例。


在下文中一共展示了IHubProxy.On方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ConnectAsync

        public void ConnectAsync()
        {
            Connection = new HubConnection("http://54.69.68.144:8733/signalr");
            HubProxy = Connection.CreateHubProxy("ChatHub");
            //Handle incoming event from server: use Invoke to write to console from SignalR's thread

            HubProxy.On<string>("AddMessage", (msg) =>
                    Console.WriteLine("AddMessage Call: " + msg)
            );
            HubProxy.On<string>("GetAllMessage", (s) =>
                    Console.WriteLine(String.Format("{0}: {1}", Environment.NewLine, s))
            );
            HubProxy.On<int>("GetNumberOfUsers",(s) =>
                Console.WriteLine(s)
            )
            ;
            try
            {
                Connection.Start().Wait();
            }
            catch (HttpRequestException)
            {
                Console.WriteLine("Unable to connect to server: Start server before connecting clients.");
            }

            //HubProxy.Invoke("GetAllMessages");
            //await HubProxy.Invoke("GetNumberOfUsers");
        }
开发者ID:unrealdrake,项目名称:eChat,代码行数:28,代码来源:Program.cs

示例2: HubInitial

        public void HubInitial()
        {
            Connection = new HubConnection("http://54.69.68.144:8733/signalr");

            HubProxy = Connection.CreateHubProxy("ChatHub");

            HubProxy.On<string>("AddMessage",(msg) =>
                Device.BeginInvokeOnMainThread(() =>
                {
                   MessageService.AddMessage(msg,false,_controls);
                }));

            HubProxy.On<int>("GetNumberOfUsers", (count) =>
                Device.BeginInvokeOnMainThread(() =>
                {
                    MessageService.SetUsersCount(count, _controls);
                }));

            try
            {
                Connection.Start().Wait();
                Device.BeginInvokeOnMainThread(() =>
                {
                    _controls.ProgressBar.ProgressTo(.9, 250, Easing.Linear);
                });
            }
            catch (Exception e)
            {
                MessageTemplate.RenderError("Невозможно подключиться к серверу");
            }
            HubProxy.Invoke("GetNumberOfUsers");
        }
开发者ID:unrealdrake,项目名称:eChat,代码行数:32,代码来源:HubInitializer.cs

示例3: Application_Initialize

partial         void Application_Initialize()
        {
            HubConnection hubConnection;
            http://localhost:49499
            hubConnection = new HubConnection("http://localhost:49499"); //make sure it matches your port in development

              //  HubProxy = hubConnection.CreateProxy("MyHub");
            HubProxy = hubConnection.CreateHubProxy("Chat");
            HubProxy.On<string, string>("CustomersInserted", (r, user) =>
            {
                this.ActiveScreens.First().Screen.Details.Dispatcher.BeginInvoke(delegate() {
                    this.ActiveScreens.First().Screen.ShowMessageBox("han creat un client");
                });
              //  this.Details.Dispatcher.BeginInvoke(() =>
              //  {
              //      this.ActiveScreens.First().Screen.ShowMessageBox("han creat un client");
              ////      Console.WriteLine("Han creat un client");
              //  });
            });

            HubProxy.On<string>("addMessage", (missatge) =>
            {
                this.ActiveScreens.First().Screen.Details.Dispatcher.BeginInvoke(delegate()
                {
                    this.ActiveScreens.First().Screen.ShowMessageBox("has rebut un "+missatge);
                });
                //  this.Details.Dispatcher.BeginInvoke(() =>
                //  {
                //      this.ActiveScreens.First().Screen.ShowMessageBox("han creat un client");
                ////      Console.WriteLine("Han creat un client");
                //  });
            });
            hubConnection.Start().Wait();
        }
开发者ID:xaviguardia,项目名称:signalrLightSwitch,代码行数:34,代码来源:Application.cs

示例4: RunDemo

        private async Task RunDemo(string url)
        {
            cde = new CountdownEvent(invocations);
            ITaskAgent client = this;
            ITaskScheduler server = this;

            var hubConnection = new HubConnection(url);
            hubConnection.TraceWriter = _traceWriter;

            _hubProxy = hubConnection.CreateHubProxy("TaskSchedulerHub");            
            _hubProxy.On<TimeSpan>("RunSync", client.RunSync);
            _hubProxy.On<TimeSpan>("RunAsync", (data) => client.RunAsync(data));

            await hubConnection.Start(new LongPollingTransport());

            var smallDuration = TimeSpan.FromMilliseconds(500);
            var largeDuration = TimeSpan.FromSeconds(10);

            for (int i = 0; i < invocations; i++ )
            {
                server.AssignMeShortRunningTask(smallDuration);
                server.AssignMeLongRunningTask(largeDuration);
            }

            cde.Wait();
        }
开发者ID:haseebshujja,项目名称:Samples,代码行数:26,代码来源:HubTClient.cs

示例5: Hub

        public Hub(User user, Dispatcher dispatcher)
        {
            this.user = user;
            this.dispatcher = dispatcher;

#if DEBUG && !LIVE
            hubConnection = new HubConnection("http://localhost:51443/");
#else
            hubConnection = new HubConnection("http://poolq3.zoo.lan/"); 
#endif

            hubConnection.TraceLevel = TraceLevels.All;
            hubConnection.TraceWriter = new NLogTextWriter("signalr");

            hub = hubConnection.CreateHubProxy("QHub");
            hub.On<Queue>("NewQueue", q => RaiseEvent("created", QueueCreated, q));
            hub.On<Queue>("QueueMembershipChanged", q => RaiseEvent("membershipchanged", QueueMembershipChanged, q));
            hub.On<Queue>("QueueStatusChanged", q => RaiseEvent("statuschanged", QueueStatusChanged, q));
            hub.On<int, User, string>("QueueMessageSent", RaiseMessageEvent);
            hub.On<int>("NagQueue", id => RaiseEvent("nag", QueueNagged, id));
            hubConnection.Headers["User"] = this.user.ToString();
            hubConnection.StateChanged += HubConnectionOnStateChanged;
            hubConnection.Error += e => logger.Error(e, "hub error");

            TryConnect();
        }
开发者ID:lx223,项目名称:Q3,代码行数:26,代码来源:Hub.cs

示例6: OpenConnection

        private async Task OpenConnection()
        {
            var url = $"http://{await _serverFinder.GetServerAddressAsync()}/";

            try
            {
                _hubConnection = new HubConnection(url);

                _hubProxy = _hubConnection.CreateHubProxy("device");
                _hubProxy.On<string>("hello", message => Hello(message));
                _hubProxy.On("helloMsg", () => Hello("EMPTY"));
                _hubProxy.On<long, bool, bool>("binaryDeviceUpdated", (deviceId, success, binarySetting) => InvokeDeviceUpdated(deviceId, success, binarySetting: binarySetting));
                _hubProxy.On<long, bool, double>("continousDeviceUpdated", (deviceId, success, continousSetting) => InvokeDeviceUpdated(deviceId, success, continousSetting));

                await _hubConnection.Start();

                await _hubProxy.Invoke("helloMsg", "mobile device here");

                Debug.WriteLine($"{nameof(RealTimeService)}.{nameof(OpenConnection)} SignalR connection opened");
            }
            catch (Exception e)
            {
                Debug.WriteLine($"{nameof(RealTimeService)}.{nameof(OpenConnection)} ex: {e.GetType()}, msg: {e.Message}");
            }
        }
开发者ID:rwojcik,项目名称:imsClient,代码行数:25,代码来源:RealTimeService.cs

示例7: ShellViewModel

        public ShellViewModel()
        {
            _hubConnection = new HubConnection("http://localhost:52029/");
            _gameHub = _hubConnection.CreateHubProxy("ScattergoramentHub");

            _gameHub.On<char, DateTime>("gameStart", GameStart);
            _gameHub.On<string, DateTime>("gameEnd", GameEnd);
            _gameHub.On<bool, char, DateTime>("gameStatus", GameStatus);

            _timer = new DispatcherTimer();
            _timer.Interval = TimeSpan.FromMilliseconds(100);
            _timer.Tick += _timer_Tick;
            _timer.Start();

            _hubConnection.Start()
                .ContinueWith(task=>
                    {
                        if (task.IsFaulted)
                        {
                            Console.WriteLine("An error occurred during the method call {0}", task.Exception.GetBaseException());
                        }
                        else
                        {
                            RegisterPlayer();
                        }
                    }
                    );
        }
开发者ID:samadhi,项目名称:DevJam_Scattergorament,代码行数:28,代码来源:ShellViewModel.cs

示例8: Chat

        public Chat(HubConnection connection)
        {
            _chat = connection.CreateHubProxy("Chat");

            _chat.On<User>("markOnline", user =>
            {
                if (UserOnline != null)
                {
                    UserOnline(user);
                }
            });

            _chat.On<User>("markOffline", user =>
            {
                if (UserOffline != null)
                {
                    UserOffline(user);
                }
            });

            _chat.On<Message>("addMessage", message =>
            {
                if (Message != null)
                {
                    Message(message);
                }
            });
        }
开发者ID:xiurui12345,项目名称:MessengR,代码行数:28,代码来源:Chat.cs

示例9: SetHub

 public async Task SetHub(IHubProxy hub)
 {
     this.hub = hub;
     hub.On<string>("info", info => ServedInformation = string.Join("\r\n", ServedInformation, info));
     hub.On("completed", () => _isCompleted = true);
     await hub.Invoke("SetupServer");
 }
开发者ID:Kazuki-Kachi,项目名称:Madoben,代码行数:7,代码来源:MainPageViewModel.cs

示例10: Start

 public void Start()
 {
     _connection = new HubConnection("http://localhost:27367/");
     _job=_connection.CreateHubProxy("JobStatusHub");
     _job.On("started",onStarted);
     _job.On("finished", onFinished);
     _connection.Start();
 }
开发者ID:erichexter,项目名称:TestSwarm,代码行数:8,代码来源:TestSwarmClient.cs

示例11: RegisterEventHandlers

        private void RegisterEventHandlers(IHubProxy proxy)
        {
            // Register event for setting the QR-code for client URL
            proxy.On<Uri>("SetQrCode", SetQrCode);

            // Register events for controlling the robot
            proxy.On<string>("LockRobot", LockRobot);
            proxy.On<string>("UnlockRobot", UnlockRobot);
        }
开发者ID:hansarnevartdal,项目名称:TimeShareRobot,代码行数:9,代码来源:RobotViewModel.cs

示例12: SignalRClient

        public SignalRClient(IEventAggregator eventAggregator)
        {
            this.eventAggregator = eventAggregator;

            connection = new HubConnection(System.Windows.Browser.HtmlPage.Document.DocumentUri.ToString());
            hubProxy = connection.CreateHubProxy(HubName);

            hubProxy.On<string>(ProductUpdatedEvent.HubEventName, OnProductUpdatedRemote);
            hubProxy.On<List<string>>(ProductUpdatedBatchEvent.HubEventName, OnProductUpdatedBatchRemote);
            hubProxy.On<List<string>>(ProductDeletedBatchEvent.HubEventName, OnProductDeletedBatchRemote);
        }
开发者ID:hva,项目名称:warehouse.net,代码行数:11,代码来源:SignalRClient.cs

示例13: StartAsync

 public async Task StartAsync()
 {
     hubConnection = new HubConnection(Url);
     eventHubProxy = hubConnection.CreateHubProxy("EventHub");
     eventHubProxy.On<Message>("Receive",
         async message => await FilterMessage(message, async () => await OnReceive(message)));
     eventHubProxy.On<Message>("UpdateConfiguration",
         async message => await FilterMessage(message, async () => await OnUpdateConfiguration(message.Values["Locations"] as IEnumerable<Location>)));
     await hubConnection.Start();
     await eventHubProxy.Invoke<Message>("RequestConfiguration");
 }
开发者ID:wertzui,项目名称:HomeController,代码行数:11,代码来源:HubClient.cs

示例14: ConnectToServer

		public virtual void ConnectToServer() {
			hubConnection = new HubConnection("http://localhost:52807/signalR", false);
			hubProxy = hubConnection.CreateHubProxy("QmsHub");

			hubProxy.On("OnRegisterConfirm", OnRegisteConfirm);
			hubProxy.On<Guid>("AddPersonToQueue", AddPersonToQueue);
			hubProxy.On("OnStart", OnStart);
			hubProxy.On("OnStop", OnStop);

			hubConnection.Start().Wait();
			OnConnectedToServer();
		}
开发者ID:TomaszKorecki,项目名称:QMS,代码行数:12,代码来源:InstitutionQueue.cs

示例15: MainWindow_Loaded

        private async void MainWindow_Loaded(object sender, RoutedEventArgs e)
        {
            var deviceName = ConfigurationManager.AppSettings["DeviceName"];
            device = PTZDevice.GetDevice(deviceName, PTZType.Relative);

            url = ConfigurationManager.AppSettings["relayServerUrl"];
            remoteGroup = Environment.MachineName; //They have to hardcode the group, but for us it's our machine name
            connection = new HubConnection(url);
            proxy = connection.CreateHubProxy("RelayHub");

            connection.TraceLevel = TraceLevels.StateChanges | TraceLevels.Events;
            connection.TraceWriter = new PTZRemoteTraceWriter(Log);

            //Can't do this here because DirectShow has to be on the UI thread!
            // This would cause an obscure COM casting error with no clue what's up. So, um, ya.
            //proxy.On<int, int>("Move",(x,y) => device.Move(x, y));
            //proxy.On<int>("Zoom", (z) => device.Zoom(z));

            magic = SynchronizationContext.Current;

            proxy.On<int, int>("Move", (x, y) =>
            {
                //Toss this over the fence from this background thread to the UI thread
                magic.Post((_) => {
                    Log(String.Format("Move({0},{1})", x,y));
                    device.Move(x, y);
                }, null);
            });

            proxy.On<int>("Zoom", (z) =>
            {
                magic.Post((_) =>
                {
                    Log(String.Format("Zoom({0})", z));
                    device.Zoom(z);
                }, null);
            });


            try
            {
                await connection.Start();
                Log("After connection.Start()");
                await proxy.Invoke("JoinRelay", remoteGroup);
                Log("After JoinRelay");
            }
            catch (Exception pants)
            {
                Log(pants.GetError().ToString());
                throw;
            }
        }
开发者ID:JonathanTLH,项目名称:PanTiltZoomSystem,代码行数:52,代码来源:ListenerMainWindow.xaml.cs


注:本文中的IHubProxy.On方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。