public static BOResult BORequest(BORequest q, string name, string id, BOResult result, bool delete = false, bool put = false, bool post = false) { if (!brokerConf.bo) { throw new SQLBrokerError("SAP B1 BO module was disabled in web.config for SQL Broker"); } System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch(); sw.Start(); try { var cp = getEffectiveConnectionParams(q?.connection, ref result.connection); using (var t = DIConnection.startTransaction(cp)) { //Must be used with using !!! BOJob(t, q, name, id, result, delete, put, post); return(result); } } catch (Exception e) { if (e is SQLBrokerError) { throw; } else { throw new SQLBrokerError(e.Message, innerException: e, boResult: result); } } finally { sw.Stop(); result.execMillis = (int)sw.Elapsed.TotalMilliseconds; } }
public ConnRef(DIConnection conn) { if (DIConnection.currentRef != null) { throw new Exception("Connection is in use"); } else { Me.company.StartTransaction(); DIConnection.currentRef = this; } }
static void SQLDIQuery(SQLQuery q, SQLResult result, ConnectionParams cp) { using (var t = DIConnection.startTransaction(cp)) { //Must be used with using !!! SAPbobsCOM.Recordset rs = t.company.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset); rs.DoQuery(q.SQL); result.statusCode = System.Net.HttpStatusCode.OK; //These mustn't be called since we get a transaction error //result.errorCode = t.company.GetLastErrorCode(); //result.errorText = t.company.GetLastErrorDescription(); string xmlText = rs.GetAsXML(); if (q.rawXml) { result.rawXml = xmlText; } System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument(); xmlDoc.LoadXml(xmlText); string jsonText = Newtonsoft.Json.JsonConvert.SerializeXmlNode(xmlDoc, Newtonsoft.Json.Formatting.Indented, false); result.data = Newtonsoft.Json.Linq.JToken.Parse(jsonText); if (q.columnInfo) { int cc = rs.Fields.Count; SAPbobsCOM.Fields fields = rs.Fields; for (int i = 0; i < cc; i++) { SAPbobsCOM.Field f = fields.Item(i); SQLResult.Column column = new SQLResult.Column(); column.name = f.Name; column.dataType = f.Type.ToString(); column.subType = f.SubType.ToString(); //column.description = f.Description; SAPbobsCOM.ValidValues vvs = f.ValidValues; int vvc = vvs.Count; for (int k = 0; k < vvc; k++) { SAPbobsCOM.ValidValue v = vvs.Item(k); column.validValues.Add(new SQLResult.ValidValue { value = v.Value, description = v.Description }); } result.columns.Add(column); } } } }