/// <summary> /// Establishes the connection to SAP Business One. /// <para /> /// Note that without connection both <see cref="Application" /> and <see cref="Company" /> are <see langword="null" />. /// </summary> /// <exception cref="ConnectionException"> /// Thrown when an error occurs while connecting. /// </exception> public void Connect() { var attempts = 1; const int maxAttempts = 3; const int intervalMilliseconds = 100; do { ConnectAndAudit(); if (Connected) { return; } // wait for next attempt Thread.Sleep(attempts * intervalMilliseconds); attempts++; } while (attempts <= maxAttempts); // could not connect var message = $@"{Audit.LastMessage}{Environment.NewLine}" + @"More information in the 'Data' property of the exception."; var e = new ConnectionException(message); e.Data.Add(@"errors", Audit.Messages); throw e; }
/// <summary> /// Connects this instance. /// </summary> /// <exception cref="ConnectionException"> /// Thrown when an error connecting to Business One occurs. /// </exception> public virtual void Connect() { try { if (Connected) { return; } var gui = new SboGuiApiClass(); gui.Connect(connectionString); Application = gui.GetApplication(); Company = new DiCompanyClass { Application = Application }; var result = Company.Connect(); if (result != 0) { var message = $"{result} {Company.GetLastErrorDescription()}"; throw new ConnectionException(message); } Connected = true; } catch (COMException e) { throw ConnectionException.CreateFrom(e); } }
/// <summary> /// Connects this instance. /// </summary> /// <exception cref="ConnectionException"> /// Thrown when an error connecting to Business One occurs. /// </exception> public void Connect() { try { if (Connected) { return; } var gui = new SboGuiApi(); gui.Connect(connectionString); Application = gui.GetApplication(); } catch (COMException e) { throw ConnectionException.CreateFrom(e); } Connected = true; }