Beispiel #1
0
        /// <summary>
        /// Executes the service thread.
        /// </summary>
        /// <param name="testQueueData">The test queue data.</param>
        public static void ExecuteServiceThread(object testQueueData)
        {
            try
            {
                ResultMessage <List <TestQueue> > testQueue = testQueueData as ResultMessage <List <TestQueue> >;
                FileGenerator fileGenerator = new FileGenerator(testQueue.Item);
                string        directoryName = fileGenerator.GenerateSpecFiles();

                if (!string.IsNullOrWhiteSpace(directoryName))
                {
                    new ProtractorConfigJsBuilder().Create(testQueue.Item[0], testQueue.Item.Count);

                    string groupName = testQueue.Item[0].GroupName;

                    var schedulerHistory = testQueue.Item[0].SchedulerId > 0
                                               ? TestDataApi.Get <SchedulerHistory>(string.Format(EndPoints.SchedulerHistory, groupName))
                                               : new ResultMessage <SchedulerHistory>();

                    if (schedulerHistory.Item == null || !schedulerHistory.Item.IsCancelled)
                    {
                        TestDataApi.Post(string.Format(EndPoints.SchedulerHistoryStatus, groupName, (int)SchedulerExecutionStatus.InProgress), new List <SchedulerHistory>());

                        ProtractorCommandRunner protractorCommandRunner = new ProtractorCommandRunner();

                        var status = protractorCommandRunner.ExecuteCommand(groupName);

                        schedulerHistory = testQueue.Item[0].SchedulerId > 0
                           ? TestDataApi.Get <SchedulerHistory>(string.Format(EndPoints.SchedulerHistory, groupName))
                           : new ResultMessage <SchedulerHistory>();

                        status = (schedulerHistory.Item == null || !schedulerHistory.Item.IsCancelled)
                                     ? status
                                     : SchedulerExecutionStatus.Cancelled;

                        TestDataApi.Post(string.Format(EndPoints.SchedulerHistoryStatus, groupName, (int)status), new List <SchedulerHistory>());

                        ProcessUnprocessedResultWithJson(groupName);
                    }
                    else
                    {
                        TestDataApi.Post(string.Format(EndPoints.SchedulerHistoryStatus, groupName, schedulerHistory.Item.Status == SchedulerExecutionStatus.CancelledCallBackIssue ? (int)SchedulerExecutionStatus.CancelledCallBackIssue : (int)SchedulerExecutionStatus.Cancelled), new List <SchedulerHistory>());
                    }

                    if (schedulerHistory.Item != null)
                    {
                        ProcessEmail(testQueue, groupName, schedulerHistory.Item.Status);
                    }

                    ImageProcessor.ProcessImages(groupName);
                }

                Hub hubInfo = testQueue.Item.First().HubInfo;

                DeleteHub(hubInfo.ProcessId, hubInfo.SeleniumAddress);
            }
            catch (Exception ex)
            {
                ResultMessage <List <TestQueue> > testQueue = testQueueData as ResultMessage <List <TestQueue> >;
                Hub hubInfo = testQueue.Item.First().HubInfo;
                DeleteHub(hubInfo.ProcessId, hubInfo.SeleniumAddress);
                LoggerService.LogException("ExecuteServiceThread: " + ex.Message);
            }
        }