Skip to content

Commit

Permalink
config update
Browse files Browse the repository at this point in the history
  • Loading branch information
ekhatko committed Feb 20, 2014
1 parent 7a8aeec commit 4c19342
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 17 deletions.
15 changes: 10 additions & 5 deletions App.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,16 @@
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5" />
</startup>
<appSettings>
<add key="url" value="https://ekhatko.visualstudio.com/DefaultCollection/" />
<add key="login" value="[email protected]" />
<add key="password" value="aYsKvHyDEQnoIuJ8Y1Qrfg==" />
<add key="project" value="cmd" />
<add key="testplan" value="bestplan" />
<add key="url" value="https://user.visualstudio.com/DefaultCollection/" />
<add key="login" value="" />
<!-- following is password '123' encrpted-->
<add key="password" value="" />
<add key="project" value="" />
<add key="testplan" value="" />
<!-- proxy settings (OPTIONAL) -->
<add key="proxy_login" value="" />
<add key="proxy_password" value="" />
<add key="proxy_domain" value="" />
</appSettings>
<system.diagnostics>
<trace autoflush="true" indentsize="4">
Expand Down
3 changes: 2 additions & 1 deletion CLAPOptions.cs
Original file line number Diff line number Diff line change
@@ -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 <pwd>\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 <pwd>\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(); }

Expand Down
14 changes: 13 additions & 1 deletion ConnectionData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
(
Expand All @@ -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;
Expand All @@ -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) {
Expand All @@ -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; }
}
}
9 changes: 6 additions & 3 deletions CredentialConnector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
9 changes: 2 additions & 7 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 4c19342

Please sign in to comment.