コード例 #1
0
ファイル: QbWcService.cs プロジェクト: theparagroup/paraquick
 protected void RequestError(DbContext db, EfParaquickSession efSession, EfParaquickMessage efMessage, string errorMessage)
 {
     ServiceUtils.RequestError(db, efMessage, errorMessage);
     OnRequestError(db, efSession, efMessage, errorMessage);
 }
コード例 #2
0
ファイル: QbWcService.cs プロジェクト: theparagroup/paraquick
 protected virtual string OnGetLastError(DbContext db, EfParaquickSession efSession)
 {
     return(ServiceUtils.FormatErrors(efSession));
 }
コード例 #3
0
ファイル: QbWcService.cs プロジェクト: theparagroup/paraquick
        protected override int OnResponseMessage(string ticket, string responseXml, HResult hResult)
        {
            //zerotickets should never be seen here, but if so, they will recur in getLastError and be logged there
            if (ticket != ServiceUtils.ZeroTicket)
            {
                using (var db = ServiceUtils.CreateDbContext())
                {
                    EfParaquickSession efSession = ServiceUtils.FindSession(db, ticket);

                    //bad tickets will recur in getLastError and be logged there
                    if (efSession != null)
                    {
                        //COM error?
                        if (hResult == null)
                        {
                            //deserialize response and process success/error
                            RsMsgSet rsMsgSet = new RsMsgSet();
                            QBXML    qbxml    = rsMsgSet.Deserialize(responseXml);

                            //TODO update paraquick entities based on response type
                            foreach (var rsMsg in rsMsgSet)
                            {
                                var efMessage = efSession.ParaquickMessages.Where(m => m.RequestId == rsMsg.requestID).FirstOrDefault();

                                if (efMessage != null)
                                {
                                    ServiceUtils.Response(db, efMessage, rsMsg);

                                    //allow implementor to do something with response
                                    OnResponse(db, efMessage, rsMsg);

                                    if (rsMsg.statusCode != "0")
                                    {
                                        //TODO stop on errors?
                                        ResponseError(db, efSession, efMessage, rsMsg.statusMessage);
                                    }
                                }
                                else
                                {
                                    //TODO stop on errors?
                                    SessionError(db, efSession, $"Can't find request ({rsMsg.requestID})");
                                }
                            }


                            //TODO StopOnErrors? do we stop on errors here (return -1) or keep going?
                            //report "%" - completed messages/total messages for session
                            int pctComplete = ServiceUtils.CalculatePercentComplete(db, efSession);
                            return(pctComplete);
                        }
                        else
                        {
                            SessionError(db, efSession, $"COM Error {hResult.Format()}");
                        }
                    }
                }
            }

            //error condition
            return(-1);
        }
コード例 #4
0
ファイル: QbWcService.cs プロジェクト: theparagroup/paraquick
 protected void SessionError(DbContext db, EfParaquickSession efSession, string errorMessage)
 {
     ServiceUtils.SessionError(db, efSession, errorMessage);
     OnSessionError(db, efSession, errorMessage);
 }
コード例 #5
0
ファイル: QbWcService.cs プロジェクト: theparagroup/paraquick
        protected override string OnCreateRequestMessage(string ticket, string hcpXml, string companyFilePath, string qbCountry, int qbMajorVersion, int qbMinorVersion)
        {
            //zerotickets should never be seen here, but if so, they will recur in getLastError and be logged there
            if (ticket != ServiceUtils.ZeroTicket)
            {
                using (var db = ServiceUtils.CreateDbContext())
                {
                    EfParaquickSession efSession = ServiceUtils.FindSession(db, ticket);

                    //bad tickets will recur in getLastError and be logged there
                    if (efSession != null)
                    {
                        //confirm file path
                        if (IsCompanyFileValid(db, efSession, companyFilePath))
                        {
                            //save the hcpXml & other information in the company record
                            if (!string.IsNullOrEmpty(hcpXml))
                            {
                                ServiceUtils.Session(db, efSession, hcpXml, qbCountry, qbMajorVersion, qbMinorVersion);
                            }

                            //find next message for this ticket
                            List <EfParaquickMessage> efMessages = ServiceUtils.FindNextMessageSet(db, efSession);

                            if (efMessages != null)
                            {
                                //TODO do we set OnError to stopOnErrors in the request?
                                RqMsgSet rqMsgSet = new RqMsgSet();

                                foreach (var efMessage in efMessages)
                                {
                                    //deserialize request message
                                    IRqMsg rqMsg = (IRqMsg)Msg.Deserialize(efMessage.MessageType.RequestTypeName, efMessage.RequestXml);

                                    //allow implementation to see/modify message
                                    string errorMessage = OnRequest(db, efMessage, rqMsg);
                                    if (errorMessage == null)
                                    {
                                        //add it to message set
                                        rqMsgSet.Add(rqMsg);
                                    }
                                    else
                                    {
                                        //"close" this request, don't send to WC
                                        RequestError(db, efSession, efMessage, errorMessage);
                                    }
                                }

                                //TODO is "nothing to do" at this point an error?

                                //send it
                                string xml = rqMsgSet.Serialize();
                                return(xml);
                            }
                            else
                            {
                                //something wrong with the message set in the database, log it
                                SessionError(db, efSession, $"An error occurred when building the message set for session ({efSession.Id})");

                                //this is pretty bad, let's just close the session
                                ServiceUtils.Close(db, efSession);
                            }
                        }
                        else
                        {
                            //log error
                            SessionError(db, efSession, $"Incorrect company file ({companyFilePath}) for company ({efSession.CompanyId})");
                        }
                    }
                }
            }

            //error condition
            return("");
        }