public void GetProjects(string rootUrl, string userName, string password, GetProjectsCompleteDelegate complete, Action<Exception> onError)
 {
     WebClient webClient = new WebClient
     {
         Credentials = new NetworkCredential(userName, password)
     };
     rootUrl = GetRootUrl(rootUrl);
     var projectUrl = new Uri(rootUrl + "/json/builders");
     webClient.DownloadStringCompleted += (s, e) =>
     {
         try
         {
             JavaScriptSerializer serializer = new JavaScriptSerializer();
             Dictionary<string, BuildBotBuildersJSONQuery> builders = serializer.Deserialize<Dictionary<string, BuildBotBuildersJSONQuery>>(e.Result);
             var builds = new List<BuildBotBuildDefinition>();
             foreach (KeyValuePair<string, BuildBotBuildersJSONQuery> kvp in builders)
             {
                 var buildurl = new Uri(rootUrl + "/json/builders/" + kvp.Key );
                 builds.Add( new BuildBotBuildDefinition(buildurl.ToString(), kvp.Key ) );
             }
             complete(builds.ToArray());
         }
         catch (Exception ex)
         {
             _log.Error("Error connecting to server", ex);
             onError(ex);
         }
     };
     webClient.DownloadStringAsync(projectUrl);
 }
Beispiel #2
0
        public void GetProjects(string rootUrl, string userName, string password, GetProjectsCompleteDelegate complete, Action <Exception> onError)
        {
            WebClientXml webClient = new WebClientXml
            {
                AuthenticationType = AuthenticationTypeEnum.Base64EncodeInHeader,
                UserName           = userName,
                Password           = password
            };

            rootUrl = GetRootUrl(rootUrl);

            webClient.DownloadXmlAsync(rootUrl + "/api/xml", onSuccess: doc =>
            {
                if (doc.Root == null)
                {
                    onError(new Exception("No results returned"));
                    return;
                }
                HudsonBuildDefinition[] buildDefinitions = doc.Root
                                                           .Elements("job")
                                                           .Select(projectXml => new HudsonBuildDefinition(rootUrl, projectXml))
                                                           .ToArray();
                complete(buildDefinitions);
            }, onError: OnError(onError));
        }
