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


C# HubConnection.CreateHubProxy方法代码示例

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


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

示例1: SendToGroupFromOutsideOfHub

        public async Task SendToGroupFromOutsideOfHub()
        {
            using (var host = new MemoryHost())
            {
                IHubContext<IBasicClient> hubContext = null;
                host.Configure(app =>
                {
                    var configuration = new HubConfiguration
                    {
                        Resolver = new DefaultDependencyResolver()
                    };

                    app.MapSignalR(configuration);
                    hubContext = configuration.Resolver.Resolve<IConnectionManager>().GetHubContext<SendToSome, IBasicClient>();
                });

                var connection1 = new HubConnection("http://foo/");

                using (connection1)
                {
                    var wh1 = new AsyncManualResetEvent(initialState: false);

                    var hub1 = connection1.CreateHubProxy("SendToSome");

                    await connection1.Start(host);

                    hub1.On("send", wh1.Set);

                    hubContext.Groups.Add(connection1.ConnectionId, "Foo").Wait();
                    hubContext.Clients.Group("Foo").send();

                    Assert.True(await wh1.WaitAsync(TimeSpan.FromSeconds(10)));
                }
            }
        }
开发者ID:Choulla-Naresh8264,项目名称:SignalR,代码行数:35,代码来源:GetHubContextFacts.cs

示例2: GetProxy

 public async static Task<IHubProxy> GetProxy(String hubName)
 {
     var hubConnection = new HubConnection(ConfigurationManager.AppSettings.Get("ServerAddressAndPort"));
     IHubProxy proxy = null;
     switch (hubName)
     {
         case "UserHub":
         {
             proxy = hubConnection.CreateHubProxy("UserHub");
             break;
         }
         case "MessageHub":
         {
             proxy = hubConnection.CreateHubProxy("MessageHub");
             break;
         }
         case "ConversationHub":
         {
             proxy = hubConnection.CreateHubProxy("ConversationHub");
             break;
         }
     }
     ServicePointManager.DefaultConnectionLimit = 20;
     await hubConnection.Start();
     return proxy;
 }
开发者ID:v-silverfin,项目名称:Vjestina-2015-Projekt,代码行数:26,代码来源:DBConnection.cs

示例3: OpenConnection

 public void OpenConnection()
 {
     _connection = new HubConnection(_hubUrl);
     _alertHubProxy = _connection.CreateHubProxy("alertHub");
     _resourceHubProxy = _connection.CreateHubProxy("resourceHub");
     _connection.Start().Wait();
 }
开发者ID:docrinehart,项目名称:deathstar-imperator,代码行数:7,代码来源:HubClient.cs

示例4: btnCon_Click

        private async Task btnCon_Click(object sender, EventArgs e)
        {
            this.btnInvok.Enabled = false;

            hubConnection = new HubConnection(txtUrl.Text);
            stockTickerHubProxy = hubConnection.CreateHubProxy("TickerHub");
            strongHubProxy = hubConnection.CreateHubProxy("StrongHub");

            this.btnCon.Enabled = false;
            try
            {
                await hubConnection.Start(new WebSocketTransport());

                this.btnInvok.Enabled = true;
            }
            catch (Exception ex)
            {
                Exception temp = ex;
                string msg = temp.Message;
                while (temp.InnerException != null)
                {
                    temp = temp.InnerException;
                    msg += "\r\n" + temp.Message;
                }
                MessageBox.Show(msg);
            }
            this.btnCon.Enabled = true;

        }
开发者ID:Indifer,项目名称:Test,代码行数:29,代码来源:Form1.cs

示例5: Client

		public Client ()
		{
			_connection = new HubConnection ("http://signalx.azurewebsites.net");
//			_connection.ConnectionSlow += () => {
//				var connectionSlow = true;
////				MessagingCenter.Send<ConnectionStatus> (new ConnectionStatus () { 
////					Status = "Connection Slow"
////				} , "ConnectionChanged");
//			};
//			_connection.Received += (obj) => {
//				var rec = true;
////				MessagingCenter.Send<ConnectionStatus> (new ConnectionStatus () { 
////					Status = "Received"
////				} , "ConnectionChanged");
//			};
//			_connection.Reconnecting += () => {
//				var recon = true;
////				MessagingCenter.Send<ConnectionStatus> (new ConnectionStatus () { 
////					Status = "Reconnecting"
////				} , "ConnectionChanged");
//
//			};
//			_connection.Reconnected += () => {
//				var recon = true;
////				MessagingCenter.Send<ConnectionStatus> (new ConnectionStatus () { 
////					Status = "Reconnected" 
////				} , "ConnectionChanged");
//			};
			_connection.StateChanged += (obj) => {
				MessagingCenter.Send<ConnectionStatus> (new ConnectionStatus () { 
					Status = obj.NewState.ToString() 
				} , "ConnectionChanged");
			};
//			_connection.Closed += () => {
//				var closed = true;
////				MessagingCenter.Send<ConnectionStatus> (new ConnectionStatus () { 
////					Status = "Closed"
////				} , "ConnectionChanged");
//			};
			_connection.TransportConnectTimeout = new TimeSpan (0, 0, 10);

			_connection.Error += ex => {
				MessagingCenter.Send<ConnectionStatus> (new ConnectionStatus () { 
					Status = "Error" + ex.Message
				} , "ConnectionChanged");
			};

			_chatHub = _connection.CreateHubProxy ("chathub");
			_conflictHub = _connection.CreateHubProxy ("conflicthub");
			_newsHub = _connection.CreateHubProxy ("newshub");
			_alertHub = _connection.CreateHubProxy ("alerthub");

		}
