/// <summary>
        /// loops through the data
        /// </summary>
        /// <param name="sessionId"></param>
        /// <param name="xmlstringdata"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        private bool ReadResult(ref string sessionId, string xmlstringdata, ref VisionMessage message)
        {
            bool _lastChunk = false;

            //create new message if reference is null
            if (message == null)
            {
                message = new VisionMessage();
            }

            //get existing data from message...
            XDocument _existingData = message.ReturnedData;

            var _xdocResult = XDocument.Load(new System.IO.StringReader(xmlstringdata));
            var _message    = VisionMessage.FromXML(_xdocResult);

            if (string.IsNullOrEmpty(_message.ReturnCode) == false && _message.ReturnCode != "1")
            {
                message = _message;
                return(true);
            }

            //append results
            if (_xdocResult.Elements("RECS") != null)
            {
                sessionId = _xdocResult.Element("RECS").Attribute("SessionID").Value;

                if (_xdocResult.Element("RECS").Attribute("LastChunk") == null)
                {
                    _lastChunk = true;
                }
                else
                {
                    _lastChunk = (_xdocResult.Element("RECS").Attribute("LastChunk").Value == "1" ? true : false);
                }

                if (_existingData == null || _existingData.ElementExists("RECS") == false)
                {
                    _existingData = _xdocResult;
                }
                else
                {
                    _existingData.Element("RECS").Add(_xdocResult.Element("RECS").Elements());
                }
            }

            //put together message
            message.ReturnedData = _existingData;
            message.ReturnCode   = "1";
            message.ReturnDesc   = "Succesful";

            return(_lastChunk);
        }
 /// <summary>
 /// deletes records from udic
 /// </summary>
 /// <param name="udicName"></param>
 /// <param name="data"></param>
 /// <returns></returns>
 public VisionMessage DeleteUDIC(string udicName, XElement data)
 {
     try
     {
         string _strData    = data.ToString().Replace("xmlns=\"\"", "");
         string _strMessage = service.DeleteUDIC(GetConnectionInfo(), udicName, _strData);
         return(VisionMessage.FromXML(_strMessage));
     }
     catch (Exception ex)
     {
         logger.Error(ex, $"DeleteUDIC() failed");
         return(VisionMessage.FromException(ex));
     }
 }
 public VisionMessage DeleteRecords(string data)
 {
     try
     {
         string _strData    = data.Replace("xmlns=\"\"", "");
         string _strMessage = service.DeleteRecords(GetConnectionInfo(), _strData);
         return(VisionMessage.FromXML(_strMessage));
     }
     catch (Exception ex)
     {
         logger.Error(ex, $"DeleteRecords() failed");
         return(VisionMessage.FromException(ex));
     }
 }
 public VisionMessage SendDataToDeltekVision(string infoCenter, string data)
 {
     try
     {
         string _strData    = data.Replace("xmlns=\"\"", "");
         string _strMessage = service.SendDataToDeltekVision(infoCenter, GetConnectionInfo(), _strData);
         return(VisionMessage.FromXML(_strMessage));
     }
     catch (Exception ex)
     {
         logger.Error(ex, $"SendDataToDeltekVision() failed");
         return(VisionMessage.FromException(ex));
     }
 }
        /// <summary>
        /// executes a stored procedure in Vision DB
        /// </summary>
        /// <param name="sprocName">stored procedures must be named "DeltekStoredProc_XYZ", only the XYZ portion must be provided!</param>
        /// <param name="parameters">a key/value pair of parameters</param>
        /// <returns></returns>
        public VisionMessage ExecuteStoredProcedure(string sprocName, Dictionary <string, object> parameters = null)
        {
            try
            {
                var _parameterXML = ToParameterXML(parameters);
                var _retval       = service.ExecuteStoredProcedure(GetConnectionInfo(), sprocName, _parameterXML.ToString());

                return(VisionMessage.FromXML(_retval));
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"ExecuteStoredProcedure({sprocName}) failed");
                return(VisionMessage.FromException(ex));
            }
        }
        /// <summary>
        /// checks for valid database, username, password
        /// </summary>
        /// <param name="uri"></param>
        /// <param name="database"></param>
        /// <param name="username"></param>
        /// <param name="password"></param>
        /// <param name="useHTTPS"></param>
        /// <param name="httpsUser"></param>
        /// <param name="httpsPassword"></param>
        /// <param name="httpsDomain"></param>
        /// <returns></returns>
        public static bool CanAuthenticate(string uri, string database, string username, string password,
                                           bool useHTTPS = false, string httpsUser = "", string httpsPassword = "", string httpsDomain = "")
        {
            try
            {
                var _service = GetService(uri, useHTTPS, httpsUser, httpsPassword, httpsDomain);
                var _retval  = _service.ValidateLogin(HelperBase.GetVisionConnInfoXML(database, username, password));

                var _message = VisionMessage.FromXML(_retval);

                return(_message.ReturnCode == "ErrLoginVal" ? false : true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
        /// <summary>
        /// retrtieves pick list values
        /// </summary>
        /// <param name="pickList"></param>
        /// <param name="hierarchical"></param>
        /// <returns></returns>
        public XDocument GetPicklist(PickList pickList, int hierarchical = 0)
        {
            try
            {
                var _xmlresult = service.GetPickList(GetConnectionInfo(), GetPickListRequestXML(pickList, hierarchical));
                var _retval    = XDocument.Load(new System.IO.StringReader(_xmlresult));
                var _message   = VisionMessage.FromXML(_xmlresult);
                if (string.IsNullOrEmpty(_message.ReturnCode) == false && _message.ReturnCode != "1")
                {
                    throw new ApplicationException(_message.ReturnDesc);
                }

                return(_retval);
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"GetPicklist() for [{pickList.GetValueName()}] failed");
                return(new XDocument(new XElement("RECS")));
            }
        }
        /// <summary>
        /// posts one or more batches into vision
        /// </summary>
        /// <returns></returns>
        public VisionMessage PostTransaction(TransactionType transType, string batchList, int period)
        {
            try
            {
                string _message = service.PostTransaction(GetConnectionInfo(), transType.GetValueName(), batchList, period);

                //catch special case when the return value does not contain any xml
                if (_message.Contains("<") == false)
                {
                    return(new VisionMessage("1", "Posting Successful", _message));
                }
                else
                {
                    return(VisionMessage.FromXML(_message));
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"PostTransaction() failed for Transaction Type {transType.GetValueName()}");
                return(VisionMessage.FromException(ex));
            }
        }
        /// <summary>
        /// available transaction types
        /// </summary>



        public VisionMessage AddTransaction(TransactionType transType, XElement data)
        {
            try
            {
                string _connInfo = GetConnectionInfo();
                string _strData  = data.ToString().Replace("xmlns=\"\"", "");
                string _message  = "";

                switch (transType)
                {
                case TransactionType.AP:
                    _message = service.AddAPVouchersTransaction(_connInfo, _strData);
                    break;

                case TransactionType.CD:
                    _message = service.AddCashDisbTransaction(_connInfo, _strData);
                    break;

                case TransactionType.CR:
                    _message = service.AddCashReceiptsTransaction(_connInfo, _strData);
                    break;

                case TransactionType.CV:
                    _message = service.AddAPDisbursementsTransaction(_connInfo, _strData);
                    break;

                case TransactionType.ER:
                    _message = service.AddEmpRepaymentTransaction(_connInfo, _strData);
                    break;

                case TransactionType.EX:
                    _message = service.AddEmpExpenseTransaction(_connInfo, _strData);
                    break;

                case TransactionType.IN:
                    _message = service.AddInvoiceTransaction(_connInfo, _strData);
                    break;

                case TransactionType.JE:
                    _message = service.AddJournalEntryTransaction(_connInfo, _strData);
                    break;

                case TransactionType.LA:
                    _message = service.AddLaborAdjustTransaction(_connInfo, _strData);
                    break;

                case TransactionType.MI:
                    _message = service.AddMiscTransaction(_connInfo, _strData);
                    break;

                case TransactionType.PR:
                    _message = service.AddPrintsReproTransaction(_connInfo, _strData);
                    break;

                case TransactionType.TS:
                    _message = service.AddTimesheetTransaction(_connInfo, _strData);
                    break;

                case TransactionType.UN:
                    _message = service.AddUnitTransaction(_connInfo, _strData);
                    break;

                case TransactionType.UP:
                    _message = service.AddUnitByProjectTransaction(_connInfo, _strData);
                    break;

                default:
                    break;
                }

                return(VisionMessage.FromXML(_message));
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"AddTransaction() failed for Transaction Type {transType.GetValueName()}");
                return(VisionMessage.FromException(ex));
            }
        }