Example #1
0
        public bool Run()
        {
            switch (_msg.RequestList.Count)
            {
            case 0:
                StatusMgr.LogError("No items in batch to process");
                return(false);

            case 1:
                break;

            default:
                if (_iterator != null)
                {
                    StatusMgr.LogError("Iterators are only allowed in single request batches");
                    return(false);
                }
                _msg.Attributes.OnError = SDK.ENRqOnError.roeContinue;
                break;
            }

            try
            {
                bool retVal = false;

                IteratorCall iterCall = null;

                do
                {
                    retVal = RunOneBatch(out iterCall);

                    if (iterCall != null)
                    {
                        if (!iterCall.iterator(iterCall.iteratorId, iterCall.remaining))
                        {
                            return(false); //user cancelled
                        }
                    }
                }while (retVal == true && iterCall != null);

                return(retVal);
            }
            catch (System.Runtime.InteropServices.COMException cex)
            {
                var entry = new StatusEntry()
                {
                    Summary     = "Request Error",
                    TypeOfEntry = StatusEntry.EntryType.Error
                };
                entry.AddLine(cex.Message);

                try
                {
                    //This may not be the source of the error
                    //entry.AddLine(_msg.ToXMLString());

                    //this causes further COM errors
                    //entry.AddLine(_msg.Attributes.ResponseData.ToString());
                    entry.AddLine("Enable SDK logging for further diagnostics");
                }
                catch (Exception)
                {
                }

                StatusMgr.LogEntry(entry);

                return(false);
            }
        }
Example #2
0
        private bool RunOneBatch(out IteratorCall _iterCall)
        {
            const string ERROR_CONTEXT = "QuickBooks query follow-up";

            _iterCall = null;

            var resp = _mgr.DoRequests(_msg);

            if (resp == null || resp.ResponseList == null)
            {
                throw new Exception("null response returned from batch");
            }

            if (resp.ResponseList.Count == 0)
            {
                throw new Exception("no response items returned from batch");
            }

            bool errors = false;

            var lstResponse = resp.ResponseList;

            for (int idx = 0; idx < lstResponse.Count; idx++)
            {
                var itm = lstResponse.GetAt(idx);

                if (itm == null)
                {
                    var entry = new StatusEntry()
                    {
                        TypeOfEntry = StatusEntry.EntryType.Error,
                        Summary     = "null reponse item encountered",
                        Details     = resp.ToXMLString()
                    };

                    StatusMgr.LogEntry(entry);

                    return(false);
                }

                ClosureSpec cls  = null;
                int         rqID = int.Parse(itm.RequestID);

                if (_clousures.ContainsKey(rqID))
                {
                    cls = _clousures[rqID];
                }

                if (itm.StatusCode == 0 || itm.StatusCode == 500)
                {
                    if (cls != null)
                    {
                        try
                        {
                            cls.success(itm.Detail);
                        }
                        catch (Exception ex)
                        {
                            StatusMgr.HandleException(ERROR_CONTEXT, ex);
                            return(false);
                        }
                    }

                    if (_iterator != null)
                    {
                        int iteratorRemaining = 0;

                        try
                        {
                            //iterator remaining count can be toxic, it
                            //iterator is not set up correctly
                            iteratorRemaining = itm.iteratorRemainingCount;
                        }
                        catch (System.Runtime.InteropServices.COMException)
                        {
                            StatusMgr.LogError("Iterator not properly initialized");
                        }

                        if (iteratorRemaining > 0)
                        {
                            _iterCall = new IteratorCall()
                            {
                                iterator   = _iterator,
                                iteratorId = itm.iteratorID,
                                remaining  = iteratorRemaining
                            };
                        }
                    }
                }
                else if (cls != null && cls.allowEmptyReturn &&
                         itm.StatusCode == 1)
                {
                    //process empty result
                    try
                    {
                        cls.success(null);
                    }
                    catch (Exception ex)
                    {
                        StatusMgr.HandleException(ERROR_CONTEXT, ex);
                        return(false);
                    }
                }
                else
                {
                    switch (itm.StatusSeverity.ToLower())
                    {
                    case "info":
                        StatusMgr.Trace(itm.StatusMessage);
                        if (cls != null)
                        {
                            try
                            {
                                cls.success(itm.Detail);
                            }
                            catch (Exception ex)
                            {
                                StatusMgr.HandleException(ERROR_CONTEXT, ex);
                                return(false);
                            }
                        }
                        break;

                    case "warning":
                    case "warn":
                        StatusMessage(idx, "Warning", itm.StatusMessage, itm.StatusCode, false);
                        if (cls != null)
                        {
                            try
                            {
                                cls.success(itm.Detail);
                            }
                            catch (Exception ex)
                            {
                                StatusMgr.HandleException(ERROR_CONTEXT, ex);
                                return(false);
                            }
                        }
                        break;

                    case "error":
                    default:
                        if (cls != null && cls.failure != null)
                        {
                            try
                            {
                                cls.failure(itm.StatusMessage, itm.StatusCode);
                            }
                            catch (Exception ex)
                            {
                                StatusMgr.HandleException(ERROR_CONTEXT, ex);
                                return(false);
                            }
                        }
                        else
                        {
                            StatusMessage(idx, "Error", itm.StatusMessage, itm.StatusCode, true);
                        }
                        errors = true;
                        break;
                    }
                }
                //end of response loop
            }
            return(errors == false);
        }
