public Server AddServer(string url, string displayName, string username, string password, bool ignoreUntrustedCertificate)
 {
     Server server = new Server();
     BindData(server, url, displayName, username, password, ignoreUntrustedCertificate);
     Servers.Add(server);
     SaveConfiguration();
     return server;
 }
Exemplo n.º 2
0
        public void UpdateProjectList(Server server)
        {
            this.server = server;
            #if SYNCRHONOUS
            List<Project> dataSource = new List<Project>();

            if (server != null)
            {
                IList<Project> projects = jenkinsService.LoadProjects(server);
                foreach (Project project in projects)
                    dataSource.Add(project);
            }

            SetProjectsDataSource(dataSource);
            #else
            // clear the view
            projectsGridControl.DataSource = null;

            if (server == null)
                return;

            // disable the window, change the cursor, update the status
            Cursor.Current = Cursors.WaitCursor;
            Enabled = false;
            string status = string.Format(JenkinsTrayResources.LoadingProjects_FormatString, server.Url);
            Controller.SetStatus(status, true);

            // run the process in background
            Process process = new Process("Loading project " + server.Url);
            IList<Project> projects = null;
            process.DoWork += delegate
            {
                projects = JenkinsService.LoadProjects(server);
            };
            process.RunWorkerCompleted += delegate(object sender, RunWorkerCompletedEventArgs e)
            {
                string endStatus = "";

                if (e.Error == null)
                {
                    var dataSource = new List<Project>();
                    foreach (Project project in projects)
                        dataSource.Add(project);
                    SetProjectsDataSource(dataSource);
                }
                else
                {
                    endStatus = string.Format(JenkinsTrayResources.FailedLoadingProjects_FormatString, server.Url);
                }

                // enable the window, change the cursor, update the status
                Enabled = true;
                Cursor.Current = Cursors.Default;
                Controller.SetStatus(endStatus, false);
            };
            BackgroundProcessExecutor.Execute(process);
            #endif
        }
Exemplo n.º 3
0
 public EditServerForm(Server server)
     : this()
 {
     ServerAddress = server.Url;
     ServerName = server.DisplayName;
     IgnoreUntrustedCertificate = server.IgnoreUntrustedCertificate;
     if (server.Credentials != null)
     {
         RequiresAuthentication = true;
         Username = server.Credentials.Username;
         Password = server.Credentials.Password;
     }
 }
Exemplo n.º 4
0
        public List<Project> GetProjects(XmlNodeList jobElements, Server server)
        {
            var projects = new List<Project>();

            foreach (XmlNode jobElement in jobElements)
            {
                string projectName = jobElement.SelectSingleNode("name").InnerText;
                string projectUrl = jobElement.SelectSingleNode("url").InnerText;
                XmlNode projectColor = jobElement.SelectSingleNode("color");
                // If the job is a folder we need to recursively get the jobs within.
                if (jobElement.SelectSingleNode("color") == null)
                {
                    String url = NetUtils.ConcatUrls(projectUrl, "/api/xml?tree=jobs[name,url,color]");
                    String xmlStr = DownloadString(server.Credentials, url, false, server.IgnoreUntrustedCertificate);
                    XmlDocument xml = new XmlDocument();
                    xml.LoadXml(xmlStr);
                    XmlNodeList nodes = xml.SelectNodes("/folder/job");
                    projects.AddRange(GetProjects(nodes, server));
                }
                else
                {
                    Project project = new Project();
                    project.Server = server;
                    project.Name = projectName;
                    project.Url = projectUrl;

                    if (logger.IsDebugEnabled)
                        logger.Debug("Found project " + projectName + " (" + projectUrl + ")");

                    // Ensure only unique entries in the returned list.
                    if (!projects.Contains(project))
                    {
                        projects.Add(project);
                    }
                }
            }
            return projects;
        }
