本文整理汇总了C#中Microsoft.AspNet.SignalR.Client.HubConnection类的典型用法代码示例。如果您正苦于以下问题:C# HubConnection类的具体用法?C# HubConnection怎么用?C# HubConnection使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
HubConnection类属于Microsoft.AspNet.SignalR.Client命名空间,在下文中一共展示了HubConnection类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConnectToSignalR
private async Task ConnectToSignalR()
{
hubConnection = new HubConnection(App.MobileService.ApplicationUri.AbsoluteUri);
if (user != null)
{
hubConnection.Headers["x-zumo-auth"] = user.MobileServiceAuthenticationToken;
}
else
{
hubConnection.Headers["x-zumo-application"] = App.MobileService.ApplicationKey;
}
proxy = hubConnection.CreateHubProxy("ChatHub");
await hubConnection.Start();
proxy.On<string>("helloMessage", async (msg) =>
{
await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
message += " " + msg;
Message.Text = message;
});
});
}
示例2: 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)));
}
}
}
示例3: 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);
}
});
}
示例4: RunDemo
private async Task RunDemo(string url)
{
var hubConnection = new HubConnection(url);
var querystringData = new Dictionary<string, string>();
querystringData.Add("name", "primaveraServer");
var connection = new HubConnection(url, querystringData);
hubConnection.TraceWriter = _traceWriter;
var hubProxy = hubConnection.CreateHubProxy("rhHub");
hubProxy.On<string>("addChatMessage", (n) =>
{
//string n = hubProxy.GetValue<string>("index");
hubConnection.TraceWriter.WriteLine("{0} ", n);
});
await hubConnection.Start();
hubConnection.TraceWriter.WriteLine("transport.Name={0}", hubConnection.Transport.Name);
hubConnection.TraceWriter.WriteLine("Invoking long running hub method with progress...");
await hubProxy.Invoke("SendChatMessage", new object[] { "primaveraServer", "ola" });
//hubConnection.TraceWriter.WriteLine("{0}", result);
//await hubProxy.Invoke("multipleCalls");
}
示例5: 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);
}
}
}
示例6: OpenConnection
public void OpenConnection()
{
_connection = new HubConnection(_hubUrl);
_alertHubProxy = _connection.CreateHubProxy("alertHub");
_resourceHubProxy = _connection.CreateHubProxy("resourceHub");
_connection.Start().Wait();
}
示例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();
}
示例8: Connect
public async Task Connect(string uri)
{
var connection = new HubConnection(uri);
connection.Closed += () =>
{
var eh = OnDisconnect;
if (eh != null) eh();
};
var hubProxy = connection.CreateHubProxy("MyHub");
hubProxy.On<string, string>("AddMessage", (userName, message) =>
{
var eh = On;
if (eh != null) eh(userName, message);
});
try
{
await connection.Start();
}
catch (AggregateException e)
{
throw e.InnerException;
}
_connection = connection;
_hubProxy = hubProxy;
}
示例9: 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");
}
示例10: 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();
}
示例11: 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);
}
示例12: ConnectServer
public void ConnectServer(string server, string port, string customerId, string accountId)
{
string ServerURI = server + ":" + port;
//string ServerURI = "http://localhost:8080/";
//if (Connection == null)
Connection = new HubConnection(ServerURI);
HubProxy = Connection.CreateHubProxy("ChatHub");
try
{
Connection.Start().ContinueWith(task =>
{
if (task.IsFaulted)
{
object[] obj = { false, "Can't connect to server." };
FireEvent("Login", obj);
}
else
{
AuthenRequest(customerId, accountId);
}
});
}
catch (Exception ex)
{
}
}
示例13: 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;
}
}
示例14: 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();
}
示例15: Connect
private async void Connect()
{
Connection = new HubConnection(ServerURI);
HubProxy = Connection.CreateHubProxy("NotifierHub");
HubProxy.On<AlarmMessage>("SendNotification", async (notification) =>
{
await this.AlarmsList.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
{
this.AlarmsList.Items.Add(notification);
});
}
);
try
{
await Connection.Start();
}
catch (HttpRequestException)
{
return;
}
catch (Exception)
{
return;
}
}