コード例 #1
0
        public Result GetWork(AsyncCallback callback)
        {
            var count      = 3;
            var checkAgain = false;

            do
            {
                try
                {
                    //get work
                    return(server.GetWork(callback));
                }
                catch (WebException webException)
                {
                    checkAgain = RequireWorkFromAnotherMine(webException);
                    if (checkAgain)
                    {
                        //pick up another server and try again
                        UpdateServerWithPreferredMineAndCredential();
                    }
                    else
                    {
                        logger.Error("Abort GetWork on WebException for bot " + bot.Id + " at " + bot.IPAddress, webException);
                    }
                }
                catch (Exception exception)
                {
                    logger.Error("Abort GetWork on Exception for bot " + bot.Id + " at " + bot.IPAddress, exception);
                    return(new Result()
                    {
                        HttpStatusCode = 404, DataText = "Server is offline.", Data = false
                    });
                }
            } while (checkAgain && --count > 0);

            return(new Result()
            {
                HttpStatusCode = 404, DataText = "All Servers are offline. (after 3 times check)", Data = false
            });
        }