internal abstract void BindMethodToProxy(HubProxy proxy);
private async void ConnectAsync() { Connection = new HubConnection(ServerURI); Connection.Closed += Connection_Closed; HubProxy = Connection.CreateHubProxy("MyHub"); //Handle incoming event from server: use Invoke to write to console from SignalR's thread HubProxy.On <string, string>("AddMessage", (name, message) => this.Invoke((Action)(() => richTextBox1.AppendText(String.Format("{0}: {1}" + Environment.NewLine, name, message)) )) ); HubProxy.On("Started", () => this.Invoke((Action)(() => richTextBox1.AppendText(String.Format("Exam Started" + Environment.NewLine)) )) ); HubProxy.On <string>("NewClient", (name) => this.Invoke((Action)(() => richTextBox1.AppendText(String.Format("Client " + name + " Connected" + Environment.NewLine)) )) ); HubProxy.On("FailedToStart", () => this.Invoke((Action)(() => richTextBox1.AppendText(String.Format("Exam Failed To Start!" + Environment.NewLine)) )) ); HubProxy.On("connected", () => this.Invoke((Action)(() => { richTextBox1.AppendText(String.Format("Connected as " + ChoosenName + "!" + Environment.NewLine)); btn_send.Enabled = true; btn_send.Text = "Send"; } )) ); HubProxy.On("rejected", () => this.Invoke((Action)(() => { richTextBox1.AppendText(String.Format("Cannot connect with name of " + ChoosenName + "!" + Environment.NewLine)); this.ChoosenName = null; btn_send.Enabled = true; btn_send.Text = "Join Chat"; } )) ); HubProxy.On <int>("TimeLeft", (timePassed) => this.Invoke((Action)(() => { TimeSpan sinavSüresi = TimeSpan.FromMinutes(30); var span = sinavSüresi.Subtract(TimeSpan.FromSeconds(timePassed)); lbl_time_left.Text = string.Format("{0}:{1}:{2}", span.Hours.ToString("0#"), span.Minutes.ToString("0#"), span.Seconds.ToString("0#")); }) )); try { await Connection.Start(); } catch (HttpRequestException) { btn_send.Enabled = false; btn_start.Enabled = false; richTextBox1.AppendText("Connected failed to " + ServerURI + Environment.NewLine); return; } richTextBox1.AppendText("Connected to server at " + ServerURI + Environment.NewLine); }
internal ServiceAdapter(HubProxy proxy) { _proxy = proxy; }
public void Connect(string name) { btn_send.Enabled = false; HubProxy.Invoke("Connect", name); }