Exemplo n.º 5
0
        public IList<Project> LoadProjects(Server server)
        {
            String url = NetUtils.ConcatUrls(server.Url, "/api/xml");

            logger.Info("Loading projects from " + url);

            String xmlStr = DownloadString(server.Credentials, url, false, server.IgnoreUntrustedCertificate);

            if (logger.IsTraceEnabled)
                logger.Trace("XML: " + xmlStr);

            XmlDocument xml = new XmlDocument();
            xml.LoadXml(xmlStr);

            XmlNodeList jobElements = xml.SelectNodes("/hudson/job");
            var projects = new List<Project>();
            foreach (XmlNode jobElement in jobElements)
            {
                string projectName = jobElement.SelectSingleNode("name").InnerText;
                string projectUrl = jobElement.SelectSingleNode("url").InnerText;

                Project project = new Project();
                project.Server = server;
                project.Name = projectName;
                project.Url = projectUrl;

                if (logger.IsDebugEnabled)
                    logger.Debug("Found project " + projectName + " (" + projectUrl + ")");

                projects.Add(project);
            }

            logger.Info("Done loading projects");

            return projects;
        }
        public Configuration LoadConfiguration()
        {
            string userAppDataDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            string userAppDataPath = PathHelper.Combine(userAppDataDir, JENKINS_TRAY_DIRECTORY);
            string userConfigurationFile = PathHelper.Combine(userAppDataPath, PROPERTIES_FILE);

            // create the directory in case it does not exist
            Directory.CreateDirectory(userAppDataPath);

            // read the properties file
            PropertiesFile propertiesFile = PropertiesFile.ReadPropertiesFile(userConfigurationFile);

            // load the servers
            var servers = new HashedSet<Server>();
            var serverMap = new Dictionary<int, Server>();
            int serverCount = propertiesFile.GetGroupCount("servers");
            for (int serverId = 0; serverId < serverCount; serverId++)
            {
                // read the server configuration
                Server server = new Server();
                server.Url = propertiesFile.GetGroupRequiredStringValue("servers", serverId, "url");
                server.DisplayName = propertiesFile.GetGroupStringValue("servers", serverId, "displayName");
                server.IgnoreUntrustedCertificate = propertiesFile.GetGroupBoolValue("servers", serverId, "ignoreUntrustedCertificate", false);

                // credentials
                string username = propertiesFile.GetGroupStringValue("servers", serverId, "username");
                if (username != null)
                {
                    string passwordBase64 = propertiesFile.GetGroupRequiredStringValue("servers", serverId, "passwordBase64");
                    string password = Encoding.UTF8.GetString(Convert.FromBase64String(passwordBase64));
                    server.Credentials = new Credentials(username, password);
                }

            #if DEBUG//FIXME
                server.Credentials = new Credentials("plop", "bam");
            #endif

                // keep the server
                servers.Add(server);

                // temporary keep for projects loading
                serverMap.Add(serverId, server);
            }

            // load the projects
            int projectCount = propertiesFile.GetGroupCount("projects");
            for (int projectId = 0; projectId < projectCount; projectId++)
            {
                // read the project configuration
                int serverId = propertiesFile.GetGroupRequiredIntValue("projects", projectId, "server");
                Server server = serverMap[serverId];
                Project project = new Project();
                project.Server = server;
                project.Name = propertiesFile.GetGroupRequiredStringValue("projects", projectId, "name");
                project.Url = propertiesFile.GetGroupRequiredStringValue("projects", projectId, "url");

                // keep the project
                server.Projects.Add(project);
            }

            var notificationSettings = new NotificationSettings();
            notificationSettings.FailedSoundPath = propertiesFile.GetStringValue("sounds.Failed");
            notificationSettings.FixedSoundPath = propertiesFile.GetStringValue("sounds.Fixed");
            notificationSettings.StillFailingSoundPath = propertiesFile.GetStringValue("sounds.StillFailing");
            notificationSettings.SucceededSoundPath = propertiesFile.GetStringValue("sounds.Succeeded");
            notificationSettings.TreatUnstableAsFailed = propertiesFile.GetBoolValue("sounds.TreatUnstableAsFailed") ?? true;

            var generalSettings = new GeneralSettings();
            generalSettings.RefreshIntervalInSeconds = propertiesFile.GetIntValue("general.RefreshTimeInSeconds", DEFAULT_TIME_BETWEEN_UPDATES);
            generalSettings.UpdateMainWindowIcon = propertiesFile.GetBoolValue("general.UpdateMainWindowIcon", true);
            generalSettings.IntegrateWithClaimPlugin = propertiesFile.GetBoolValue("general.IntegrateWithClaimPlugin", true);

            var res = new Configuration
            {
                Servers = servers,
                NotificationSettings = notificationSettings,
                GeneralSettings = generalSettings
            };
            return res;
        }
 private void BindData(Server server, string url, string displayName, string username, string password, bool ignoreUntrustedCertificate)
 {
     server.Url = url;
     server.DisplayName = displayName;
     server.IgnoreUntrustedCertificate = ignoreUntrustedCertificate;
     if (String.IsNullOrEmpty(username) == false)
         server.Credentials = new Credentials(username, password);
     else
         server.Credentials = null;
 }
        public void UpdateServer(Server server, string url, string displayName, string username, string password, bool ignoreUntrustedCertificate)
        {
            // note: we need to remove and re-add the server because its hash-code might change
            string oldServerUrl = server.Url;
            Servers.Remove(server);
            BindData(server, url, displayName, username, password, ignoreUntrustedCertificate);

            //  Update all projects with new server url
            if (server.Url.ToUpper().CompareTo(oldServerUrl.ToUpper()) != 0)
            {
                logger.Info("Server Url updated: " + oldServerUrl + " -> " + server.Url);
                foreach (Project project in server.Projects)
                {
                    string updatedUrl = project.Url.Replace(oldServerUrl, server.Url);
                    logger.Info("Project Url updated: " + project.Url + " -> " + updatedUrl);
                    project.Url = updatedUrl;
                }
            }
            Servers.Add(server);
            SaveConfiguration();
        }
 public void RemoveServer(Server server)
 {
     Servers.Remove(server);
     SaveConfiguration();
 }