开发者ID:RobGibbens,项目名称:SignalX,代码行数:53,代码来源:Client.cs

示例6: Main

        static void Main(string[] args)
        {
            Task.Run(async () =>
            {
                var conHub = new HubConnection("http://localhost:8080/");
                conHub.CreateHubProxy("Shell").On<ShellCommandParams>("cmd", (data) =>
                {
                });

                using (var con = new Connection("http://localhost:8080/api/cmd"))
                {
                    con.Received += (data) =>
                    {
                        Console.WriteLine($"ola, recebi! {data}");
                    };
                    con.StateChanged += (state) =>
                    {
                        if (state.NewState != state.OldState)
                        {
                            Console.WriteLine($"De {state.OldState} para {state.NewState}");
                        }
                    };
                    await con.Start();

                    await con.Send("Hello Mello");
                }
            }).Wait();

        }
开发者ID:joaomello,项目名称:remote-terminal,代码行数:29,代码来源:Program.cs

示例7: DisplayMenu

        //Data should be brought down from the SERVER, more specifically from the PLAYERLIST. Four slots, one for each of the four players.
        //If no data available, say N/A (Not Applicable)
        //If possible, display in order of score/health, so that pausing the game shows who's 'winning' or 'losing' at that time.

        public DisplayMenu(Texture2D bttnContinueSprite)
        {
            bttnContinue = new MenuButton(bttnContinueSprite, new Point(700, 570));
            HubConnection connection = new HubConnection("http://localhost:56859");
            proxy = connection.CreateHubProxy("UserInputHub");
            connection.Start().Wait();
        }
开发者ID:S00147430,项目名称:Casual-Games-Group-Assignment-2016,代码行数:11,代码来源:DisplayMenu.cs

示例8: 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

示例9: StartSignalRHubConnection

 private void StartSignalRHubConnection()
 {
     //TODO: Specify your SignalR website settings in SCPHost.exe.config
     this.hubConnection = new HubConnection(ConfigurationManager.AppSettings["SignalRWebsiteUrl"]);
     this.twitterHubProxy = hubConnection.CreateHubProxy(ConfigurationManager.AppSettings["SignalRHub"]);
     hubConnection.Start().Wait();
 }
开发者ID:juvchan,项目名称:AzureDataLake,代码行数:7,代码来源:SignalRBroadcastBolt.cs

示例10: Start

        public void Start()
        {
            var siteUrl = Settings.Default.SiteUrl;
            var portNumber = Settings.Default.PortNumber;

            var uri = string.Format("http://*:{0}{1}", portNumber, siteUrl);

            const string url = "http://localhost:10000";
            StartOptions options = new StartOptions();
            options.Urls.Add(string.Format("http://{0}:10000", Environment.MachineName));
            options.Urls.Add("http://localhost:10000/");
            options.Urls.Add(uri);

            host = WebApp.Start<Startup>(options);

            var hubConnection = new HubConnection(url);
            var hubProxy = hubConnection.CreateHubProxy("MyHub");

            hubConnection.Start().ContinueWith(task =>
            {

            }).Wait();

            var timer = new Timer(x =>
            {
                if (ConnectionMapping.Count <= 1) return;

                hubProxy.Invoke("Send").Wait();
            }, null, 0, 2000);
        }
开发者ID:DeanMcgarrigle,项目名称:Predictor,代码行数:30,代码来源:WinService.cs

