Exemplo n.º 1
0
        //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
        //Send Document : Used from Tests and From Timer Service

        public static ServicesATSoapResult SendDocument(FIN_DocumentFinanceMaster documentMaster)
        {
            //Send Document
            ServicesAT sendDocument = new ServicesAT(documentMaster);
            //Get Result from SendDocument Object
            string resultSend = sendDocument.Send();
            //Post
            ServicesATSoapResult soapResult = sendDocument.SoapResult;

            //Show Result
            //Log(string.Format("SendDocument DocumentMaster: [{0}]", documentMaster.DocumentNumber));
            //Log(string.Format("SendDocument ResultRaw: [{0}]", resultSend));
            //if (sendDocument.SoapResult != null) {
            //    Log(string.Format(@"{0}ResultCode: [{1}]{0}ResultMessage: [{2}]"
            //        , Environment.NewLine
            //        , sendDocument.SoapResult.ReturnCode
            //        , sendDocument.SoapResult.ReturnMessage
            //    ));
            //    //WB
            //    if (!string.IsNullOrEmpty(sendDocument.SoapResult.ATDocCodeID))
            //    {
            //        Log(string.Format(@"ATDocCodeID: [{0}]", sendDocument.SoapResult.ATDocCodeID));
            //    }
            //}

            return(soapResult);
        }
Exemplo n.º 2
0
        //:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
        //AT WebServices

        public ServicesATSoapResult SendDocument(Guid pDocumentMaster)
        {
            ServicesATSoapResult result = null;

            try
            {
                FIN_DocumentFinanceMaster documentMaster = (FIN_DocumentFinanceMaster)GlobalFramework.SessionXpo.GetObjectByKey(typeof(FIN_DocumentFinanceMaster), pDocumentMaster);

                if (documentMaster != null)
                {
                    //Send Document
                    ServicesAT servicesAT = new ServicesAT(documentMaster);
                    //Get Result from SendDocument Object
                    string resultSend = servicesAT.Send();
                    //Get SoapResult
                    result = servicesAT.SoapResult;

                    if (
                        //Error: Não foi possível resolver o nome remoto: 'servicos.portaldasfinancas.gov.pt'
                        result == null
                        //Error: <faultcode>33</faultcode>
                        ||
                        result != null && string.IsNullOrEmpty(result.ReturnCode)
                        )
                    {
                        result = new ServicesATSoapResult("200", resultSend);
                        servicesAT.PersistResult(result);
                        Utils.Log(string.Format("Error {0}: [{1}]", result.ReturnCode, result.ReturnMessage));
                    }
                    else
                    {
                        //Output in ServiceAT With Log, here is optional
                        //Utils.Log(string.Format("SendDocument Result: [{0}]:[{1}]:[{2}]", result.ReturnCode, result.ReturnMessage, result.ReturnRaw));
                    }
                }
                else
                {
                    //All messages are in PT, from ATWS, dont required translation here
                    string errorMsg = string.Format("Documento Inválido: {0}", pDocumentMaster);
                    result = new ServicesATSoapResult("202", errorMsg);
                    Utils.Log(string.Format("Error {0}: [{1}]", result.ReturnCode, result.ReturnMessage));
                }
            }
            catch (Exception ex)
            {
                _log.Error(ex.Message, ex);
                if (Environment.UserInteractive)
                {
                    Utils.Log(ex.Message);
                }
                //Send Error Message : 210 is All Exceptions Errors
                result = new ServicesATSoapResult("210", ex.Message);
            }

            //Dont Send null ServicesATSoapResult here, else triggers erros outside
            return(result);
        }