public static IPromise<IEditorProxy> FromConn(ConnectionData conn)
    {
      Func<ConnectionData, IPromise<IEditorProxy>> factory;
      if (_factories.TryGetValue(conn.Type, out factory))
      {
        return factory.Invoke(conn);
      }
      else
      {
        switch (conn.Type)
        {
          case ConnectionType.Innovator:
            return conn.ArasLogin(true)
              .Convert(c => (IEditorProxy)new Editor.ArasEditorProxy(c, conn.ConnectionName)
              {
                ConnData = conn
              });
          case ConnectionType.Soap:
            var service = new Innovator.Client.Connection.DefaultHttpService();
            return service.Execute("GET", conn.Url, null, null, true, null)
              .Convert(r =>
              {
                ServiceDescription descrip;
                using (var reader = new StreamReader(r.AsStream))
                using (var xml = XmlReader.Create(reader))
                {
                  descrip = ServiceDescription.Read(xml);
                }

                return (IEditorProxy)new Editor.SoapEditorProxy(conn, descrip
                  , Editor.XmlSchemas.SchemasFromDescrip(descrip));
              });
          case ConnectionType.SqlServer:
            return Promises.Resolved<IEditorProxy>(new Editor.SqlEditorProxy(conn));
          case ConnectionType.Sharepoint:
            return new Editor.SharepointEditorProxy(conn).Initialize().ToPromise();
        }
        return Promises.Rejected<IEditorProxy>(new NotSupportedException("Unsupported connection type"));
      }
    }
    public ConnectionData Clone()
    {
      var result = new ConnectionData()
      {
        ConnectionName = this.ConnectionName,
        Database = this.Database,
        Password = this.Password,
        Url = this.Url,
        UserName = this.UserName,
        Color = this.Color,
        Type = this.Type,
        Authentication = this.Authentication,
        Confirm = this.Confirm,
        Timeout = this.Timeout
      };

      foreach (var param in _params)
      {
        result._params.Add(param);
      }
      return result;
    }
    public void SetConnection(ConnectionData connData)
    {
      _conn = null;
      _connData = null;
      btnEditConnection.Text = "No Connection ▼";
      lblConnColor.BackColor = Color.Transparent;

      if (connData.Type != ConnectionType.Innovator)
      {
        MessageBox.Show("Only Innovator connections are supported");
        return;
      }

      _connData = connData;
      btnEditConnection.Text = "Connecting... ▼";
      _conn = connData.ArasLogin(true)
        .UiPromise(this)
        .Done(c =>
        {
          btnEditConnection.Text = connData.ConnectionName + " ▼";
          lblConnColor.BackColor = connData.Color;
        });
    }
    public void SetConnection(ConnectionData conn)
    {
      if (!_loadingConnection && !string.IsNullOrEmpty(conn.Url))
      {
        _loadingConnection = true;
        btnSoapAction.Visible = false;
        lblSoapAction.Visible = false;
        exploreButton.Visible = false;
        btnSubmit.Visible = false;

        var lastQuery = SnippetManager.Instance.GetLastQueryByConnection(conn.ConnectionName);
        inputEditor.Text = lastQuery.Text;
        this.SoapAction = lastQuery.Action;
        inputEditor.CleanUndoStack();

        try
        {
          btnEditConnections.Text = "Connecting... ▼";
          ProxyFactory.FromConn(conn)
            .UiPromise(this)
            .Done(proxy =>
            {
              SetProxy(proxy);
              _disposeProxy = true;
            })
            .Fail(ex =>
            {
              lblProgress.Text = ex.Message;
              btnEditConnections.Text = "Not Connected ▼";
              lblConnection.Visible = true;
              btnEditConnections.Visible = lblConnection.Visible;
            }).Always(() => _loadingConnection = false);
        }
        catch (Exception ex)
        {
          MessageBox.Show(ex.Message);
        }
      }
    }
Example #5
0
    public async Task<bool> SetConnection(ConnectionData conn)
    {
      if (!_loadingConnection && !string.IsNullOrEmpty(conn.Url))
      {
        _loadingConnection = true;
        btnSoapAction.Visible = false;
        lblSoapAction.Visible = false;
        exploreButton.Visible = false;
        btnSubmit.Visible = false;

        if (inputEditor.Document.TextLength <= 0 || conn.Type != _oldConnType)
        {
          var lastQuery = SnippetManager.Instance.GetLastQueryByConnection(conn.ConnectionName);
          inputEditor.Text = lastQuery.Text;
          this.SoapAction = lastQuery.Action;
          inputEditor.CleanUndoStack();
        }
        _oldConnType = conn.Type;

        try
        {
          btnEditConnections.Text = "Connecting... ▼";
          var proxy = await ProxyFactory.FromConn(conn).ToTask();
          SetProxy(proxy);
          _disposeProxy = true;
        }
        catch (Exception ex)
        {
          lblProgress.Text = ex.Message;
          btnEditConnections.Text = "Not Connected ▼";
          lblConnection.Visible = true;
          btnEditConnections.Visible = lblConnection.Visible;
        }
        _loadingConnection = false;
        return true;
      }
      return false;
    }