コード例 #1
0
		private static string GetResponse(string args)
		{
			var profile = args.DeserializeProfile();
			var settings = (ConnectionSettings) profile.Settings;
			var errors = new PluginProfileErrorCollection();

			settings.ValidateConnection(errors);
			if (errors.Any())
			{
				return errors.Serialize();
			}

			CheckConnection(settings, errors);
			return errors.Any() ? errors.Serialize() : string.Empty;
		}
コード例 #2
0
        private static string GetResponse(string args)
        {
            var profile  = args.DeserializeProfile();
            var settings = (ConnectionSettings)profile.Settings;
            var errors   = new PluginProfileErrorCollection();

            settings.ValidateConnection(errors);
            if (errors.Any())
            {
                return(errors.Serialize());
            }

            CheckConnection(settings, errors);
            return(errors.Any() ? errors.Serialize() : string.Empty);
        }
コード例 #3
0
		public void Execute(PluginProfileErrorCollection errors)
		{
			if (errors.Any())
				return;

			ExecuteConcreate(errors);
		}
コード例 #4
0
        protected override void OnCheckConnection(PluginProfileErrorCollection errors, GitPluginProfile settings)
        {
            settings.ValidateUri(errors);

            if (!errors.Any())
            {
                _folder = GitRepositoryFolder.Create(settings.Uri);
                var nativeGit = NGit.Api.Git.Init().SetDirectory(_folder.GetAbsolutePath()).Call();
                var transport = Transport.Open(nativeGit.GetRepository(), settings.Uri);
                try
                {
                    transport.SetCredentialsProvider(new UsernamePasswordCredentialsProvider(settings.Login, settings.Password));
                    transport.OpenFetch();
                }
                catch (EOFException ex)
                {
                    transport.Close();
                    throw new InvalidOperationException("Unable to connect to repository. Run 'git fsck' in the repository to check for possible errors.", ex);
                }
                catch
                {
                    transport.Close();
                    throw;
                }
            }
        }
コード例 #5
0
        public void Execute(PluginProfileErrorCollection errors)
        {
            if (errors.Any())
            {
                return;
            }

            ExecuteConcreate(errors);
        }
        protected override void OnCheckConnection(PluginProfileErrorCollection errors, SubversionPluginProfile settings)
        {
            settings.ValidateUri(errors);

            if (!errors.Any())
            {
                base.OnCheckConnection(errors, settings);
            }
        }
コード例 #7
0
		public bugzilla_properties CheckConnection(BugzillaProfile profile)
		{
			var errors = new PluginProfileErrorCollection();
			try
			{
				SetServerCertificateValidationCallback(profile);

				var validators = new Queue<Validator>();

				var connectionValidator = new ConnectionValidator(profile);
				validators.Enqueue(connectionValidator);

				var scriptValidator = new ScriptValidator(profile);
				validators.Enqueue(scriptValidator);

				var responseValidator = new ResponseValidator(profile, scriptValidator);
				validators.Enqueue(responseValidator);

				var deserializeValidator = new DeserializeValidator(profile, responseValidator);
				validators.Enqueue(deserializeValidator);

				var settingsValidator = new SettingsValidator(profile, deserializeValidator);
				validators.Enqueue(settingsValidator);

				var savedQueryValidator = new SavedQueryValidator(profile);
				validators.Enqueue(savedQueryValidator);

				while (validators.Count > 0)
				{
					var validator = validators.Dequeue();
					validator.Execute(errors);
				}

				if (errors.Any())
				{
					throw new BugzillaPluginProfileException(profile, errors);
				}

				return deserializeValidator.Data;
			}
			catch (BugzillaPluginProfileException)
			{
				throw;
			}
			catch (Exception ex)
			{
				errors.Add(new PluginProfileError
				           	{
				           		FieldName = BugzillaProfile.ProfileField,
				           		Message = string.Format("The connection with {0} is failed. {1}", profile, ex.Message)
				           	});
				throw new BugzillaPluginProfileException(profile, errors);
			}
		}