Beispiel #3
0
        public void GetProjects(string rootUrl, string userName, string password, GetProjectsCompleteDelegate complete, Action <Exception> onError)
        {
            WebClient webClient = new WebClient
            {
                Credentials = new NetworkCredential(userName, password)
            };

            rootUrl = GetRootUrl(rootUrl);
            var projectUrl = new Uri(rootUrl + "/XmlStatusReport.aspx");

            webClient.DownloadStringCompleted += (s, e) =>
            {
                try
                {
                    XDocument doc = XDocument.Parse(e.Result);
                    if (doc.Root == null)
                    {
                        throw new Exception("Could not get project list");
                    }
                    var projectElems = doc.Root.Elements("Project");
                    CruiseControlNetBuildDefinition[] buildDefinitions = projectElems
                                                                         .Select(planXml => new CruiseControlNetBuildDefinition(rootUrl, planXml))
                                                                         .ToArray();
                    complete(buildDefinitions);
                }
                catch (Exception ex)
                {
                    _log.Error("Error connecting to server", ex);
                    onError(ex);
                }
            };
            webClient.DownloadStringAsync(projectUrl);
        }
 public void GetProjects(string rootUrl, string userName, string password, GetProjectsCompleteDelegate complete, Action<Exception> onError)
 {
     WebClient webClient = new WebClient
     {
         Credentials = new NetworkCredential(userName, password)
     };
     rootUrl = GetRootUrl(rootUrl);
     var projectUrl = new Uri(rootUrl + "/XmlStatusReport.aspx");
     webClient.DownloadStringCompleted += (s, e) =>
     {
         try
         {
             XDocument doc = XDocument.Parse(e.Result);
             if (doc.Root == null) throw new Exception("Could not get project list");
             var projectElems = doc.Root.Elements("Project");
             CruiseControlNetBuildDefinition[] buildDefinitions = projectElems
                 .Select(planXml => new CruiseControlNetBuildDefinition(rootUrl, planXml))
                 .ToArray();
             complete(buildDefinitions);
         }
         catch (Exception ex)
         {
             _log.Error("Error connecting to server", ex);
             onError(ex);
         }
     };
     webClient.DownloadStringAsync(projectUrl);
 }
        public void GetProjects(string rootUrl, string userName, string password, GetProjectsCompleteDelegate complete, Action <Exception> onError)
        {
            WebClient webClient = new WebClient
            {
                Credentials = new NetworkCredential(userName, password)
            };

            rootUrl = GetRootUrl(rootUrl);
            var projectUrl = new Uri(rootUrl + "/json/builders");

            webClient.DownloadStringCompleted += (s, e) =>
            {
                try
                {
                    JavaScriptSerializer serializer = new JavaScriptSerializer();
                    Dictionary <string, BuildBotBuildersJSONQuery> builders = serializer.Deserialize <Dictionary <string, BuildBotBuildersJSONQuery> >(e.Result);
                    var builds = new List <BuildBotBuildDefinition>();
                    foreach (KeyValuePair <string, BuildBotBuildersJSONQuery> kvp in builders)
                    {
                        var buildurl = new Uri(rootUrl + "/json/builders/" + kvp.Key);
                        builds.Add(new BuildBotBuildDefinition(buildurl.ToString(), kvp.Key));
                    }
                    complete(builds.ToArray());
                }
                catch (Exception ex)
                {
                    _log.Error("Error connecting to server", ex);
                    onError(ex);
                }
            };
            webClient.DownloadStringAsync(projectUrl);
        }
        public void GetProjects(string rootUrl, string userName, string password, GetProjectsCompleteDelegate complete, Action <Exception> onError)
        {
            WebClient webClient = new WebClient
            {
                Credentials = new NetworkCredential(userName, password)
            };

            rootUrl = GetRootUrl(rootUrl);
            var projectUrl = new Uri(rootUrl + "/httpAuth/app/rest/projects");

            webClient.DownloadStringCompleted += (s, e) =>
            {
                try
                {
                    XDocument doc = XDocument.Parse(e.Result);
                    if (doc.Root == null)
                    {
                        throw new Exception("Could not get project list");
                    }
                    TeamCityProject[] projects = doc.Root
                                                 .Elements("project")
                                                 .Select(projectXml => new TeamCityProject(rootUrl, projectXml))
                                                 .ToArray();
                    complete(projects);
                }
                catch (Exception ex)
                {
                    _log.Error("Error connecting to server", ex);
                    onError(ex);
                }
            };
            webClient.DownloadStringAsync(projectUrl);
        }
        public void GetProjects(string rootUrl, string userName, string password, GetProjectsCompleteDelegate complete, Action<Exception> onError)
        {
            WebClient webClient = new WebClient
            {
                Credentials = new NetworkCredential(userName, password)
            };
            rootUrl = GetRootUrl(rootUrl);
            var projectUrl = new Uri(rootUrl + "/rest/api/latest/plan?os_authType=basic");
            BambooBuildDefinition[] buildDefinitions = new BambooBuildDefinition[] { };
            //This loop may be run multiple times
            webClient.DownloadStringCompleted += (s, e) =>
            {
                try
                {
                    XDocument doc = XDocument.Parse(e.Result);
                    if (doc.Root == null) throw new Exception("Could not get project list");
                    var plansElem = doc.Root.Element("plans");
                    if (plansElem == null) throw new Exception("Could not get plans element");
                    var plansElements = doc.Descendants("plans")
                        .Where(i => i.Attribute("size") != null)
                        .ToArray();
                    if (plansElements.Length != 1) throw new Exception("Retrieved " + plansElements.Length + " plans when 1 was expected");
                    XElement firstPlan = plansElements[0];
                    int startIndex = firstPlan.AttributeValueAsInt("start-index");
                    int size = firstPlan.AttributeValueAsInt("size");
                    int maxResults = firstPlan.AttributeValueAsInt("max-result");

                    BambooBuildDefinition[] buildPlans = plansElem
                        .Elements("plan")
                        .Select(planXml => new BambooBuildDefinition(rootUrl, planXml))
                        .ToArray();

                    buildDefinitions = buildDefinitions.Concat(buildPlans).ToArray();
                    bool moreResultsInBatch = (startIndex + maxResults) < size;
                    if (moreResultsInBatch)
                        webClient.DownloadStringAsync(new Uri(projectUrl.ToString() + "&start-index=" + (startIndex + maxResults)));
                    else
                        complete(buildDefinitions);
                }
                catch (Exception ex)
                {
                    _log.Error("Error connecting to server", ex);
                    onError(ex);
                }
            };
            webClient.DownloadStringAsync(projectUrl);
        }
        public void GetProjects(string rootUrl, string userName, string password, GetProjectsCompleteDelegate complete, Action<Exception> onError)
        {
            WebClientXml webClient = new WebClientXml
            {
                AuthenticationType = AuthenticationTypeEnum.Base64EncodeInHeader,
                UserName = userName,
                Password = password
            };
            rootUrl = GetRootUrl(rootUrl);

            webClient.DownloadXmlAsync(rootUrl + "/api/xml", onSuccess: doc =>
            {
                if (doc.Root == null)
                {
                    onError(new Exception("No results returned"));
                    return;
                }
                HudsonBuildDefinition[] buildDefinitions = doc.Root
                    .Elements("job")
                    .Select(projectXml => new HudsonBuildDefinition(rootUrl, projectXml))
                    .ToArray();
                complete(buildDefinitions);
            }, onError: OnError(onError));
        }
