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; }
public void UpdateProjectList(Server server) { this.server = server; #if SYNCRHONOUS List<Project> dataSource = new List<Project>(); if (server != null) { IList<Project> projects = hudsonService.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(HudsonTrayTrackerResources.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 = HudsonService.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(HudsonTrayTrackerResources.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 }
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 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; } }
public IList<Project> LoadProjects(Server server) { var projects = new List<Project>(); if (!server.CredentialsOutOfDate) { 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"); 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, HUDSON_TRAY_TRACKER_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 Servers.Remove(server); BindData(server, url, displayName, username, password, ignoreUntrustedCertificate); Servers.Add(server); SaveConfiguration(); }
public void RemoveServer(Server server) { Servers.Remove(server); SaveConfiguration(); }
public void UpdateProjectList(Server server) { this.server = server; #if SYNCRHONOUS List<Project> dataSource = new List<Project>(); if (server != null) { IList<Project> projects = hudsonService.LoadProjects(server); foreach (Project project in projects) dataSource.Add(project); } SetProjectsDataSource(dataSource); #else // clear the view projectsGridControl.DataSource = null; if (server == null || server.CredentialsOutOfDate) return; // disable the window, change the cursor, update the status Cursor.Current = Cursors.WaitCursor; Enabled = false; string status = string.Format(HudsonTrayTrackerResources.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 = HudsonService.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 { if (e.Error is System.Net.WebException) { var webException = (System.Net.WebException)e.Error; if (webException.Status == System.Net.WebExceptionStatus.ProtocolError) { var response = webException.Response as System.Net.HttpWebResponse; if (response != null) { if ((int)response.StatusCode == 401) { if (!BadCredentialsHandler.ServersWithFailedAuthorization.Contains(server)) { BadCredentialsHandler.ServersWithFailedAuthorization.Add(server); } } } } } endStatus = string.Format(HudsonTrayTrackerResources.FailedLoadingProjects_FormatString, server.Url); } // enable the window, change the cursor, update the status Enabled = true; Cursor.Current = Cursors.Default; Controller.SetStatus(endStatus, false); }; if(!BadCredentialsHandler.ServersWithFailedAuthorization.Contains(server)) { BackgroundProcessExecutor.Execute(process); } #endif }
public void UpdateProjectList(Server server) { projectListControl.UpdateProjectList(server); }
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(); }