Exemplo n.º 10
0
        public void RemoveFromQueue(Server server, long queueId)
        {
            String url = NetUtils.ConcatUrls(server.Url, "/queue/cancelItem?id=" + queueId);

            logger.Info("Removing queue item at " + url);

            Credentials credentials = server.Credentials;

            try
            {
                String str = UploadString(credentials, url, server.IgnoreUntrustedCertificate);

                if (logger.IsTraceEnabled)
                    logger.Trace("Result: " + str);
            }
            catch (WebException webEx)
            {
                //  Workaround for JENKINS-21311
                if (webEx.Status == WebExceptionStatus.ProtocolError && ((HttpWebResponse)webEx.Response).StatusCode == HttpStatusCode.NotFound)
                {
                    //  consume error 404
                }
                else
                    throw webEx;
            }
            logger.Info("Done removing queue item");
        }
Exemplo n.º 11
0
        public IList<Project> LoadProjects(Server server)
        {
            String url = NetUtils.ConcatUrls(server.Url, "/api/xml?tree=jobs[name,url,color]");

            logger.Info("Loading projects from " + url);

            String xmlStr = DownloadString(server.Credentials, url, false, server.IgnoreUntrustedCertificate);

            if (logger.IsTraceEnabled)
                logger.Trace("XML: " + xmlStr);

            XmlDocument xml = new XmlDocument();
            xml.LoadXml(xmlStr);

            XmlNodeList jobElements = xml.SelectNodes("/hudson/job");
            var projects = GetProjects(jobElements, server);

            logger.Info("Done loading projects");

            return projects;
        }
Exemplo n.º 12
0
 private void UpdateForServer(Server server)
 {
     foreach (var project in server.Projects)
     {
         UpdateForProject(project);
         lastStatuses.SetOrAdd(project.Url, project.Status);
         if (!project.Status.IsInProgress)
         {
             lastCompletedStatuses.SetOrAdd(project.Url, project.Status);
         }
     }
 }
 public void UpdateProjectList(Server server)
 {
     projectListControl.UpdateProjectList(server);
 }