public static IPromise <IAsyncConnection> ArasLogin(this ConnectionData credentials, bool async)
        {
            var cred  = credentials.ArasCredentials();
            var prefs = new ConnectionPreferences();

            prefs.Headers.UserAgent = "InnovatorAdmin v" + Assembly.GetExecutingAssembly().GetName().Version.ToString();
            var localePref = credentials.Params.FirstOrDefault(p => p.Name == "LOCALE");
            var tzPref     = credentials.Params.FirstOrDefault(p => p.Name == "TIMEZONE_NAME");

            if (localePref != null)
            {
                prefs.Headers.Locale = localePref.Value;
            }
            if (tzPref != null)
            {
                prefs.Headers.TimeZone = tzPref.Value;
            }

            return(Factory.GetConnection(credentials.Url
                                         , prefs, async)
                   .Continue(c =>
            {
                return c.Login(cred, async)
                .Convert(u => (IAsyncConnection)c);
            }));
        }
Exemplo n.º 2
0
        public void ConnectionPreferencesRoundTrip()
        {
            var cred = new ExplicitCredentials("db", "user", "pass");
            var pref = new ConnectionPreferences()
            {
                Credentials    = cred,
                DefaultTimeout = 1000,
                Name           = "ConnName",
                Url            = "http://example.com"
            };

            pref.Headers.Locale = "en-gb";

            var saved = new SavedConnections();

            saved.Add(pref);
            var newPref = saved.First();
            var newCred = newPref.Credentials as ExplicitCredentials;

            Assert.AreEqual(cred.Database, newCred.Database);
            Assert.AreEqual(cred.Username, newCred.Username);
            Assert.AreEqual(pref.DefaultTimeout, newPref.DefaultTimeout);
            Assert.AreEqual(pref.Name, newPref.Name);
            Assert.AreEqual(pref.Url, newPref.Url);
            Assert.AreEqual(pref.Headers.Locale, newPref.Headers.Locale);
        }
Exemplo n.º 3
0
        public async Task Run(TestContext context)
        {
            var url = this.Url;
            var db  = this.Database;

            var remoteConn = context.Connection as IRemoteConnection;

            if (string.IsNullOrEmpty(url) && remoteConn != null)
            {
                url = remoteConn.Url.ToString();
            }
            if (string.IsNullOrEmpty(db))
            {
                db = context.Connection.Database;
            }

            var prefs = new ConnectionPreferences();

            prefs.Headers.UserAgent = "InnovatorAdmin UnitTest";
            var conn = await Factory.GetConnection(url, prefs, true).ToTask();

            ICredentials cred;

            switch (this.Type)
            {
            case CredentialType.Anonymous:
                cred = new AnonymousCredentials(db);
                break;

            case CredentialType.Windows:
                cred = new WindowsCredentials(db);
                break;

            default:
                if (_password.IsNullOrEmpty())
                {
                    cred = context.CredentialStore.OfType <ExplicitCredentials>()
                           .FirstOrDefault(c => string.Equals(c.Database, db) && string.Equals(c.Username, this.UserName));
                }
                else
                {
                    cred = new ExplicitCredentials(db, this.UserName, _password);
                }
                break;
            }

            if (cred == null)
            {
                throw new InvalidOperationException("Could not create credentials for this login type");
            }
            await conn.Login(cred, true).ToTask();

            context.PushConnection(conn);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ArasVaultConnection"/> class for
 /// a given <see cref="IArasConnection"/>
 /// </summary>
 /// <param name="conn">The corresponding <see cref="IArasConnection"/>.</param>
 public ArasVaultConnection(IArasConnection conn) : this(conn, ConnectionPreferences.GetService())
 {
 }
Exemplo n.º 5
0
 public SavedConnection(ConnectionPreferences prefs)
 {
     _prefs = prefs;
 }