本文整理汇总了C#中Microsoft.AspNet.SignalR.Client.HubConnection.Stop方法的典型用法代码示例。如果您正苦于以下问题:C# HubConnection.Stop方法的具体用法?C# HubConnection.Stop怎么用?C# HubConnection.Stop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.AspNet.SignalR.Client.HubConnection
的用法示例。
在下文中一共展示了HubConnection.Stop方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartRealtimeConnection
private async Task<ApiResultBase> StartRealtimeConnection(ConnectExtruderModel connectExtruderModel)
{
try
{
_connection = new HubConnection(SOS_URL);
_proxy = _connection.CreateHubProxy("SosHub");
_proxy.On<int?, TimeSpan?>("setLights", OnSetLightsEventReceived);
_proxy.On<int?, TimeSpan?>("setAudio", OnSetAudioEventReceived);
_proxy.On<ModalDialogEventArgs>("modalDialog", OnModalDialogEventReceived);
_proxy.On("forceDisconnect", OnForceDisconnect);
_proxy.On<TrayIcon>("setTrayIcon", OnSetTrayIcon);
_proxy.On<TrayNotifyEventArgs>("trayNotify", OnTrayNotify);
_connection.Error += ConnectionOnError;
_connection.StateChanged += ConnectionOnStateChanged;
_connection.Closed += ConnectionOnClosed;
await _connection.Start();
var result = await _proxy.Invoke<ApiResultBase>("connectExtruder", connectExtruderModel);
if (!result.Success)
{
_connection.Stop();
}
return result;
}
catch (Exception ex)
{
_log.Error("Unable to start realtime connection to SoS Online", ex);
return new ApiResultBase {Success = false, ErrorMessage = ex.Message};
}
}
示例2: CallToServer
void CallToServer()
{
Console.WriteLine("Input your name ==>");
string inputName = Console.ReadLine();
var hubConnection = new HubConnection("http://localhost:50515/");
hubConnection.Error += hubConnection_Error;
IHubProxy consoleHubProxy = hubConnection.CreateHubProxy("HubCenter");
consoleHubProxy.On("broadcastMessage", (string name, string message) =>
{
Console.WriteLine("{0} say: {1}", name, message);
});
hubConnection.Start().Wait();
string sayWhat;
Console.WriteLine("Say something.");
while ((sayWhat = Console.ReadLine()) != "")
{
try
{
consoleHubProxy.Invoke("CallFromConsole", new ClientModel { Name = inputName, Message = sayWhat }).Wait();
}
catch(Exception ex)
{
}
}
hubConnection.Stop();
}
示例3: SendCompleteNotification
private static async Task SendCompleteNotification(Message message, string uri)
{
var hubConnection = new HubConnection(url);
hub = hubConnection.CreateHubProxy("GifServerHub");
await hubConnection.Start();
Console.WriteLine("Invoked GifGenerationCompleted with URL: {0}", uri);
await hub.Invoke("GifGenerationCompleted", message.HubId, uri);
hubConnection.Stop();
}
示例4: MainAsync
private async Task MainAsync()
{
_hubConnection = CreateConnection();
Console.WriteLine("Created connection, waiting 1 minute to start it.");
Thread.Sleep(TimeSpan.FromMinutes(1));
await _hubConnection.Start();
Console.WriteLine("Press any key to exit.");
Console.ReadKey();
_hubConnection.Stop();
}
示例5: Main
static void Main(string[] args)
{
var con = new HubConnection("http://localhost/SignalRDemo");
var adminHub = con.CreateHubProxy("admin");
con.Start().ContinueWith(t => Console.WriteLine("Connected")).Wait();
adminHub.On<dynamic>("orderReceived", order => Console.WriteLine(order));
Console.Read();
con.Stop();
}
示例6: Main
static void Main(string[] args)
{
var url = "http://localhost:8080/";
var connection = new HubConnection(url);
//必须在Connection连接之前创建Hub
var serviceHub = connection.CreateHubProxy("MyServiceHub");
//注册该Hub的Hit方法对应的客户端处理程序
serviceHub.On<string,string>("pushMessage", (p,q) =>
{
Console.WriteLine(p+":"+q);
});
Console.WriteLine("正在连接服务器...");
connection.Start().Wait();
if (connection.State == ConnectionState.Disconnected)
{
Console.WriteLine("连接服务器失败");
}
else
{
Console.WriteLine("连接服务器成功");
serviceHub.Invoke("HelloWorld").Wait();
while (true)
{
Console.WriteLine("请选择:\n1.发送消息\n2.发送测试对象\n3.获取SessionID\n0.退出");
string key = Console.ReadLine();
if (key == "1")
{
Console.WriteLine("请输入消息内容:");
serviceHub.Invoke("SendMessage", Console.ReadLine()).Wait();
}
else if (key == "2")
{
var obj = new { Name = "小明", Age = 18 };
serviceHub.Invoke("SendObject",obj).Wait();
}
else if (key == "3")
{
Console.WriteLine("SessionID:" + serviceHub.Invoke<string>("GetSessionId").Result);
}
else if (key == "0")
{
connection.Stop();
return;
}
}
}
}
示例7: Signal_Excute
/// <summary>
/// 互动发送消息
/// </summary>
/// <param name="HubName"></param>
/// <param name="HubAction"></param>
public void Signal_Excute(String HubName, Action<IHubProxy> HubAction)
{
var HubUrl = ConfigurationManager.AppSettings["AdminSiteUrl"] + "/signalr";
var Connection = new HubConnection(HubUrl);
var HubItem = Connection.CreateHubProxy(HubName);
Connection.Start().ContinueWith(task =>
{
if (!task.IsFaulted)
{
HubAction(HubItem);
}
}).Wait();
Connection.Stop();
}
示例8: Main
static void Main(string[] args)
{
String hub = ConfigurationManager.AppSettings["hub"];
HubConnection myHubConn;
IHubProxy myHub;
myHubConn = new HubConnection(hub);
myHub = myHubConn.CreateHubProxy("resultatServiceHub");
myHubConn.Error += ex => Console.WriteLine("SignalR error: {0}", ex.Message, ex.InnerException);
myHubConn.TraceLevel = TraceLevels.None;
myHubConn.TraceWriter = Console.Out;
myHubConn.Start()
.ContinueWith((prevTask) =>
{
myHub.Invoke("Join", "ResultService");
myHub.Invoke("AddtoGroup", "");
}).Wait();
myHub.On<Participant>("newPass", (data) =>
{
foreach (ParticipantClass c in data.Classes)
{
myHub.Invoke<ICollection<Participant>>("GetCurrentResults", c.Id)
.ContinueWith((result) =>
{
var d = result.Result;
var json = JsonConvert.SerializeObject(d, Formatting.Indented);
System.IO.File.WriteAllText(@"c:\temp\" + c.Name + ".json", json);
});
}
}
);
Console.ReadLine();
myHubConn.Stop();
Console.WriteLine("Stopped");
}
示例9: Upload
public async Task<ActionResult> Upload(string site)
{
for (int i = 0; i < Request.Files.Count; i++)
{
var file = Request.Files[i];
Guid id = Guid.NewGuid();
byte[] logo = new byte[file.ContentLength];
file.InputStream.Read(logo, 0, file.ContentLength);
_dataPersistor.SaveImage(logo, site, id);
var hubConnection = new HubConnection("http://localhost:4785/");
IHubProxy stockTickerHubProxy = hubConnection.CreateHubProxy("NotificationHub");
await hubConnection.Start();
await stockTickerHubProxy.Invoke("NotifyPostedImage", new NotifyPostedImageCommand { Id = id, Secret = _secret, Image = logo, Timestamp = DateTime.Now, SiteName = (string)RouteData.Values["site"] });
hubConnection.Stop();
}
return Json(new { success = true }, JsonRequestBehavior.AllowGet);
}
示例10: Main
static void Main(string[] args)
{
Console.Title = "Drawing Board Virtual";
Console.SetWindowSize(80, 60);
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Black;
Console.Clear();
var server = "http://localhost:52234/";
var hubConn = new HubConnection(server);
var hubProxy = hubConn.CreateHubProxy("board");
hubProxy.On("clear", () =>
{
Console.BackgroundColor = ConsoleColor.White;
Console.Clear();
});
hubProxy.On("drawPoint", (int x, int y, int color) => DrawPoint(x, y, color));
hubProxy.On("update", (int[,] buffer) =>
{
for (int x = 0; x < buffer.GetLength(0); x++)
{
for (int y = 0; y < buffer.GetLength(1); y++)
{
if (buffer[x, y] != 0)
{
DrawPoint(x, y, buffer[x, y]);
}
}
}
});
hubConn.Start().ContinueWith(c =>
{
if (c.IsFaulted)
{
Console.WriteLine("Error to conect");
}
});
Console.ReadLine();
hubConn.Stop();
}
示例11: Main
private static void Main(string[] args) {
Console.Title = "Console drawing board viewer";
Console.SetWindowSize(80, 50);
Console.BackgroundColor = ConsoleColor.White;
Console.ForegroundColor = ConsoleColor.Black;
Console.Clear();
var server = "http://localhost:52682/signalr";
var hubConn = new HubConnection(server, false);
var hubProxy = hubConn.CreateHubProxy("drawingBoard");
hubProxy.On("clear", () => {
Console.BackgroundColor = ConsoleColor.White;
Console.Clear();
});
hubProxy.On("drawPoint", (int x, int y, int color) => {
DrawPoint(x, y, color);
});
hubProxy.On("update", (int[,] buffer) => {
for (int x = 0; x < buffer.GetLength(0); x++) {
for (int y = 0; y < buffer.GetLength(1); y++) {
if (buffer[x, y] != 0)
DrawPoint(x, y, buffer[x, y]);
}
}
});
hubConn.Start().ContinueWith(t => {
if (t.IsFaulted) {
Console.WriteLine("Error connecting to "
+ server + ". Are you using the right URL?");
}
});
Console.ReadLine();
hubConn.Stop();
}
示例12: Main
private static void Main(string[] args) {
Console.Clear();
Console.WriteLine("(Enter port number");
var port = Console.ReadLine();
string host = "http://localhost:" + port;
while (true) {
var connection = new HubConnection(host);
Console.Clear();
Console.WriteLine("(Enter 'adam' or 'admin' as username to access private methods)");
Console.Write("Enter your username: ");
var username = Console.ReadLine();
Console.Write("Enter your password: ");
var password = Console.ReadLine();
var authCookie = GetAuthCookie(host + "/account/login", username, password).Result;
if (authCookie == null) {
Console.WriteLine("Impossible to get the token. Press a key to try again.");
Console.ReadKey();
continue;
}
Console.WriteLine("Token obtained");
connection.CookieContainer = new CookieContainer();
connection.CookieContainer.Add(authCookie);
var proxy = connection.CreateHubProxy("EchoHub");
proxy.On<string>("Message", msg => Console.WriteLine(" Received: " + msg));
connection.Start().Wait();
Invoke(proxy, "PublicMessage", username);
Invoke(proxy, "MembersMessage", username);
Invoke(proxy, "AdminsMessage", username);
Invoke(proxy, "PrivateMessage", username);
Console.WriteLine("\n\nPress any key to try again, Ctrl-C to exit");
Console.ReadKey();
connection.Stop();
}
}
示例13: Main
public static void Main(string[] args)
{
var connection = new HubConnection("http://127.0.0.1:8088/");
var myHub = connection.CreateHubProxy("ChatHub");
connection.Start().ContinueWith(task =>
{
if (task.IsFaulted)
{
Console.WriteLine("There was an error opening the connection:{0}",
task.Exception.GetBaseException());
}
else
{
Console.WriteLine("Connected");
}
}).Wait();
myHub.On<string>("addMessage", param =>
{
Console.WriteLine(param);
});
Console.Write("Your name: ");
string name = Console.ReadLine();
myHub.Invoke<string>("Chat", "Online: " + name).Wait();
while (true)
{
string message = Console.ReadLine();
myHub.Invoke<string>("Chat", name + ":" + message).Wait();
if (message == "quit")
break;
}
connection.Stop();
}
示例14: Main
static void Main(string[] args)
{
var connection = new HubConnection("http://localhost:57459/");
connection.TraceLevel = TraceLevels.All;
connection.TraceWriter = System.Console.Out;
var proxy = connection.CreateHubProxy("ChatHub");
connection.Start()
.ContinueWith(t =>
{
throw t.Exception.GetBaseException();
},TaskContinuationOptions.OnlyOnFaulted)
.ContinueWith(_ =>
{
for (int i = 0; i < 1000; i++)
{
Thread.Sleep(TimeSpan.FromMilliseconds(new Random().Next(1, 15)));
var message = string.Format("Message number {0}", i);
System.Console.WriteLine(message);
proxy.Invoke("MessageGroup", "SignalR", message).Wait();
}
}).ContinueWith(_ => connection.Stop());
System.Console.ReadLine();
}
示例15: RunConnectDisconnect
public static IDisposable RunConnectDisconnect(bool scaleout, int nodes = 1, int connections = 1000)
{
IHttpClient client;
IDisposable disposable = TryGetClient(scaleout, nodes, out client);
for (int i = 0; i < connections; i++)
{
var connection = new HubConnection("http://foo");
var proxy = connection.CreateHubProxy("SimpleEchoHub");
var wh = new ManualResetEventSlim(false);
proxy.On("echo", _ => wh.Set());
try
{
connection.Start(client).Wait();
proxy.Invoke("Echo", "foo").Wait();
if (!wh.Wait(TimeSpan.FromSeconds(10)))
{
Debugger.Break();
}
}
finally
{
connection.Stop();
}
}
return disposable;
}