コード例 #1
0
        public static TfsConnectionParameters GetTfsConnectionParameters(ISourceControlConnectionSettingsSource settings)
        {
            try
            {
                var parameters = new TfsConnectionParameters {
                    Credential = CreateCredential(settings)
                };

                var      uri = new Uri(settings.Uri);
                string[] absolutePathSegments     = uri.LocalPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                string   possibleVirtualDirectory = absolutePathSegments[0];
                string[] segements          = settings.Uri.Split('/');
                string[] serverPathSegments = segements.TakeWhile(x => !x.Equals(possibleVirtualDirectory, StringComparison.OrdinalIgnoreCase)).ToArray();
                string   serverPath         = String.Join("/", serverPathSegments);

                if (CheckTfsServerPath(serverPath, parameters.Credential))
                {
                    parameters.TfsCollectionUri = new Uri(serverPath + "/" + possibleVirtualDirectory);

                    if (absolutePathSegments.Length > 1)
                    {
                        parameters.TeamProjectName = absolutePathSegments[1];
                    }

                    parameters.SegmentsCount = absolutePathSegments.Length;

                    return(parameters);
                }

                serverPath += "/" + possibleVirtualDirectory;

                if (!CheckTfsServerPath(serverPath, parameters.Credential))
                {
                    throw new TeamFoundationServiceUnavailableException("Could not connect to server.");
                }

                string[] pathSegments = absolutePathSegments.SkipWhile(x => !x.Equals(absolutePathSegments[1], StringComparison.OrdinalIgnoreCase)).ToArray();

                parameters.TfsCollectionUri = new Uri(serverPath + "/" + pathSegments[0]);

                if (pathSegments.Length > 1)
                {
                    parameters.TeamProjectName = pathSegments[1];
                }

                parameters.SegmentsCount = pathSegments.Length;
                return(parameters);
            }
            catch (TeamFoundationServiceUnavailableException)
            {
                throw;
            }
            catch
            {
                throw new Exception("Wrong URI format.");
            }
        }
コード例 #2
0
        public static TfsConnectionParameters GetTfsConnectionParameters(ISourceControlConnectionSettingsSource settings)
        {
            try
            {
                var parameters = new TfsConnectionParameters {Credential = CreateCredential(settings)};

                var uri = new Uri(settings.Uri);
                string[] absolutePathSegments = uri.LocalPath.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
                string possibleVirtualDirectory = absolutePathSegments[0];
                string[] segements = settings.Uri.Split('/');
                string[] serverPathSegments = segements.TakeWhile(x => !x.Equals(possibleVirtualDirectory, StringComparison.OrdinalIgnoreCase)).ToArray();
                string serverPath = String.Join("/", serverPathSegments);

                if (CheckTfsServerPath(serverPath, parameters.Credential))
                {
                    parameters.TfsCollectionUri = new Uri(serverPath + "/" + possibleVirtualDirectory);

                    if (absolutePathSegments.Length > 1)
                        parameters.TeamProjectName = absolutePathSegments[1];

                    parameters.SegmentsCount = absolutePathSegments.Length;

                    return parameters;
                }

                serverPath += "/" + possibleVirtualDirectory;

                if (!CheckTfsServerPath(serverPath, parameters.Credential))
                    throw new TeamFoundationServiceUnavailableException("Could not connect to server.");

                string[] pathSegments = absolutePathSegments.SkipWhile(x => !x.Equals(absolutePathSegments[1], StringComparison.OrdinalIgnoreCase)).ToArray();

                parameters.TfsCollectionUri = new Uri(serverPath + "/" + pathSegments[0]);

                if (pathSegments.Length > 1)
                    parameters.TeamProjectName = pathSegments[1];

                parameters.SegmentsCount = pathSegments.Length;
                return parameters;
            }
            catch (TeamFoundationServiceUnavailableException)
            {
                throw;
            }
            catch
            {
                throw new Exception("Wrong URI format.");
            }
        }
コード例 #3
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();
                    }
                }
            }
        }