public TfsServerConfiguration Get() { var configProvider = new ConfigurationProvider(); var config = new TfsServerConfiguration { VersionOneUrl = configProvider.VersionOneUrl.ToString(), VersionOnePassword = configProvider.VersionOnePassword, VersionOneUserName = configProvider.VersionOneUserName, TfsUrl = configProvider.TfsUrl.ToString(), TfsUserName = configProvider.TfsUserName, TfsPassword = configProvider.TfsPassword, TfsWorkItemRegex = configProvider.TfsWorkItemRegex, IsWindowsIntegratedSecurity = configProvider.IsWindowsIntegratedSecurity, DebugMode = configProvider.DebugMode, BaseListenerUrl = configProvider.BaseListenerUrl.ToString() }; if (configProvider.ProxySettings.ProxyIsEnabled) { config.ProxyDomain = configProvider.ProxySettings.Domain; config.ProxyIsEnabled = configProvider.ProxySettings.ProxyIsEnabled; config.ProxyUrl = configProvider.ProxySettings.Url.ToString(); config.ProxyUsername = configProvider.ProxySettings.Username; config.ProxyPassword = configProvider.ProxySettings.Password; } return config; }
private TfsServerConfiguration GetConfigurationData() { if (tcSettings.Enabled == false) tcSettings.Enabled = true; if (btnSaveAllSettings.Enabled == false) btnSaveAllSettings.Enabled = true; var tfsConfig = new TfsServerConfiguration(); var proxy = new ConfigurationProxy(null, tbBaseUrl.Text); UpdateStatusText(string.Format("Updating configuration information from {0}.", proxy.ConfigurationUrl), false); try { tfsConfig = proxy.Retrieve(); } catch (Exception e) { UpdateStatusText(string.Format("Could not use the to TFS Listener at url {0}. Exception: {1}.", proxy.ConfigurationUrl, e.Message), true); tcSettings.Enabled = false; btnSaveAllSettings.Enabled = false; } finally { tbBaseUrl.Text = proxy.BaseListenerUrl; } return tfsConfig; }
private void btnSaveVersionOneSettings_Click(object sender, EventArgs e) { var configToSave = new TfsServerConfiguration() { VersionOneUrl = V1URLTB.Text, VersionOneUserName = V1UsernameTB.Text, VersionOnePassword = V1PasswordTB.Text, TfsUrl = TFSURLTB.Text, TfsUserName = TFSUsernameTB.Text, TfsPassword = TFSPasswordTB.Text, TfsWorkItemRegex = RegExTB.Text, DebugMode = chkDebugMode.Checked, IsWindowsIntegratedSecurity = UseIntegratedAuthenticationCB.Checked, ProxyIsEnabled = chkUseProxy.Checked, ProxyUrl = txtProxyUrl.Text, ProxyUsername = txtProxyUsername.Text, ProxyPassword = txtProxyPassword.Text, ProxyDomain = txtProxyDomain.Text, BaseListenerUrl = tbBaseUrl.Text }; var results = new ConfigurationProxy().Store(configToSave); if(results != null && results[StatusKey.Status] == StatusCode.Ok) { UpdateStatusText("Save successful.", false); return; } if (results == null) throw new Exception("Unable to retrieve results from server."); var missingFields = string.Join(", ", results.Keys.Where(key => key != "status")); var text = string.Format("The following values must be present in order to save settings: {0}.", missingFields); UpdateStatusText(text, true); }
public Dictionary<string, string> Store(TfsServerConfiguration config) { var json = JsonConvert.SerializeObject(config); var result = _client.Put(ConfigurationUrl, System.Text.Encoding.UTF8.GetBytes(json)); var body = System.Text.Encoding.UTF8.GetString(result); return JsonConvert.DeserializeObject<Dictionary<string, string>>(body); }
private static IEnumerable<KeyValuePair<string, string>> ValidatePostData(TfsServerConfiguration config) { if (string.IsNullOrEmpty(config.VersionOneUrl)) yield return RequiredFieldError("VersionOneUrl"); if (string.IsNullOrEmpty(config.VersionOnePassword)) yield return RequiredFieldError("VersionOnePassword"); if (string.IsNullOrEmpty(config.VersionOneUserName)) yield return RequiredFieldError("VersionOneUserName"); if (string.IsNullOrEmpty(config.TfsUrl)) yield return RequiredFieldError("TfsUrl"); if (string.IsNullOrEmpty(config.TfsUserName)) yield return RequiredFieldError("TfsUserName"); if (string.IsNullOrEmpty(config.TfsPassword)) yield return RequiredFieldError("TfsPassword"); if (string.IsNullOrEmpty(config.BaseListenerUrl)) yield return RequiredFieldError("BaseListenerUrl"); }
public void given_settings_are_being_sent_to_the_controller() { context["when a valid set of data including all possible fields"] = () => { //all possible fields are set var postData = new TfsServerConfiguration() { IsWindowsIntegratedSecurity = true, TfsUrl = "http://www.mytfsserver.com/default/", TfsUserName = "******", TfsPassword = "******", VersionOneUrl = "http://www.versionone.com/", VersionOneUserName = "******", VersionOnePassword = "******", ProxyIsEnabled = true, TfsWorkItemRegex = "[]", BaseListenerUrl = "http://localhost:9090/", DebugMode = true, ProxyUrl = "http://192.168.1.1/home/", ProxyDomain = "AD1", ProxyUsername = "******", ProxyPassword = "******" }; it["then the data is saved accurately"] = () => { new ConfigurationProvider().ClearAllSettings(); var postResult = new ConfigurationController().Post(postData); var getData = new ConfigurationController().Get(); postResult[StatusKey.Status].should_be(StatusCode.Ok); getData.should_be(postData); }; }; context["when a valid object is sent to the server"] = () => { //min acceptable valid set of data var postData = new TfsServerConfiguration() { TfsUrl = "http://www.mytfsserver.com/default/", TfsUserName = "******", TfsPassword = "******", VersionOneUrl = "http://www.versionone.com/", VersionOneUserName = "******", VersionOnePassword = "******", ProxyIsEnabled = false, BaseListenerUrl = "http://locahost:9090/", TfsWorkItemRegex = "[]" //not a required field, but returns a default so needs to be set in order for a valid comparison to occur below. }; it["then the data is saved accurately"] = () => { new ConfigurationProvider().ClearAllSettings(); var postResult = new ConfigurationController().Post(postData); var getData = new ConfigurationController().Get(); //the data retrieved should equal the data posted getData.should_be(postData); it["and the status of 'ok' is in the result data"] = () => { postResult.should_contain(kvp => kvp.Key == StatusKey.Status); postResult[StatusKey.Status].should_be(StatusCode.Ok); }; }; }; context["when an invalid object is sent to the server"] = () => { //invalid data missing v1url var postData = new TfsServerConfiguration() { TfsUrl = "http://www.mytfsserver.com/default/", TfsUserName = "******", TfsPassword = "******", VersionOneUserName = "******", VersionOnePassword = "******", ProxyIsEnabled = false }; it["then a proper list of errors is received"] = () => { new ConfigurationProvider().ClearAllSettings(); var postResult = new ConfigurationController().Post(postData); postResult.should_contain(x => x.Key == "VersionOneUrl"); postResult["VersionOneUrl"].should_be(StatusCode.Required); postResult[StatusKey.Status].should_be(StatusCode.Exception); }; }; }