Example #1
0
        /// <summary>
        ///     Attempts to Deserialize the incoming message to a Request object, then excutes it.
        /// </summary>
        /// <param name="message"></param>
        public void ProcessMessage(BrokeredMessage message)
        {
            WorkerRequest workerRequest = null;

            try
            {
                var request = message.GetBody <Request>();
                Console.WriteLine("Decoded the message " + request.Guid);
                workerRequest = JsonConvert.DeserializeObject <WorkerRequest>(JsonConvert.SerializeObject(request),
                                                                              new CommandConverter());
                message.Complete();
            }
            catch (Exception e)
            {
                //The message could not be parsed. Calls "message.DeadLetter();" so the message isn't read again and again.
                //TODO:Needs a way to let master know that a request was in wrong format so that master can let the user know.
                message.DeadLetter();
                Console.WriteLine("////////////////////EXCEPTION trown: " + e.Message);
                //throw;
            }
            if (workerRequest != null)
            {
                try

                {
                    //Worker implements IDisposable, so the using statement makes sure everything is disposed of.
                    WorkerResponse response;
                    using (var worker = new PhantomWorker())
                    {
                        var tClient = new TelemetryClient();
                        tClient.TrackEvent("Working on " + workerRequest.Guid);
                        response = worker.ExecuteRequest(workerRequest);
                        Console.WriteLine("Response retrieved");
                    }
                    SendResponse(response);
                }
                catch (Exception e)
                {
                    //Something went wrong with the worker.
                    //TODO:Let user know something went wrong and he should try again
                    message.DeadLetter();
                    Console.WriteLine("////////////////////EXCEPTION trown: " + e.Message);
                    //throw;
                }
            }
        }
Example #2
0
        public WorkerResponse ExecuteRequest(WorkerRequest request)
        {
            var commandNr      = 1;
            var commandResults = new List <string>();

            _driver.Navigate().GoToUrl(request.RootUrl);
            foreach (var command in request.Commands)
            {
                var success = command.Execute(_driver);
                commandResults.Add("Command nr " + commandNr + " '" + command.Cmd + "' - " + (success ? "success" : "failed"));
                commandNr++;
            }
            var response = new WorkerResponse {
                Assertions = commandResults, Guid = request.Guid, Timestamp = request.Timestamp
            };

            if (request.ReturnHtml)
            {
                response.HtmlBody = _driver.PageSource;
            }
            return(response);
        }