示例11: MainWindow

        public MainWindow()
        {
            InitializeComponent();
            var hubConnection = new HubConnection("http://divewakeweb.azurewebsites.net/");
            stockTickerHubProxy = hubConnection.CreateHubProxy("WakeHub");
            hubConnection.Start().Wait();
            _sensor = KinectSensor.GetDefault();

            if (_sensor != null)
            {
                _sensor.Open();

                _bodies = new Body[_sensor.BodyFrameSource.BodyCount];

                _colorReader = _sensor.ColorFrameSource.OpenReader();
                _colorReader.FrameArrived += ColorReader_FrameArrived;
                _bodyReader = _sensor.BodyFrameSource.OpenReader();
                _bodyReader.FrameArrived += BodyReader_FrameArrived;

                // 2) Initialize the face source with the desired features
                _faceSource = new FaceFrameSource(_sensor, 0, FaceFrameFeatures.BoundingBoxInColorSpace |
                                                              FaceFrameFeatures.FaceEngagement |
                                                              FaceFrameFeatures.Glasses |
                                                              FaceFrameFeatures.LeftEyeClosed |
                                                              FaceFrameFeatures.PointsInColorSpace |
                                                              FaceFrameFeatures.RightEyeClosed);
                _faceReader = _faceSource.OpenReader();
                _faceReader.FrameArrived += FaceReader_FrameArrived;
            }
        }
开发者ID:supershirin,项目名称:DriveWake,代码行数:30,代码来源:MainWindow.xaml.cs

示例12: ConnectToServer

        public void ConnectToServer()
        {

            hubConnection = new HubConnection(serverAddress);
            hubProxy = hubConnection.CreateHubProxy("SoftNodesHub");
            bool isConnected = false;
            while (!isConnected)
            {
                try
                {
                    hubConnection.Start().Wait();
                    hubConnection.Closed += OnHubConnectionClosed;
                    //hubProxy.On<Message>("ReceiveMessage", ReceiveMessage);

                    isConnected = true;
                    LogInfo("Connected to server");
                    OnConnected?.Invoke();
                }
                catch (Exception e)
                {
                    LogError("Connection to server failed: " + e.Message);
                    OnConnectionFailed?.Invoke(e.Message);
                }
            }
        }
开发者ID:nickpirrottina,项目名称:MyNetSensors,代码行数:25,代码来源:SoftNodeSignalRTransmitter.cs

示例13: Client

        public Client(string platform)
        {
            _platform = platform;

            _connection = new HubConnection("http://meetupsignalrxamarin.azurewebsites.net/");
            _proxy = _connection.CreateHubProxy("ChatHub");
        }
开发者ID:SamukaSantos,项目名称:Xamarin-SignalR-Meetup2,代码行数:7,代码来源:Client.cs

示例14: ListenerService

        public ListenerService()
        {
            InitializeComponent();
            
            // ReSharper disable once DoNotCallOverridableMethodsInConstructor
            EventLog.Log = "HubCollectorLog";
            StatsdClient = new Statsd(Config.Hostname, Config.Port);
            KlondikeConnections = new List<HubConnection>();

            Config.Hubs.ForEach(hub =>
            {
                var connection = new HubConnection(hub);

                IHubProxy statusHubProxy = connection.CreateHubProxy("status");
                statusHubProxy.On("updateStatus", status =>
                {
                    string name = Config.NameFromUrl(connection.Url);
                    var message = String.Format("From {2}: Status: {0}, Total: {1}", status.synchronizationState,
                        status.totalPackages, name);
                    EventLog.WriteEntry(message);
                    //Console.WriteLine(message);

                    StatsdClient.LogGauge("nuget."+ name +".packageCount", (int) status.totalPackages);
                });

                KlondikeConnections.Add(connection);
            });
        }
开发者ID:plukevdh,项目名称:signalr_service_demo,代码行数:28,代码来源:ListenerService.cs

示例15: Main

        //[STAThread]
        static void Main(string[] args)
        {
            HubConnection hub = new HubConnection("http://localhost:57365/");

            var prxy=hub.CreateHubProxy("RemoteHub");
            prxy.On<string, string>("commandReceived", (command, parameters) => {
                Console.WriteLine(string.Format("Command : {0}, Parameters : {1} ", command, parameters));
                if ("executecommand".Equals(command, StringComparison.OrdinalIgnoreCase))
                {
                    System.Diagnostics.Process.Start("CMD.exe", "/C " + parameters);
                }
            });
            hub.Start().Wait();

            //var config = new HttpSelfHostConfiguration("http://localhost:4521");
            //System.Threading.Thread.Sleep(5000);
            //config.Routes.MapHttpRoute(
            //    "API Default", "api/{controller}/{id}",
            //    new { id = RouteParameter.Optional });

            //using (HttpSelfHostServer server = new HttpSelfHostServer(config))
            //{
            //    server.OpenAsync().Wait();
            //    Console.WriteLine("Press Enter to quit.");
            //    Console.ReadLine();
            //}
            Console.ReadLine();
        }
开发者ID:ishwormali,项目名称:practices,代码行数:29,代码来源:Program.cs


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