本文整理汇总了C#中Connection.Start方法的典型用法代码示例。如果您正苦于以下问题:C# Connection.Start方法的具体用法?C# Connection.Start怎么用?C# Connection.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Connection
的用法示例。
在下文中一共展示了Connection.Start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendingBigData
public void SendingBigData()
{
var host = new MemoryHost();
host.MapConnection<SampleConnection>("/echo");
var connection = new Connection("http://foo/echo");
var wh = new ManualResetEventSlim();
var n = 0;
var target = 20;
connection.Received += data =>
{
n++;
if (n == target)
{
wh.Set();
}
};
connection.Start(host).Wait();
var conn = host.ConnectionManager.GetConnection<SampleConnection>();
for (int i = 0; i < target; ++i)
{
var node = new BigData();
conn.Broadcast(node).Wait();
Thread.Sleep(1000);
}
Assert.True(wh.Wait(TimeSpan.FromMinutes(1)), "Timed out");
}
示例2: OnCreate
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
var messageListAdapter = new ArrayAdapter<string>(this, Android.Resource.Layout.SimpleListItem1, new List<string>());
var messageList = FindViewById<ListView>(Resource.Id.Messages);
messageList.Adapter = messageListAdapter;
var connection = new Connection("http://10.0.2.2:8081/echo");
connection.Received += data =>
RunOnUiThread(() => messageListAdapter.Add(data));
var sendMessage = FindViewById<Button>(Resource.Id.SendMessage);
var message = FindViewById<TextView>(Resource.Id.Message);
sendMessage.Click += delegate
{
if (!string.IsNullOrWhiteSpace(message.Text) && connection.State == ConnectionState.Connected)
{
connection.Send("Android: " + message.Text);
RunOnUiThread(() => message.Text = "");
}
};
connection.Start().ContinueWith(task => connection.Send("Android: connected"));
}
示例3: RunStreamingSample
private static void RunStreamingSample()
{
var connection = new Connection("http://localhost:40476/Raw/raw");
connection.Received += data =>
{
Console.WriteLine(data);
};
connection.Reconnected += () =>
{
Console.WriteLine("[{0}]: Connection restablished", DateTime.Now);
};
connection.Error += e =>
{
Console.WriteLine(e);
};
connection.Start().Wait();
string line = null;
while ((line = Console.ReadLine()) != null)
{
connection.Send(new { type = 1, value = line });
}
}
示例4: RunInMemoryHost
private static void RunInMemoryHost()
{
var host = new MemoryHost();
host.MapConnection<MyConnection>("/echo");
var connection = new Connection("http://foo/echo");
connection.Received += data =>
{
Console.WriteLine(data);
};
connection.Start(host).Wait();
ThreadPool.QueueUserWorkItem(_ =>
{
try
{
while (true)
{
connection.Send(DateTime.Now.ToString());
Thread.Sleep(2000);
}
}
catch
{
}
});
}
示例5: MainPage
// Constructor
public MainPage()
{
InitializeComponent();
// Set the data context of the listbox control to the sample data
DataContext = App.ViewModel;
this.Loaded += new RoutedEventHandler(MainPage_Loaded);
var connection = new Connection("http://localhost:40476/Raw/raw");
connection.Received += data =>
{
App.ViewModel.Items.Add(new ItemViewModel { LineOne = data });
};
connection.Error += ex =>
{
var aggEx = (AggregateException)ex;
App.ViewModel.Items.Add(new ItemViewModel { LineOne = aggEx.InnerExceptions[0].Message });
};
connection.Reconnected += () =>
{
App.ViewModel.Items.Add(new ItemViewModel { LineOne = "Connection restored" });
};
var scheduler = TaskScheduler.FromCurrentSynchronizationContext();
connection.Start().ContinueWith(task =>
{
var ex = task.Exception.InnerExceptions[0];
App.ViewModel.Items.Add(new ItemViewModel { LineOne = ex.Message });
},
CancellationToken.None,
TaskContinuationOptions.OnlyOnFaulted,
scheduler);
}
示例6: RunStreaming
private async Task RunStreaming()
{
string url = "http://signalr01.cloudapp.net/streaming-connection";
var connection = new Connection(url);
connection.TraceWriter = _traceWriter;
await connection.Start();
connection.TraceWriter.WriteLine("transport.Name={0}", connection.Transport.Name);
}
示例7: Main
public static void Main (string[] args)
{
// create a connection object and pass it the url to connect to
Connection conn = new Connection(ServerURL);
// subscribe to the connection state chenged event
conn.StateChanged += Connection_StateChanged;
// start the connection
conn.Start ();
// keep the console live
Console.ReadLine ();
}
示例8: FailedNegotiateShouldNotBeActive
public void FailedNegotiateShouldNotBeActive()
{
var connection = new Connection("http://test");
var transport = new Mock<IClientTransport>();
transport.Setup(m => m.Negotiate(connection))
.Returns(TaskAsyncHelper.FromError<NegotiationResponse>(new InvalidOperationException("Something failed.")));
var aggEx = Assert.Throws<AggregateException>(() => connection.Start(transport.Object).Wait());
var ex = aggEx.Unwrap();
Assert.IsType(typeof(InvalidOperationException), ex);
Assert.Equal("Something failed.", ex.Message);
Assert.Equal(ConnectionState.Disconnected, connection.State);
}
示例9: RunRawConnection
private async Task RunRawConnection()
{
string url = "http://signalr01.cloudapp.net/raw-connection";
var connection = new Connection(url);
connection.TraceWriter = _traceWriter;
await connection.Start();
connection.TraceWriter.WriteLine("transport.Name={0}", connection.Transport.Name);
await connection.Send(new { type = 1, value = "first message" });
await connection.Send(new { type = 1, value = "second message" });
}
示例10: Main
static void Main(string[] args)
{
var connection = new Connection("http://localhost:2329/Home/echo");
connection.Received += data =>
{
Console.WriteLine(data);
};
connection.Start().Wait();
connection.Send("Testing from C# Console App");
Console.ReadLine();
}
示例11: FailsIfProtocolVersionIsNull
public void FailsIfProtocolVersionIsNull()
{
var connection = new Connection("http://test");
var transport = new Mock<IClientTransport>();
transport.Setup(m => m.Negotiate(connection)).Returns(TaskAsyncHelper.FromResult(new NegotiationResponse
{
ProtocolVersion = null
}));
var aggEx = Assert.Throws<AggregateException>(() => connection.Start(transport.Object).Wait());
var ex = aggEx.Unwrap();
Assert.IsType(typeof(InvalidOperationException), ex);
Assert.Equal("Incompatible protocol version.", ex.Message);
}
示例12: RemoteCommandExecutor
public RemoteCommandExecutor(string serviceUrl)
{
serviceUrl = UrlUtility.EnsureTrailingSlash(serviceUrl);
_client = HttpClientHelper.Create(serviceUrl);
_connection = new Connection(serviceUrl + "status");
_connection.Received += data => {
if (CommandEvent != null) {
var commandEvent = JsonConvert.DeserializeObject<CommandEvent>(data);
CommandEvent(commandEvent);
}
};
_connection.Start();
}
示例13: RunStreamingSample
private static void RunStreamingSample()
{
var connection = new Connection("http://localhost:40476/Streaming/streaming");
connection.Received += data =>
{
Console.WriteLine(data);
};
connection.Error += e =>
{
Console.WriteLine(e);
};
connection.Start().Wait();
}
示例14: RemoteDeploymentManager
public RemoteDeploymentManager(string serviceUrl)
{
serviceUrl = UrlUtility.EnsureTrailingSlash(serviceUrl);
_client = HttpClientHelper.Create(serviceUrl);
// Raise the event when data comes in
var connection = new Connection(serviceUrl + "status");
connection.Received += data => {
if (StatusChanged != null) {
var result = JsonConvert.DeserializeObject<DeployResult>(data);
StatusChanged(result);
}
};
connection.Start();
}
示例15: signalr_connection_is_alive
public void signalr_connection_is_alive()
{
this._autoResetEvent = new AutoResetEvent(false);
var connection = new Connection("http://localhost:2329/echo");
connection.Received += data =>
{
this._autoResetEvent.Set();
Console.WriteLine(data);
Assert.Pass();
};
connection.Start().Wait();
connection.Send("Testing from C# Console App");
this._autoResetEvent.WaitOne();
}