コード例 #8
0
        public bugzilla_properties CheckConnection(BugzillaProfile profile)
        {
            var errors = new PluginProfileErrorCollection();

            try
            {
                var validators = new Queue <Validator>();

                var connectionValidator = new ConnectionValidator(profile);
                validators.Enqueue(connectionValidator);

                var scriptValidator = new ScriptValidator(profile);
                validators.Enqueue(scriptValidator);

                var responseValidator = new ResponseValidator(profile, scriptValidator);
                validators.Enqueue(responseValidator);

                var deserializeValidator = new DeserializeValidator(profile, responseValidator);
                validators.Enqueue(deserializeValidator);

                var settingsValidator = new SettingsValidator(profile, deserializeValidator);
                validators.Enqueue(settingsValidator);

                var savedQueryValidator = new SavedQueryValidator(profile);
                validators.Enqueue(savedQueryValidator);

                while (validators.Count > 0)
                {
                    var validator = validators.Dequeue();
                    validator.Execute(errors);
                }

                if (errors.Any())
                {
                    throw new BugzillaPluginProfileException(profile, errors);
                }

                return(deserializeValidator.Data);
            }
            catch (BugzillaPluginProfileException)
            {
                throw;
            }
            catch (Exception ex)
            {
                errors.Add(new PluginProfileError
                {
                    FieldName = BugzillaProfile.ProfileField,
                    Message   = string.Format("The connection with {0} is failed. {1}", profile, ex.Message)
                });
                throw new BugzillaPluginProfileException(profile, errors);
            }
        }
コード例 #9
0
        protected override void OnCheckConnection(PluginProfileErrorCollection errors, MercurialPluginProfile settings)
        {
            settings.ValidateUri(errors);

            if (!errors.Any())
            {
                var identifyCommand = new IdentifyCommand().WithPath(settings.Uri).WithTimeout(20);
                NonPersistentClient.Execute(identifyCommand);
                if (identifyCommand.RawExitCode != 0)
                {
                    throw new Exception("Can't establish connection");
                }
            }
        }
コード例 #10
0
		public PluginCommandResponseMessage Execute(string args, UserDTO user)
		{
			var errors = new PluginProfileErrorCollection();
			var profile = args.DeserializeProfile();
			var settings = (BugzillaProfile) profile.Settings;

			var properties = GetBugzillaProperties(settings, errors);

			return errors.Any()
			       	? new PluginCommandResponseMessage
			       	  	{PluginCommandStatus = PluginCommandStatus.Fail, ResponseData = errors.Serialize()}
			       	: new PluginCommandResponseMessage
			       	  	{PluginCommandStatus = PluginCommandStatus.Succeed, ResponseData = properties.Serialize()};
		}
コード例 #11
0
        private static void CheckVersions(bugzilla_properties bugzillaProperties, PluginProfileErrorCollection errors)
        {
            if (!ScriptVersionIsValid(bugzillaProperties.script_version))
            {
                errors.Add(
                    new PluginProfileError
                {
                    Message = string.Format(
                        TP2_CGI_IS_NOT_SUPPORTED_BY_THIS_PLUGIN,
                        string.IsNullOrEmpty(bugzillaProperties.script_version) ? "undefined" : bugzillaProperties.script_version),
                    AdditionalInfo = ValidationErrorType.InvalidTpCgiVersion.ToString()
                });
            }

            if (!errors.Any() && !BugzillaVersionIsSupported(bugzillaProperties.version))
            {
                errors.Add(new PluginProfileError
                {
                    Message = string.Format(
                        BUGZILLA_VERSION_IS_NOT_SUPPORTED_BY_PLUGIN,
                        bugzillaProperties.version),
                    AdditionalInfo = ValidationErrorType.InvalidBugzillaVersion.ToString()
                });
            }

            if (!errors.Any() && !ScriptSupportsProvidedBugzillaVersion(bugzillaProperties.version, bugzillaProperties.supported_bugzilla_version))
            {
                errors.Add(new PluginProfileError
                {
                    Message = string.Format(
                        BUGZILLA_VERSION_IS_NOT_SUPPORTED_BY_TP2_CGI,
                        bugzillaProperties.version),
                    AdditionalInfo = ValidationErrorType.InvalidTpCgiVersion.ToString()
                });
            }
        }
