public static IPromise<IAsyncConnection> ArasLogin(this ConnectionData credentials, bool async)
    {
      ICredentials cred;
      switch (credentials.Authentication)
      {
        case Authentication.Anonymous:
          cred = new AnonymousCredentials(credentials.Database);
          break;
        case Authentication.Windows:
          cred = new WindowsCredentials(credentials.Database);
          break;
        default:
          cred = new ExplicitCredentials(credentials.Database, credentials.UserName, credentials.Password);
          break;
      }

      return Factory.GetConnection(credentials.Url
        , new ConnectionPreferences() { UserAgent = "InnovatorAdmin" }
        , async)
      .Continue(c =>
      {
        return c.Login(cred, async)
          .Convert(u => (IAsyncConnection)c);
      });
    }
Ejemplo n.º 2
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() { 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);
    }