Web service and filtering list

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Saser
    New Member
    • Jul 2009
    • 17

    Web service and filtering list

    Hi. I have two questions.

    #1. I'm thinking of creating a web service which contain a list object which contain a number of entrys of the own-defined class Match, which will have the variables:
    MapID (int)
    Number of players (int)
    SkillLevel (enum)
    ServerIsOn (bool)
    In a Windows application you can either choose to search for matches or create a match which will be searchable to others. If you choose to create a match, a new instance of the Match object is created with the settings you specify and then added to the list on the web service.If you choose to search for matches instead, you retrieve the list and filter it (see question #2), and retrieve the list from the server again every 10 seconds or when the user self press an Update-button. Now, to my question:
    How do I create a web service for this?
    Can you show me some examples? I'd be grateful if you also showed me some example methods for the application as well.

    #2. When you've retrieved the list from the server, you want to filter it to only show the results you want to see. How do you do that? Like this?
    Code:
    private void filter()
    {
        foreach (Match m in retrievedList)
        {
            if (m.MapID == map && m.NumberOfPlayers == nrOfPlayers && m.SkillLevel == skill && m.ServerIsOn == serverOn)
            {
                filteredList.Add(m);
            }
        }
    
        // methods for displaying the filtered list in the application
        ...
    }
    Thanks in advance.

    Oh, and sorry for my English and for a messy post :P
  • cloud255
    Recognized Expert Contributor
    • Jun 2008
    • 427

    #2
    Hi,

    I would suggest doing the filtering on the server, this will save having to transfer a full list to the client every X seconds.

    I would override the Filter method to cater for the possible combinations of settings; a quick example:

    Code:
    Public List<Match> Filter()
    {
        //return all available matches
    }
    
    Public List<Match> Filter(int MapID)
    {
        //return all matches for a specific map regardless of other settings
    }
    
    Public List<Match> Filter(int MapID, int NumPlayers)
    {
        //return all matches for a specific map and number of players
    }
    Using Linq for your actual filtering will probably be faster than using foreach loops, when creating an application like this you need to pay alot of attention to optimization.

    As for the client updating every X seconds (10 might be a bit short) the client should run a thread with a timer that requests the server to perform a new filter operation, you can interrupt this thread to send a manual refresh request. Take note to make communication asynchronous as if the server is unavailable your client will forever try to get data from the server.

    Comment

    • Saser
      New Member
      • Jul 2009
      • 17

      #3
      Thanks for your answer.

      If I'd override the Filter() method, I'd need to create an override for every possible combination of settings, for example I'd need to create one method for players and map, another for players and skill, another for map and skill and so forth...
      Kinda nooby question, but is it really necessary to do this? Can't I just create one Filter() method which includes all parameters, and if I want to search for e.g. matches with 3 players, skilllevel any and de_inferno as map and don't care if server is on or off, can't I just call the filter method with this parameters (ServerIsOn as an enum instead of bool):
      Code:
      List<Match> matchList = WebService.Filter(1, 3, Skill.Any, ServerStatus.Any);
      I'm not really into threading and I don't know anything about Linq, can you link me some tutorial or show examples of what you mean?
      Thanks in advance.

      Comment

      • cloud255
        Recognized Expert Contributor
        • Jun 2008
        • 427

        #4
        Originally posted by Saser
        If I'd override the Filter() method, I'd need to create an override for every possible combination of settings, for example I'd need to create one method for players and map, another for players and skill, another for map and skill and so forth...
        Kinda nooby question, but is it really necessary to do this?
        No you can use just one function, the function might just become a bit big and hard to maintain IMHO.

        Originally posted by Saser
        I'm not really into threading and I don't know anything about Linq, can you link me some tutorial or show examples of what you mean?
        Linq
        Thread Class
        Threading tips

        Hope this helps

        Comment

        Working...