//Inicializa aplicacion public static void SetApplication() { //Se obtiene string de conexion de Cliente SAP B1 if (Environment.GetCommandLineArgs().Count() == 1) { throw new Exception("No se agregaron los parametros de conexión...", new Exception("No se encontro string de conexión SAP B1")); } ConnectionString = Environment.GetCommandLineArgs().GetValue(1).ToString(); //Se realiza conexion SAPbouiCOM.SboGuiApi client = new SAPbouiCOM.SboGuiApi(); client.Connect(ConnectionString); SBOApplication = client.GetApplication(-1); //Se carga <<Company>> de aplicacion SBOCompany = new SAPbobsCOM.Company(); string cookies = SBOCompany.GetContextCookie(); string connectionContext = SBOApplication.Company.GetConnectionContext(SBOCompany.GetContextCookie()); SBOCompany.SetSboLoginContext(connectionContext); //Conexion con sociedad if (SBOCompany.Connect() != 0) { throw new Exception(SBOError); } }
public static void ConnectViaSSO() { try { // 1. Connect to UI ConnectViaUI(); oCompany = new SAPbobsCOM.Company(); string sCookie = oCompany.GetContextCookie(); string connInfo = oApp.Company.GetConnectionContext(sCookie); // It will set Server, db, username, password to the DI Company oCompany.SetSboLoginContext(connInfo); lRetCode = oCompany.Connect(); MsgBoxWrapper("Addon MIS_TO_PROD Connected via SSO"); CompDB = oCompany.CompanyDB; } catch (Exception ex) { MsgBoxWrapper(ex.Message); } }
private int SetConnectionContext() { int setConnectionContextReturn = 0; string sCookie = null; string sConnectionContext = null; int lRetCode = 0; // // First initialize the Company object oCompany = new SAPbobsCOM.Company(); // // Acquire the connection context cookie from the DI API. sCookie = oCompany.GetContextCookie(); // // Retrieve the connection context string from the UI API using the // // acquired cookie. sConnectionContext = SBO_Application.Company.GetConnectionContext(sCookie); // // before setting the SBO Login Context make sure the company is not // // connected if (oCompany.Connected == true) { oCompany.Disconnect(); } // // Set the connection context information to the DI API. setConnectionContextReturn = oCompany.SetSboLoginContext(sConnectionContext); return(setConnectionContextReturn); }
private int SetConnectionContext() { int setConnectionContextReturn = 0; string sCookie = null; string sConnectionContext = null; oCompany = new SAPbobsCOM.Company(); sCookie = oCompany.GetContextCookie(); sConnectionContext = SBO_Application.Company.GetConnectionContext(sCookie); setConnectionContextReturn = oCompany.SetSboLoginContext(sConnectionContext); return(setConnectionContextReturn); }
/// <summary> /// Connect UI and DI Api /// </summary> /// <param name="connectionString">Connection String from SBO Main Application</param> /// <param name="loggingEnabled">Is SBO Common Logging enabled</param> public static void Connect(string connectionString = null, bool loggingEnabled = true) { if (connectionString == null) { connectionString = Environment.GetCommandLineArgs().Length > 1 ? Convert.ToString(Environment.GetCommandLineArgs().GetValue(1)) : ""; } var sboGuiApi = new SAPbouiCOM.SboGuiApi(); _diCompany = new SAPbobsCOM.Company(); try { sboGuiApi.Connect(connectionString); _application = sboGuiApi.GetApplication(); var contextCookie = _diCompany.GetContextCookie(); var diCompanyConnectionString = _application.Company.GetConnectionContext(contextCookie); var responseCode = _diCompany.SetSboLoginContext(diCompanyConnectionString); ErrorHelper.HandleErrorWithException(responseCode, "DI API Could not Set Sbo Login Context"); var connectResponse = _diCompany.Connect(); ErrorHelper.HandleErrorWithException(connectResponse, "DI API Could not connect"); if (loggingEnabled) { SboAppLogger.Enable(); } var assemblyName = System.Reflection.Assembly.GetExecutingAssembly().GetName().Name; Logger.Info($"{assemblyName} connected"); SetAppEvents(); } catch (Exception ex) { Logger.Error($"SboApp UI Connect Error: {ex.Message}", ex); throw; } }
public void B1Connect(bool stopEvents) { SAPbouiCOM.SboGuiApi objGUIApi = null; SAPbobsCOM.Company objCompany = null; try { _Logger.Debug("Starting SAP Connection"); objGUIApi = new SAPbouiCOM.SboGuiApi(); _Logger.Debug("Retrieving connection string from Cache"); objGUIApi.Connect((string)T1.CacheManager.CacheManager.Instance.getFromCache(T1.CacheManager.Settings._Main.connStringCacheName)); _Logger.Debug("Connectong to current company"); objApplication = objGUIApi.GetApplication(-1); objApplication.EventLevel = SAPbouiCOM.BoEventLevelType.elf_Both; if (Settings._Main.useCompatibilityConnection) { _Logger.Info("Connecting to DI API using Compatibility mode (cookies)"); objCompany = new SAPbobsCOM.Company(); string strContextCookie = objCompany.GetContextCookie(); string strConnectionString = objApplication.Company.GetConnectionContext(strContextCookie); _Logger.Debug("Setting Login Context"); if (objCompany.SetSboLoginContext(strConnectionString) == 0) { if (objCompany.Connect() != 0) { string strError = objCompany.GetLastErrorCode() + ":" + objCompany.GetLastErrorDescription(); _Logger.Error(strError); } else { bool isHANA = objCompany.DbServerType == SAPbobsCOM.BoDataServerTypes.dst_HANADB ? true : false; T1.CacheManager.CacheManager.Instance.addToCache(T1.CacheManager.Settings._Main.isHANACacheName, isHANA, CacheManager.CacheManager.objCachePriority.NotRemovable); } } else { string strError = objCompany.GetLastErrorCode() + ":" + objCompany.GetLastErrorDescription(); _Logger.Error(strError); } } else { _Logger.Info("Connecting to DI API using shared memory library"); objCompany = new SAPbobsCOM.Company(); if (Settings._Main.useCompanyApplication) { objCompany.Application = objApplication; if (objCompany.Connect() != 0) { string strError = objCompany.GetLastErrorCode() + ":" + objCompany.GetLastErrorDescription(); _Logger.Error(strError); } else { bool isHANA = objCompany.DbServerType == SAPbobsCOM.BoDataServerTypes.dst_HANADB ? true : false; T1.CacheManager.CacheManager.Instance.addToCache(T1.CacheManager.Settings._Main.isHANACacheName, isHANA, CacheManager.CacheManager.objCachePriority.NotRemovable); } } else { objCompany = objApplication.Company.GetDICompany(); bool isHANA = objCompany.DbServerType == SAPbobsCOM.BoDataServerTypes.dst_HANADB ? true : false; T1.CacheManager.CacheManager.Instance.addToCache(T1.CacheManager.Settings._Main.isHANACacheName, isHANA, CacheManager.CacheManager.objCachePriority.NotRemovable); } } _Logger.Debug("Checking connection status"); blConnected = objCompany.Connected; if (blConnected) { _Logger.Debug("Connected to company " + objCompany.CompanyName); objCompany.XmlExportType = SAPbobsCOM.BoXmlExportTypes.xet_ExportImportMode; objCompany.XMLAsString = true; T1.B1.MainObject.Instance.B1Application = objApplication; T1.B1.MainObject.Instance.B1Company = objCompany; SAPbobsCOM.CompanyService objServ = objCompany.GetCompanyService(); SAPbobsCOM.AdminInfo objAdmInfo = objServ.GetAdminInfo(); T1.B1.InternalClasses.AdminInfo B1AdmInfo = new InternalClasses.AdminInfo(); B1AdmInfo.DecimalSeparator = objAdmInfo.DecimalSeparator; B1AdmInfo.ThousandsSeparator = objAdmInfo.ThousandsSeparator; B1AdmInfo.DateSeparator = objAdmInfo.DateSeparator; B1AdmInfo.SystemCurrency = objAdmInfo.SystemCurrency; B1AdmInfo.RateAccuracy = objAdmInfo.RateAccuracy; B1AdmInfo.QueryAccuracy = objAdmInfo.QueryAccuracy; B1AdmInfo.AccuracyofQuantities = objAdmInfo.AccuracyofQuantities; B1AdmInfo.PercentageAccuracy = objAdmInfo.PercentageAccuracy; B1AdmInfo.PriceAccuracy = objAdmInfo.PriceAccuracy; B1AdmInfo.TotalsAccuracy = objAdmInfo.TotalsAccuracy; B1AdmInfo.LocalCurrency = objAdmInfo.LocalCurrency; B1AdmInfo.DateTemplate = objAdmInfo.DateTemplate; B1AdmInfo.DisplayCurrencyontheRight = objAdmInfo.DisplayCurrencyontheRight == SAPbobsCOM.BoYesNoEnum.tYES ? true : false; B1AdmInfo.FederalTaxID = objAdmInfo.FederalTaxID; B1AdmInfo.MeasuringAccuracy = objAdmInfo.MeasuringAccuracy; T1.B1.MainObject.Instance.B1AdminInfo = B1AdmInfo; } if (stopEvents) { objHandler1 = new SAPbouiCOM._IApplicationEvents_ItemEventEventHandler(objApplication_ItemEvent); objHandler2 = new SAPbouiCOM._IApplicationEvents_MenuEventEventHandler(objApplication_MenuEvent); objApplication.ItemEvent += objHandler1; objApplication.MenuEvent += objHandler2; } } catch (COMException comEx) { //Exception er = new Exception(Convert.ToString(comEx.ErrorCode + "::" + comEx.Message + "::" + comEx.StackTrace)); _Logger.Error("", comEx); } catch (Exception er) { _Logger.Error("", er); } }
private int SetConnectionContext() { int setConnectionContextReturn = 0; string sCookie = null; string sConnectionContext = null; int lRetCode = 0; oCompany = new SAPbobsCOM.Company(); sCookie = oCompany.GetContextCookie(); sConnectionContext = SBO_Application.Company.GetConnectionContext(sCookie); if (oCompany.Connected == true) { oCompany.Disconnect(); } setConnectionContextReturn = oCompany.SetSboLoginContext(sConnectionContext); return setConnectionContextReturn; }
private void ConnectDi() { try { Logger.Info("Initializing DI API for SAP Business One Addon - {0}", Name); if (Company == null) { Company = new Company(); } string cookie = Company.GetContextCookie(); ConnectionString = Application.Company.GetConnectionContext(cookie); // ////////////////My Code int ret = Company.SetSboLoginContext(ConnectionString); int result = 0;//; oCompany.Connect(); Company = (SAPbobsCOM.Company)Application.Company.GetDICompany(); ///////////// /// oldCode ///////////// //if (Company.Connected) // Company.Disconnect(); //int result = Company.SetSboLoginContext(ConnectionString); //if (result != 0) // throw new Exception(string.Format("Error setting login context: {0} - {1} - {2}", result, Company.GetLastErrorCode(), Company.GetLastErrorDescription())); //Logger.Info("Connecting to company database (type: {0}, server: {1}, licenseserver: {2}, database: {3})", Company.DbServerType, Company.Server, Company.LicenseServer, Company.CompanyDB); //result = Company.Connect(); //// end of old code if (result != 0 && !Company.Connected) { throw new Exception(string.Format("Could not connect to company: {0} - {1} - {2}", result, Company.GetLastErrorCode(), Company.GetLastErrorDescription())); } else { Application.SetStatusBarMessage("Connected!", BoMessageTime.bmt_Short, false); } Logger.Info("Addon {0} (version {1}) initialized and connected to SAP Business One DI API version {2}.", Name, Version, Company.Version); } catch (Exception e) { throw new Exception("Error connecting to DI API", e); } }