コード例 #12
0
        public PluginCommandResponseMessage Execute(string args)
        {
            var mashup = args.Deserialize <T>();

            NormalizeMashup(mashup);
            PluginProfileErrorCollection errors = ExecuteOperation(mashup);

            return(new PluginCommandResponseMessage
            {
                PluginCommandStatus = errors.Any()
                                                                      ? PluginCommandStatus.Fail
                                                                      : PluginCommandStatus.Succeed,
                ResponseData = errors.Serialize()
            });
        }
コード例 #13
0
		private static void CheckVersions(bugzilla_properties bugzillaProperties, PluginProfileErrorCollection errors)
		{
			if (!ScriptVersionIsValid(bugzillaProperties.script_version))
			{
				errors.Add(
					new PluginProfileError
						{
							Message = string.Format(
								TP2_CGI_IS_NOT_SUPPORTED_BY_THIS_PLUGIN,
								string.IsNullOrEmpty(bugzillaProperties.script_version) ? "undefined" : bugzillaProperties.script_version),
							AdditionalInfo = ValidationErrorType.InvalidTpCgiVersion.ToString()
						});
			}

			if (!errors.Any() && !BugzillaVersionIsSupported(bugzillaProperties.version))
			{
				errors.Add(new PluginProfileError
				           	{
				           		Message = string.Format(
				           			BUGZILLA_VERSION_IS_NOT_SUPPORTED_BY_PLUGIN,
				           			bugzillaProperties.version),
									AdditionalInfo = ValidationErrorType.InvalidBugzillaVersion.ToString()
				           	});
			}

			if (!errors.Any() && !ScriptSupportsProvidedBugzillaVersion(bugzillaProperties.version, bugzillaProperties.supported_bugzilla_version))
			{
				errors.Add(new PluginProfileError
				           	{
								Message = string.Format(
									BUGZILLA_VERSION_IS_NOT_SUPPORTED_BY_TP2_CGI,
									bugzillaProperties.version),
								AdditionalInfo = ValidationErrorType.InvalidTpCgiVersion.ToString()
							});
			}
		}
コード例 #14
0
        public PluginCommandResponseMessage Execute(string args)
        {
            var errors   = new PluginProfileErrorCollection();
            var profile  = args.DeserializeProfile();
            var settings = (BugzillaProfile)profile.Settings;

            var properties = GetBugzillaProperties(settings, errors);

            return(errors.Any()
                                ? new PluginCommandResponseMessage
            {
                PluginCommandStatus = PluginCommandStatus.Fail, ResponseData = errors.Serialize()
            }
                                : new PluginCommandResponseMessage
            {
                PluginCommandStatus = PluginCommandStatus.Succeed, ResponseData = properties.Serialize()
            });
        }
コード例 #15
0
		protected void ValidateNameUniqueness(PluginProfileErrorCollection errors, MashupManagerProfile profile)
		{
			if (errors.Any())
				return;

			var existsSuchName = profile != null && profile.MashupNames
															.Any(
																m => m.Equals(Name, StringComparison.InvariantCultureIgnoreCase));

			if (existsSuchName)
			{
				errors.Add(new PluginProfileError
				{
					FieldName = NameField,
					Message = "Mashup with the same name already exists"
				});
			}
		}
コード例 #16
0
        protected void ValidateNameUniqueness(PluginProfileErrorCollection errors, MashupManagerProfile profile)
        {
            if (errors.Any())
            {
                return;
            }

            var existsSuchName = profile != null && profile.MashupNames
                                 .Any(
                m => m.Equals(Name, StringComparison.InvariantCultureIgnoreCase));

            if (existsSuchName)
            {
                errors.Add(new PluginProfileError
                {
                    FieldName = NameField,
                    Message   = "Mashup with the same name already exists"
                });
            }
        }
コード例 #17
0
		public BugzillaProperties GetBugzillaProperties(BugzillaProfile profile, PluginProfileErrorCollection errors)
		{
			profile.ValidateCredentials(errors);

			if (!errors.Any())
			{
				try
				{
					_logger.Info("Checking connection");
					var bugzillaProperties = new BugzillaService().CheckConnection(profile);
					_logger.Info("Connection success");
					return new BugzillaProperties(bugzillaProperties);
				}
				catch (BugzillaPluginProfileException e)
				{
					e.ErrorCollection.ForEach(errors.Add);
					_logger.WarnFormat("Connection failed: {0}", e);
				}
			}

			return null;
		}
