Пример #1
0
 /// <summary>
 /// Processes the unprocessed result with json.
 /// </summary>
 /// <param name="groupName">Name of the group.</param>
 private static void ProcessUnprocessedResultWithJson(string groupName)
 {
     try
     {
         var settings   = SettingsHelper.Get();
         var resultData = TestDataApi.Get <List <ReportData> >(string.Format(EndPoints.GetAllUnprocessedReports, groupName));
         if (!resultData.IsError)
         {
             foreach (var item in resultData.Item)
             {
                 string path = settings.BaseReportPath + "\\" + groupName + "\\JSON\\" + item.TestQueueId + "-" + item.Os.ToLower() + "-" + item.BrowserName.ToLower() + ".json";
                 if (File.Exists(path))
                 {
                     string jsonString = File.ReadAllText(path);
                     JavaScriptSerializer serializer = new JavaScriptSerializer();
                     object output = serializer.Deserialize <object>(jsonString);
                     TestDataApi.Post <object>("api/report", output);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         LoggerService.LogException("ProcessUnprocessedResultWithJson: " + ex.Message);
     }
 }
Пример #2
0
        public static void ExecuteServiceThread(Object tQ)
        {
            try
            {
                ResultMessage <List <TestQueue> > testQueue = tQ as ResultMessage <List <TestQueue> >;
                FileGenerator fileGenerator = new FileGenerator(testQueue.Item);
                string        directoryName = fileGenerator.GenerateSpecFiles();

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

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

                    TestDataApi.Post(string.Format(EndPoints.SchedulerHistoryStatus, groupName, (int)SchedulerExecutionStatus.InProgress), new SchedulerHistory());

                    ProtractorCommandRunner protractorCommandRunner = new ProtractorCommandRunner();

                    double maxExecutionTime = TimeSpan.FromMinutes(testQueue.Item.Count * testQueue.Item[0].Browsers.Count * 10).TotalMilliseconds;

                    protractorCommandRunner.ExecuteCommand(groupName, maxExecutionTime);

                    TestDataApi.Post(string.Format(EndPoints.SchedulerHistoryStatus, groupName, (int)SchedulerExecutionStatus.Completed), new SchedulerHistory());

                    ProcessUnprocessedResultWithJson(groupName);

                    ProcessEmail(testQueue, groupName);

                    ImageProcessor.ProcessImages(groupName);
                }

                Hub hubInfo = testQueue.Item.FirstOrDefault().hubInfo;
                DeleteHub(hubInfo.ProcessId, hubInfo.SeleniumAddress);
            }
            catch (Exception ex)
            {
                ResultMessage <List <TestQueue> > testQueue = tQ as ResultMessage <List <TestQueue> >;
                Hub hubInfo = testQueue.Item.FirstOrDefault().hubInfo;
                DeleteHub(hubInfo.ProcessId, hubInfo.SeleniumAddress);
                LoggerService.LogException(ex);
            }
        }
Пример #3
0
        /// <summary>
        /// Processes the email.
        /// </summary>
        /// <param name="testQueue">The test queue.</param>
        /// <param name="groupName">Name of the group.</param>
        /// <param name="schedulerExecutionStatus">The scheduler execution status.</param>
        private static void ProcessEmail(ResultMessage <List <TestQueue> > testQueue, string groupName, SchedulerExecutionStatus schedulerExecutionStatus)
        {
            var emailStatus = SchedulerHistoryEmailStatus.NotSent;

            if (testQueue != null && testQueue.Item != null && groupName.IsNotBlank())
            {
                var schedulerIds = testQueue.Item.Select(x => x.SchedulerId).Distinct();

                var resultData = TestDataApi.Post <SearchReportObject, SearchReportResult>(EndPoints.ReportSearch, new SearchReportObject {
                    ExecutionGroup = groupName
                });

                if (resultData == null || resultData.IsError)
                {
                    emailStatus = SchedulerHistoryEmailStatus.SendException;
                }
                else if (resultData.Item != null)
                {
                    var emailProcessor = new EmailProcessor();

                    foreach (var schedulerId in schedulerIds)
                    {
                        if (!schedulerId.HasValue)
                        {
                            continue;
                        }

                        var schedularData = TestDataApi.Get <Scheduler>(string.Format(EndPoints.SchedulerById, schedulerId));

                        if (schedularData != null && !schedularData.IsError && schedularData.Item != null)
                        {
                            schedularData.Item.Status = schedulerExecutionStatus;
                            var repostData = new ReportResultData(resultData.Item.Data, schedularData.Item, groupName);
                            emailStatus = emailProcessor.EmailReport(repostData);
                        }
                    }
                }
            }

            TestDataApi.Post(string.Format(EndPoints.SchedulerHistoryEmailStatus, groupName, (int)emailStatus), new List <SchedulerHistory>());
        }
Пример #4
0
        /// <summary>
        /// Executes the service.
        /// </summary>
        public static void ExecuteService()
        {
            var testQueue = TestDataApi.Get <List <TestQueue> >(EndPoints.GetTestQueue);

            if (!testQueue.IsError && testQueue.Item != null)
            {
                testQueue.Item.ForEach(x => x.Status = 1);
                var updateResult = TestDataApi.Post(EndPoints.BulkUpdateTestQueue, testQueue.Item);
                if (!updateResult.IsError)
                {
                    Hub hub = GetHubBySeleniumAddress(testQueue.Item[0].Settings.SeleniumAddress);
                    if (hub == null)
                    {
                        Hub hubCreated = AddHub(Guid.NewGuid(), testQueue.Item[0].Settings.SeleniumAddress);
                        testQueue.Item.ForEach(x => x.hubInfo = hubCreated);
                        ThreadPool.QueueUserWorkItem(new WaitCallback(ExecuteServiceThread), testQueue);
                    }
                    else
                    {
                        _QueuedTest[Guid.NewGuid()] = testQueue;
                    }
                }
            }
            else
            {
                foreach (var item in _QueuedTest)
                {
                    Hub hubPast = GetHubBySeleniumAddress(item.Value.Item[0].Settings.SeleniumAddress);
                    if (hubPast == null)
                    {
                        Hub hubCreated = AddHub(Guid.NewGuid(), item.Value.Item[0].Settings.SeleniumAddress);
                        item.Value.Item.ForEach(x => x.hubInfo = hubCreated);
                        ThreadPool.QueueUserWorkItem(new WaitCallback(ExecuteServiceThread), item.Value);
                        ResultMessage <List <TestQueue> > h;
                        _QueuedTest.TryRemove(item.Key, out h);
                    }
                }
            }
        }
Пример #5
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);
            }
        }