public void Handle(TickMessage message)
		{
			var profile = _storageRepository.GetProfile<TestRunImportPluginProfile>();
			if (profile.FrameworkType == FrameworkTypes.FrameworkTypes.Selenium && profile.PostResultsToRemoteUrl)
			{
				return;
			}

			try
			{
				_log.InfoFormat("Started synchronizing at {0}", DateTime.Now);

				var lastModifyResults = _storageRepository.Get<LastModifyResult>();
				var lastModifyResult = lastModifyResults.Empty() ? new LastModifyResult() : lastModifyResults.Single();

				var jenkinsHudsonLastCompletedBuildNumber = profile.FrameworkType == FrameworkTypes.FrameworkTypes.JenkinsHudson ?
					GetJenkinsHudsonLastCompletedBuildNumber(profile) : null;

				if (profile.FrameworkType == FrameworkTypes.FrameworkTypes.JenkinsHudson &&
						(jenkinsHudsonLastCompletedBuildNumber == null || string.CompareOrdinal(lastModifyResult.ETagHeader, jenkinsHudsonLastCompletedBuildNumber) == 0))
				{
					_log.Info("No new modification of results source detected");
					return;
				}

				var uri = profile.FrameworkType == FrameworkTypes.FrameworkTypes.JenkinsHudson
										? new Uri(string.Format("{0}/lastCompletedBuild/testReport/api/xml", profile.ResultsFilePath.TrimEnd(new[] { '/', '\\' })))
										: new Uri(profile.ResultsFilePath);
				var factoryResult = _streamFactory.OpenStreamIfModified(uri, lastModifyResult, profile.PassiveMode);

				_log.InfoFormat("{0} modification of results source detected", factoryResult == null ? "No new" : "New");

				if (factoryResult != null)
				{
					if (profile.FrameworkType == FrameworkTypes.FrameworkTypes.JenkinsHudson)
					{
						factoryResult.LastModifyResult.ETagHeader = jenkinsHudsonLastCompletedBuildNumber;
					}

					lastModifyResults.Clear();
					lastModifyResults.Add(factoryResult.LastModifyResult);

					using (factoryResult.Stream)
					{
						using (var reader = new StreamReader(factoryResult.Stream))
						{
							try
							{
								var result = _resultsReaderFactory.GetResolver(profile, reader).GetTestRunImportResults();
								_log.InfoFormat("{0} items for import detected in resutls source", result.Count == 0 ? "No" : result.Count.ToString(CultureInfo.InvariantCulture));
								if (result.Count > 0)
								{
									_localBus.SendLocal(new TestRunImportResultDetectedLocalMessage
																				{
																					TestRunImportInfo =
																						new TestRunImportInfo { TestRunImportResults = result.ToArray() }
																				});
								}
							}
							catch (ApplicationException)
							{
								throw;
							}
							catch (XmlException ex)
							{
								throw new ApplicationException("Error parsing results XML file", ex);
							}
							catch (Exception ex)
							{
								throw new ApplicationException("Error importing results XML file", ex);
							}
						}
					}
				}
			}
			catch (UriFormatException ex)
			{
				_log.Error(ex.Message);
				throw new ApplicationException(string.Format("Specified path has invalid format. {0}", ex.Message), ex);
			}
			catch (ApplicationException ex)
			{
				_log.Error(ex.Message);
				throw;
			}
			catch (Exception ex)
			{
				_log.ErrorFormat("Could not read file \"{0}\": {1}", profile.ResultsFilePath, ex.Message);
				throw new ApplicationException(
					string.Format("Could not read file \"{0}\": {1}", profile.ResultsFilePath, ex.Message), ex);
			}
		}
コード例 #2
0
        private PluginCommandResponseMessage OnExecute()
        {
            var resultMessage = new PluginCommandResponseMessage
            {
                ResponseData = string.Empty, PluginCommandStatus = PluginCommandStatus.Succeed
            };

            var profile = _storageRepository.GetProfile <TestRunImportPluginProfile>();

            if (profile.FrameworkType == FrameworkTypes.FrameworkTypes.Selenium && profile.PostResultsToRemoteUrl)
            {
                return(resultMessage);
            }

            try
            {
                var uri           = new Uri(profile.ResultsFilePath);
                var factoryResult = _streamFactory.OpenStreamIfModified(uri, new LastModifyResult(), profile.PassiveMode);
                if (factoryResult != null)
                {
                    _storageRepository.Get <LastModifyResult>().Clear();
                    _storageRepository.Get <LastModifyResult>().Add(factoryResult.LastModifyResult);

                    using (factoryResult.Stream)
                    {
                        using (var reader = new StreamReader(factoryResult.Stream))
                        {
                            try
                            {
                                var result = _resultsReaderFactory.GetResolver(profile, reader).GetTestRunImportResults();
                                if (result.Count > 0)
                                {
                                    _localBus.SendLocal(new TestRunImportResultDetectedLocalMessage
                                    {
                                        TestRunImportInfo =
                                            new TestRunImportInfo {
                                            TestRunImportResults = result.ToArray()
                                        }
                                    });
                                }
                            }
                            catch (ApplicationException ex)
                            {
                                resultMessage.ResponseData        = ex.Message;
                                resultMessage.PluginCommandStatus = PluginCommandStatus.Error;
                            }
                            catch (XmlException ex)
                            {
                                resultMessage.ResponseData        = string.Format("Error parsing results XML file; {0}", ex.Message);
                                resultMessage.PluginCommandStatus = PluginCommandStatus.Error;
                            }
                            catch (Exception ex)
                            {
                                resultMessage.ResponseData        = string.Format("Error parsing results XML file; {0}", ex.Message);
                                resultMessage.PluginCommandStatus = PluginCommandStatus.Error;
                            }
                        }
                    }
                }
            }
            catch (UriFormatException ex)
            {
                resultMessage.ResponseData        = string.Format("Specified path has invalid format. {0}", ex.Message);
                resultMessage.PluginCommandStatus = PluginCommandStatus.Error;
            }
            catch (ApplicationException ex)
            {
                resultMessage.ResponseData        = string.Format("Specified path has invalid format. {0}", ex.Message);
                resultMessage.PluginCommandStatus = PluginCommandStatus.Error;
            }
            catch (Exception ex)
            {
                resultMessage.ResponseData        = string.Format("Could not read file \"{0}\": {1}", profile.ResultsFilePath, ex.Message);
                resultMessage.PluginCommandStatus = PluginCommandStatus.Error;
            }
            return(resultMessage);
        }