Find Clients
Most methods used when working with controller are extension methods. This is also true for the Find
methods, and you can write your own extensions as well. We will walk through that in the Custom Extensions
section.
When sending data directly to the clients you use PUB/SUB
or RPC/RMI
. The PUB/SUB
extensions start with Publish
and the RPC/RMI
extensions start with Invoke
. However, you can also find client on any controller using the FindOn
extension. You can then iterate over the result to accomplish various tasks. You might change some property (state) on the controller.
FindOn<T>
Since the extension is generic you can find instances on any controller T
. There is 3 overloads of FindOn<T>
and you will see examples of them below.
This sample controller will be used in the FindOn<T>
samples. We have properties (Name
and Age
) on the sample controller that will be used to filter out clients.
public class Chat : XSocketController
{
public string Name { get; set; }
public int Age { get; set; }
}
FindOn<T>()
This extension will return all instances connected to the controller of type T
var chatInstances = this.FindOn<Chat>();
FindOn<T>(Func<T,bool> exp)
This extension will return all instances connected to the controller of type T
that match the expression Func<T,bool>
var chatInstances = this.FindOn<Chat>(p => p.Age > 20);
So that statement above will only return instances that has the Age
property set to 21
or more.
FindOn<T>(Func<T,bool> expression, Action<IEnumerable<T>> action)
This extension will take an Action<IEnumerable<T>>
as second parameter. You can then process the result in the Action
. As before the result will be based on the Func<T,bool>
passed in.
this.FindOn<Chat>(p => p.Name == "Steve", (i)=>{
//process the result
});
So that statement above will only return instances that has the Name
property set to Steve
or more.