Example #3
0
        private bool RunOneBatch(out IteratorCall _iterCall)
        {
            const string ERROR_CONTEXT = "QuickBooks query follow-up";

            _iterCall = null;

            var resp = _mgr.DoRequests(_msg);

            if (resp == null || resp.ResponseList == null)
            {
                throw new Exception("null response returned from batch");
            }

            if (resp.ResponseList.Count == 0)
            {
                throw new Exception("no response items returned from batch");
            }

            bool errors = false;

            var lstResponse = resp.ResponseList;

            for (int idx = 0; idx < lstResponse.Count; idx++)
            {
                var itm = lstResponse.GetAt(idx);

                if (itm == null)
                {
                    var entry = new StatusEntry()
                    {
                        TypeOfEntry = StatusEntry.EntryType.Error,
                        Summary = "null reponse item encountered",
                        Details = resp.ToXMLString()
                    };

                    StatusMgr.LogEntry(entry);

                    return false;
                }

                ClosureSpec cls = null;
                int rqID = int.Parse(itm.RequestID);

                if (_clousures.ContainsKey(rqID))
                {
                    cls = _clousures[rqID];
                }

                if (itm.StatusCode == 0)
                {
                    if (cls != null)
                    {
                        try
                        {
                            cls.success(itm.Detail);
                        }
                        catch (Exception ex)
                        {
                            StatusMgr.HandleException(ERROR_CONTEXT, ex);
                            return false;
                        }
                    }

                    if (_iterator != null)
                    {

                        int iteratorRemaining = 0;

                        try
                        {
                            //iterator remaining count can be toxic, it
                            //iterator is not set up correctly
                            iteratorRemaining = itm.iteratorRemainingCount;
                        }
                        catch (System.Runtime.InteropServices.COMException)
                        {
                            StatusMgr.LogError("Iterator not properly initialized");
                        }

                        if (iteratorRemaining > 0)
                        {
                            _iterCall = new IteratorCall()
                            {
                                iterator = _iterator,
                                iteratorId = itm.iteratorID,
                                remaining = iteratorRemaining
                            };
                        }
                    }
                }
                else if (cls != null && cls.allowEmptyReturn
                            && (itm.StatusCode == 1 || itm.StatusCode == 500))
                {
                    //process empty result
                    try
                    {
                        cls.success(null);
                    }
                    catch (Exception ex)
                    {
                        StatusMgr.HandleException(ERROR_CONTEXT, ex);
                        return false;
                    }
                }
                else
                {
                    switch (itm.StatusSeverity.ToLower())
                    {
                        case "info":
                            StatusMgr.Trace(itm.StatusMessage);
                            if (cls != null)
                            {
                                try
                                {
                                    cls.success(itm.Detail);
                                }
                                catch (Exception ex)
                                {
                                    StatusMgr.HandleException(ERROR_CONTEXT, ex);
                                    return false;
                                }
                            }
                            break;

                        case "warning":
                        case "warn":
                            StatusMessage(idx, "Warning", itm.StatusMessage, itm.StatusCode, false);
                            if (cls != null)
                            {
                                try
                                {
                                    cls.success(itm.Detail);
                                }
                                catch (Exception ex)
                                {
                                    StatusMgr.HandleException(ERROR_CONTEXT, ex);
                                    return false;
                                }
                            }
                            break;

                        case "error":
                        default:
                            if (cls != null && cls.failure != null)
                            {
                                try
                                {
                                    cls.failure(itm.StatusMessage, itm.StatusCode);
                                }
                                catch (Exception ex)
                                {
                                    StatusMgr.HandleException(ERROR_CONTEXT, ex);
                                    return false;
                                }
                            }
                            else
                            {
                                StatusMessage(idx, "Error", itm.StatusMessage, itm.StatusCode, true);
                            }
                            errors = true;
                            break;
                    }
                }
                //end of response loop
            }
            return errors == false;
        }