diff --git a/App.config b/App.config index 794cde0..73951d9 100644 --- a/App.config +++ b/App.config @@ -4,11 +4,16 @@ - - - - - + + + + + + + + + + diff --git a/CLAPOptions.cs b/CLAPOptions.cs index 4debec0..fe4c884 100644 --- a/CLAPOptions.cs +++ b/CLAPOptions.cs @@ -1,4 +1,5 @@ -using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Configuration; using System.Threading.Tasks; using CLAP; using CLAP.Validation; namespace tfs_cli { class CLAPOptions { private static Configuration configManager = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); private static KeyValueConfigurationCollection _appconf = configManager.AppSettings.Settings; private static ConnectionData _conData; public static void readConfig() { try { _conData = new ConnectionData( _appconf["url"].Value, _appconf["project"].Value, _appconf["testplan"].Value, _appconf["login"].Value, StringEncriptor.Decrypt(_appconf["password"].Value), (_appconf.AllKeys.Contains("domen")) ? _appconf["domen"].Value : null ); } catch (Exception e) { TfsCliHelper.ExitWithError(string.Format( "Set correct parameters in the config file. Make sure you encrypt your password with tfs_cli enc \n{0}\n{1}", e.Message, e.StackTrace )); } } [Empty] static void NoInput() { Console.WriteLine( @"This is command line utility to get tests from TFS or to update results of tests inside TFS. Try -h option for more." ); } [Help] static void help() { Console.WriteLine("Help:"); } [Verb(Aliases = "get", Description = "Exports TFS tests from provided project and testplan. Please fill config file beforehand\nExample usage: tfs_cli get" )] static void get_tests( [DefaultValue("tests.xml"), DescriptionAttribute("Filename for tests export")] string output, [AliasesAttribute("tp"), DefaultValue(""), DescriptionAttribute("Testplan to get tests from (overrides .config option)")] string testplan ) { if (testplan != "") _conData.setTestPlan(testplan); +using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Configuration; using System.Threading.Tasks; using CLAP; using CLAP.Validation; namespace tfs_cli { class CLAPOptions { private static Configuration configManager = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None); private static KeyValueConfigurationCollection _appconf = configManager.AppSettings.Settings; private static ConnectionData _conData; public static void readConfig() { try { _conData = new ConnectionData( _appconf["url"].Value, _appconf["project"].Value, _appconf["testplan"].Value, _appconf["login"].Value, StringEncriptor.Decrypt(_appconf["password"].Value), (_appconf.AllKeys.Contains("domen")) ? _appconf["domen"].Value : null, _appconf["proxy_login"].Value, + _appconf["proxy_password"].Value, _appconf["proxy_domain"].Value ); } catch (Exception e) { TfsCliHelper.ExitWithError(string.Format( "Set correct parameters in the config file. Make sure you encrypt your password with tfs_cli enc \n{0}\n{1}", e.Message, e.StackTrace )); } } [Empty] static void NoInput() { Console.WriteLine( @"This is command line utility to get tests from TFS or to update results of tests inside TFS. Try -h option for more." ); } [Help] static void help() { Console.WriteLine("Help:"); } [Verb(Aliases = "get", Description = "Exports TFS tests from provided project and testplan. Please fill config file beforehand\nExample usage: tfs_cli get" )] static void get_tests( [DefaultValue("tests.xml"), DescriptionAttribute("Filename for tests export")] string output, [AliasesAttribute("tp"), DefaultValue(""), DescriptionAttribute("Testplan to get tests from (overrides .config option)")] string testplan ) { if (testplan != "") _conData.setTestPlan(testplan); TestsWriter writer = new XmlFileWriter(output, _conData, new XmlBuilder()); writer.CreateOutput(); } diff --git a/ConnectionData.cs b/ConnectionData.cs index 16c45cb..41280d2 100644 --- a/ConnectionData.cs +++ b/ConnectionData.cs @@ -14,6 +14,9 @@ class ConnectionData private string _login; private string _pwd; private string _domen; + private string _proxy_login; + private string _proxy_password; + private string _proxy_domain; public ConnectionData ( @@ -22,7 +25,10 @@ public ConnectionData string testplan, string login, string pwd, - string domen + string domen, + string proxy_login, + string proxy_password, + string proxy_domain ) { _url = url; @@ -31,6 +37,9 @@ string domen _login = login; _pwd = pwd; _domen = domen; + _proxy_login = proxy_login; + _proxy_password = proxy_password; + _proxy_domain = proxy_domain; } public void setTestPlan(string newtp) { @@ -43,5 +52,8 @@ public void setTestPlan(string newtp) { public string User() { return _login; } public string Password() { return _pwd; } public string Domen() { return _domen; } + public string ProxyLogin() { return _proxy_login; } + public string ProxyPassword() { return _proxy_password; } + public string ProxyDomain() { return _proxy_domain; } } } diff --git a/CredentialConnector.cs b/CredentialConnector.cs index 3e1722b..be69cdc 100644 --- a/CredentialConnector.cs +++ b/CredentialConnector.cs @@ -23,9 +23,12 @@ public void Connect() { // Try to connect first var cred = (_connData.User() != null && _connData.Password() != null) ? - new NetworkCredential(_connData.User(), _connData.Password(), _connData.Domen()) : - null; - + new NetworkCredential(_connData.User(), _connData.Password(), _connData.Domen()) : null; + if (_connData.ProxyLogin() != "" && _connData.ProxyPassword() != "" && _connData.ProxyDomain() != "") + { + NetworkCredential credentials = new System.Net.NetworkCredential(_connData.ProxyLogin(), _connData.ProxyPassword(), _connData.ProxyDomain()); + WebRequest.DefaultWebProxy.Credentials = credentials; + } _tfs = new TfsTeamProjectCollection(new Uri(_connData.Url()), cred); _tfs.Authenticate(); TfsCliHelper.Debug(string.Format("Connection: \"{0}\" \"{1}\"", _tfs.Name, _tfs.Uri)); diff --git a/Program.cs b/Program.cs index a14443b..706a0b4 100644 --- a/Program.cs +++ b/Program.cs @@ -1,10 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using System.Net; -using System.IO; +#define TRACE +using System; using CLAP; namespace tfs_cli