Example #1
0
        public object Get(ConnectionRequest request)
        {
            var result = ConnectionResult.UnknownTarget;

            if (request.Type == null)
            {
                return(result);
            }

            switch (request.Type.ToLowerInvariant())
            {
            case "tfs":
                string.Format("Connecting to TFS using {0}", request).Debug();
                var tfs = new TfsConnection();
                result = tfs.Connect(request.Url, request.User, request.Password);
                break;

            case "jira":
                string.Format("Connecting to JIRA using {0}", request).Debug();
                var jira = new JiraConnection();
                result = jira.Connect(request.Url, request.User, request.Password);
                break;

            case "githubissues":
                string.Format("Connecting to GitHub (Issues) using {0}", request).Debug();
                var githubissues = new GitHubIssuesConnection();
                result = githubissues.Connect(request.Host, request.User, request.Password);
                break;

            case "githubpulls":
                string.Format("Connecting to GitHub (Pulls) using {0}", request).Debug();
                var githubpulls = new GitHubPullsConnection();
                result = githubpulls.Connect(request.Host, request.User, request.Password);
                break;
            }

            if (result == ConnectionResult.Success)
            {
                "Connection successful.".Debug();
                SaveLogin(request);
                return(OK());
            }

            if (result == ConnectionResult.FailedToConnect)
            {
                return(NotAuthorized("Credentials Rejected"));
            }

            if (result == ConnectionResult.InvalidUrl)
            {
                return(BadRequest("Invalid Url"));
            }

            return(BadRequest("Unknown Target"));
        }
Example #2
0
        private static IConnection Connect(Request request, out ConnectionResult result)
        {
            result = ConnectionResult.UnknownTarget;
            if (request.Type == null)
            {
                return(null);
            }

            IConnection target;

            switch (request.Type.ToLowerInvariant())
            {
            case "tfs":
                target = new TfsConnection();
                result = target.Connect(request.Url, request.User, request.Password);
                break;

            case "jira":
                target = new JiraConnection();
                result = target.Connect(request.Url, request.User, request.Password);
                break;

            case "githubissues":
                target = new GitHubIssuesConnection();
                result = target.Connect(request.Host, request.User, request.Password);
                break;

            case "githubpulls":
                target = new GitHubPullsConnection();
                result = target.Connect(request.Host, request.User, request.Password);
                break;

            default:
                target = null;
                break;
            }
            return(target);
        }