コード例 #18
0
        public BugzillaProperties GetBugzillaProperties(BugzillaProfile profile, PluginProfileErrorCollection errors)
        {
            profile.ValidateCredentials(errors);

            if (!errors.Any())
            {
                try
                {
                    _logger.Info("Checking connection");
                    var bugzillaProperties = new BugzillaService().CheckConnection(profile);
                    _logger.Info("Connection success");
                    return(new BugzillaProperties(bugzillaProperties));
                }
                catch (BugzillaPluginProfileException e)
                {
                    e.ErrorCollection.ForEach(errors.Add);
                    _logger.WarnFormat("Connection failed: {0}", e);
                }
            }

            return(null);
        }
コード例 #19
0
        protected override void OnCheckConnection(PluginProfileErrorCollection errors, TfsPluginProfile settings)
        {
            settings.ValidateStartRevision(errors);
            settings.ValidateUri(errors);

            if (!errors.Any())
            {
                TfsTeamProjectCollection collection = null;

                try
                {
                    TfsConnectionParameters parameters = TfsConnectionHelper.GetTfsConnectionParameters(settings);

                    switch (parameters.SegmentsCount)
                    {
                    case UriTfsProjectCollection:
                    {
                        collection = new TfsTeamProjectCollection(parameters.TfsCollectionUri, parameters.Credential);
                        collection.EnsureAuthenticated();
                        collection.Connect(ConnectOptions.None);

                        var vcs = collection.GetService <VersionControlServer>();
                        CheckChangeset(settings, vcs);

                        break;
                    }

                    case UriTfsTeamProject:
                    {
                        collection = new TfsTeamProjectCollection(parameters.TfsCollectionUri, parameters.Credential);
                        collection.EnsureAuthenticated();
                        collection.Connect(ConnectOptions.None);

                        var         vcs         = collection.GetService <VersionControlServer>();
                        TeamProject teamProject = vcs.GetTeamProject(parameters.TeamProjectName);

                        CheckChangeset(settings, vcs, teamProject);

                        break;
                    }

                    default:
                        errors.Add(new PluginProfileError {
                            FieldName = "Uri", Message = "Could not connect to server."
                        });
                        break;
                    }
                }
                catch (TeamFoundationServerUnauthorizedException e)
                {
                    errors.Add(
                        new PluginProfileError
                    {
                        Status         = PluginProfileErrorStatus.WrongCredentialsError,
                        FieldName      = "Login",
                        Message        = "Authorization failed.",
                        AdditionalInfo = e.Message
                    });
                    errors.Add(
                        new PluginProfileError
                    {
                        Status         = PluginProfileErrorStatus.WrongCredentialsError,
                        FieldName      = "Password",
                        Message        = "Authorization failed.",
                        AdditionalInfo = e.Message
                    });
                }
                catch (ResourceAccessException e)
                {
                    errors.Add(new PluginProfileError
                    {
                        AdditionalInfo = e.Message,
                        FieldName      = "Uri",
                        Message        = "Resource access denied",
                        Status         = PluginProfileErrorStatus.Error
                    });
                }
                catch (ChangesetNotFoundException e)
                {
                    errors.Add(new PluginProfileError
                    {
                        AdditionalInfo = e.Message,
                        FieldName      = "StartRevision",
                        Message        = "There’s no such revision.",
                        Status         = PluginProfileErrorStatus.UnexistedRevisionWarning
                    });
                }
                catch (TeamFoundationServiceUnavailableException e)
                {
                    errors.Add(new PluginProfileError
                    {
                        AdditionalInfo = e.Message,
                        FieldName      = "Uri",
                        Message        = "Could not connect to server.",
                    });
                }
                finally
                {
                    if (collection != null)
                    {
                        collection.Dispose();
                    }
                }
            }
        }
コード例 #20
0
 public void CheckConnectionIsValid()
 {
     _errors.Any().Should(Be.False);
 }
コード例 #21
0
 public void ErrorShouldOccur(string fieldName, string errorMessage)
 {
     _errors.Any(x => x.FieldName == fieldName && x.Message == errorMessage).Should(Be.True);
 }