Example #1
0
 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;
     }
 }
Example #2
0
 public SQLBrokerError(string message, Exception innerException = null,
                       ConnectionParams connection = null, SQLResult sqlResult = null, BOResult boResult = null) : base(message, innerException)
 {
     config          = SAPB1.brokerConf;
     this.boResult   = boResult;
     this.sqlResult  = sqlResult;
     this.connection = new NoPwdConnectionParams(connection);
     if (this.connection == null && boResult?.connection != null)
     {
         this.connection = boResult?.connection;
     }
     if (this.connection == null && sqlResult?.connection != null)
     {
         this.connection = sqlResult?.connection;
     }
 }
Example #3
0
 public static BOResult BOJob(DIConnection.IConnRef t, 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();
     result.boName  = name;
     result.reqType = post ? "POST" : (delete ? "DELETE" : (put ? "PUT" : "GET"));
     if (string.IsNullOrEmpty(id))
     {
         result.id = id;
     }
     try {
         string cuXml = q.boXml;
         if (string.IsNullOrEmpty(cuXml))
         {
             if (q.bo != null)
             {
                 System.Xml.XmlDocument xmlDoc = Newtonsoft.Json.JsonConvert.DeserializeXmlNode(q.bo.ToString());
                 cuXml = xmlDoc.OuterXml;                         // Maybe xmlDoc.ToString() would be OK, too
             }
         }
         result.found = true;
         string xmlText = crudBO(t, name, ref id, cuXml, delete, put, post, q.xmlSchema, ref result.xmlSchema, ref result.found);
         result.id         = id;        //For newly created objects the BO id is returned
         result.statusCode = System.Net.HttpStatusCode.OK;
         if (string.IsNullOrEmpty(xmlText))
         {
             if (!result.found)
             {
                 result.statusCode = System.Net.HttpStatusCode.NotFound;
                 result.errorCode  = (int)System.Net.HttpStatusCode.NotFound;
                 result.errorText  = $"Not found {name} for ID {id}";
             }
             else
             {
                 if (delete)
                 {
                     result.statusCode = System.Net.HttpStatusCode.Gone;
                 }
             }
         }
         else
         {
             if (post)
             {
                 result.statusCode = System.Net.HttpStatusCode.Created;
             }
             //Is there a way to find out, when PUT/Update was requested, if nodified or not?
             //Possibly the Not Modified HTTP is a situation when the update was rejected because of some reasons.
             //if (put) result.statusCode = System.Net.HttpStatusCode.NotModified;
             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.bo = Newtonsoft.Json.Linq.JToken.Parse(jsonText);
         }
         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;
     }
 }