示例#1
0
 static void Main(string[] args)
 {
     try
     {
         ClientCommunicator clientCommunicator      = new ClientCommunicator();
         Task <ChampionPicksTurnAndPosition> retval = clientCommunicator.getChampionsPicked();
         retval.Wait();
         var result = retval.Result;
         Console.WriteLine(retval.Result);
     } catch (Exception e)
     {
         Console.WriteLine(e);
     }
 }
示例#2
0
        private void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            ClientCommunicator clientCommunicator      = new ClientCommunicator();
            Task <ChampionPicksTurnAndPosition> retval = clientCommunicator.getChampionsPicked();

            try
            {
                retval.Wait();
            } catch
            {
                Console.WriteLine("Cant contact the client.");
                //todo uncomment
                //ResetUI(true);
                return;
            }

            var result = retval.Result;

            Console.WriteLine("SEND IT");
            if (result.picks.Count() > 0 && result.picks.Count() < 10)
            {
                Console.WriteLine("PICK---------------------------------------------------------------");
                var client  = new RestClient("http://localhost:9090/api/pick");
                var request = new RestRequest(Method.POST);
                request.AddHeader("cache-control", "no-cache");
                request.AddHeader("content-type", "application/json");
                ChampionPicksAndPosition cpp = new ChampionPicksAndPosition(result.picks, result.position);
                request.AddParameter("application/json", cpp.toJson(), ParameterType.RequestBody);
                //IRestResponse response = client.Execute(request);
                Task <ChampionPicksAndChampionSelect> retval2 = client.PostAsync <ChampionPicksAndChampionSelect>(request);
                retval2.Wait();
                if (retval2.Result == null)
                {
                    ResetUI(true);
                    MainContent = "There has been too many requests from your IP address. If this is a false alert, try to use the service later again.";
                }
                else
                {
                    cpcs = retval2.Result;
                    UpdateUI(true);
                }
            }
            else if (result.picks.Count() == 10)
            {
                Console.WriteLine("ADVICE ---------------------------------------------------------------");
                var client  = new RestClient("http://localhost:9090/api/advice");
                var request = new RestRequest(Method.POST);
                request.AddHeader("cache-control", "no-cache");
                request.AddHeader("content-type", "application/json");
                ChampionPicksAndPosition cpp = new ChampionPicksAndPosition(result.picks, result.position);
                request.AddParameter("application/json", cpp.toJson(), ParameterType.RequestBody);
                //IRestResponse response = client.Execute(request);
                Task <ChampionPicksAndChampionSelect> retval2 = client.PostAsync <ChampionPicksAndChampionSelect>(request);
                retval2.Wait();
                if (retval2.Result == null)
                {
                    ResetUI(true);
                    MainContent = "There has been too many requests from your IP address. If this is a false alert, try to use the service later again.";
                }
                else
                {
                    cpcs = retval2.Result;
                    UpdateUI(false);
                }
            }
        }