Beispiel #9
0
        public void GetProjects(string rootUrl, string userName, string password, GetProjectsCompleteDelegate complete, Action <Exception> onError)
        {
            WebClient webClient = new WebClient
            {
                Credentials = new NetworkCredential(userName, password)
            };

            rootUrl = GetRootUrl(rootUrl);
            var projectUrl = new Uri(rootUrl + "/rest/api/latest/plan?os_authType=basic");

            BambooBuildDefinition[] buildDefinitions = new BambooBuildDefinition[] { };
            //This loop may be run multiple times
            webClient.DownloadStringCompleted += (s, e) =>
            {
                try
                {
                    XDocument doc = XDocument.Parse(e.Result);
                    if (doc.Root == null)
                    {
                        throw new Exception("Could not get project list");
                    }
                    var plansElem = doc.Root.Element("plans");
                    if (plansElem == null)
                    {
                        throw new Exception("Could not get plans element");
                    }
                    var plansElements = doc.Descendants("plans")
                                        .Where(i => i.Attribute("size") != null)
                                        .ToArray();
                    if (plansElements.Length != 1)
                    {
                        throw new Exception("Retrieved " + plansElements.Length + " plans when 1 was expected");
                    }
                    XElement firstPlan  = plansElements[0];
                    int      startIndex = firstPlan.AttributeValueAsInt("start-index");
                    int      size       = firstPlan.AttributeValueAsInt("size");
                    int      maxResults = firstPlan.AttributeValueAsInt("max-result");

                    BambooBuildDefinition[] buildPlans = plansElem
                                                         .Elements("plan")
                                                         .Select(planXml => new BambooBuildDefinition(rootUrl, planXml))
                                                         .ToArray();

                    buildDefinitions = buildDefinitions.Concat(buildPlans).ToArray();
                    bool moreResultsInBatch = (startIndex + maxResults) < size;
                    if (moreResultsInBatch)
                    {
                        webClient.DownloadStringAsync(new Uri(projectUrl.ToString() + "&start-index=" + (startIndex + maxResults)));
                    }
                    else
                    {
                        complete(buildDefinitions);
                    }
                }
                catch (Exception ex)
                {
                    _log.Error("Error connecting to server", ex);
                    onError(ex);
                }
            };
            webClient.DownloadStringAsync(projectUrl);
        }
 public void GetProjects(string rootUrl, string userName, string password, GetProjectsCompleteDelegate complete, Action<Exception> onError)
 {
     WebClient webClient = new WebClient
     {
         Credentials = new NetworkCredential(userName, password)
     };
     rootUrl = GetRootUrl(rootUrl);
     var projectUrl = new Uri(rootUrl + "/httpAuth/app/rest/projects");
     webClient.DownloadStringCompleted += (s, e) =>
         {
             try
             {
                 XDocument doc = XDocument.Parse(e.Result);
                 if (doc.Root == null)
                 {
                     throw new Exception("Could not get project list");
                 }
                 TeamCityProject[] projects = doc.Root
                     .Elements("project")
                     .Select(projectXml => new TeamCityProject(rootUrl, projectXml))
                     .ToArray();
                 complete(projects);
             }
             catch (Exception ex)
             {
                 _log.Error("Error connecting to server", ex);
                 onError(ex);
             }
         };
     webClient.DownloadStringAsync(projectUrl);
 }