/// <summary> /// This is a "actionmethod" /// ___________________________ /// It can be called from the javascript API like this. /// var json = { /// City: 'Sundsvall' /// }; /// ws.trigger('setcity', json); /// /// The model binder will convert json into our expected object "ViewModel" /// /// this.Send(...) will send a message to the client triggering the event. /// </summary> /// <param name="model"></param> public void SetCity(ViewModel model) { try { this.ViewModel.City = model.City; this.Send(model, "SetCity"); } catch (Exception ex) { //Note: To catch errors in the client listen for error like the example below. //ws.bind(XSockets.Events.onError, function (err) { // console.log('Error', err); //}); this.DispatchError(ex, "Exception in SetCity"); } }
/// <summary> /// Another "actionmethod" that you can trigger from the JsAPI like. /// var json = { /// Message: 'Hello Sundsvall', /// City: 'Sundsvall' /// }; /// ws.trigger('sendtocity', json); /// /// Note: this.SendTo filters where to sendthe message, we only want to send it to the city targeted. /// </summary> /// <param name="model"></param> public void SendToCity(ViewModel model) { try { //Note: this will hit the binding in the client that listens for 'SendToCity' //Note: BUT... It will only be sent to the "nodes" with the property City set to the city in the passed in ViewModel. //Note: This way we can target specific cients without binding to specific subjects. this.SendTo(n => ((GeoLocation)n.XSocket).ViewModel.City == model.City, model, "SendToCity"); } catch (Exception ex) { //Note: To catch errors in the client listen for error like the example below. //ws.bind(XSockets.Events.onError, function (err) { // console.log('Error', err); //}); this.DispatchError(ex, "Exception in SendToCity"); } }