Beispiel #1
0
 /// <summary>
 /// appends a message to an existing message if the return code of the added message is not "1" success
 /// </summary>
 /// <param name="message"></param>
 public void AppendToMessage(VisionMessage message)
 {
     if (string.IsNullOrEmpty(ReturnCode))
     {
         ReturnCode   = message.ReturnCode;
         ReturnDesc   = message.ReturnDesc;
         Detail       = message.Detail;
         ReturnedData = message.ReturnedData;
         Errors       = message.Errors;
     }
     else
     {
         if (message.ReturnCode != "1")
         {
             ReturnCode = message.ReturnCode;
             ReturnDesc = $"{ReturnDesc}, {message.ReturnDesc}";
             Detail     = $"{Detail}{Environment.NewLine}{message.Detail}";
             ReturnedData.Add(message.ReturnedData.Root);
             foreach (var itm in message.Errors)
             {
                 Errors.Add(itm.Key, itm.Value);
             }
         }
     }
 }
Beispiel #2
0
 public void AddError(string message, VisionMessage info)
 {
     System.Text.StringBuilder msg = new System.Text.StringBuilder();
     msg.AppendLine(message);
     msg.AppendFormat("Vision Message Error: Return Code = {0}, Description = {1}, Detail = {2}, Errors = {3}", info.ReturnCode, info.ReturnDesc, info.ReturnedData, info.GetErrors());
     _messages.Add(msg.ToString());
     _isError = true;
 }
        /// <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));
     }
 }
Beispiel #7
0
        /// <summary>
        /// produces a VisionMessage from  XML string
        /// </summary>
        /// <param name="xml"></param>
        /// <returns></returns>
        public static VisionMessage FromXML(string xml)
        {
            XDocument     _doc;
            VisionMessage _retval = new VisionMessage();

            try
            {
                _doc = XDocument.Load(new System.IO.StringReader(xml));
                return(FromXML(_doc));
            }
            catch (Exception)
            {
                return(_retval);
            }
        }
        /// <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));
            }
        }
Beispiel #9
0
        public static VisionMessage FromException(Exception ex)
        {
            VisionMessage _retval = new VisionMessage();

            _retval.ReturnCode = "-1";
            _retval.ReturnDesc = ex.Message;

            Exception inner = ex;

            while (inner != null)
            {
                _retval.Detail = $"{_retval.Detail}{Environment.NewLine}{inner.Message}";
                inner          = ex.InnerException;
            }

            return(_retval);
        }
        /// <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>
        /// get records by query
        /// </summary>
        /// <param name="infoCenter"></param>
        /// <param name="query"></param>
        /// <param name="recordDetail"></param>
        /// <param name="rowAccess"></param>
        /// <param name="chunkSize"></param>
        /// <param name="tableInfo"></param>
        /// <returns></returns>
        public VisionMessage GetRecordsByQuery(string infoCenter,
                                               string query,
                                               RecordDetail recordDetail = RecordDetail.Empty,
                                               bool rowAccess            = false,
                                               int chunkSize             = 100,
                                               XElement tableInfo        = null)
        {
            try
            {
                VisionMessage _retval    = new VisionMessage();
                int           _nextChunk = 1;
                bool          _lastChunk = false;
                string        _sessionId = "";
                string        _connInfo  = GetConnectionInfo();
                XElement      _xQuery    = new XElement("Queries", new XElement("Query", query, new XAttribute("ID", 1)));

                do
                {
                    string _xmlretval = service.GetRecordsByQuery(
                        _connInfo,
                        GetInfoCenterXML(infoCenter, rowAccess, _nextChunk, chunkSize, tableInfo),
                        _xQuery.ToString(),
                        recordDetail.GetValueName()
                        );

                    //read loop moved into separate method...
                    _lastChunk = ReadResult(ref _sessionId, _xmlretval, ref _retval);
                    if (string.IsNullOrEmpty(_sessionId) == false)
                    {
                        _connInfo = GetVisionConnInfoXML(database, username, password, _sessionId);
                    }
                    _nextChunk += 1;
                } while (_lastChunk == false);

                return(_retval);
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"GetRecordsByQuery() with query [{query}] call failed");
                return(VisionMessage.FromException(ex));
            }
        }
        /// <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>
        /// retrieves record by UID
        /// </summary>
        /// <param name="udicName"></param>
        /// <param name="id"></param>
        /// <param name="recordDetail"></param>
        /// <returns></returns>
        public VisionMessage GetUDICRecordsByKey(string udicName, string id, RecordDetail recordDetail = RecordDetail.Empty)
        {
            try
            {
                VisionMessage _retval    = new VisionMessage();
                int           _nextChunk = 1;
                bool          _lastChunk = false;
                string        _sessionId = "";
                string        _connInfo  = GetConnectionInfo();

                do
                {
                    string _xmlretval = service.GetUDICByKey(
                        _connInfo,
                        udicName,
                        id,
                        recordDetail.GetValueName()
                        );

                    //read loop moved into separate method...
                    _lastChunk = ReadResult(ref _sessionId, _xmlretval, ref _retval);
                    if (string.IsNullOrEmpty(_sessionId) == false)
                    {
                        _connInfo = GetVisionConnInfoXML(database, username, password, _sessionId);
                    }
                    _nextChunk += 1;
                } while (_lastChunk == false);

                return(_retval);
            }
            catch (Exception ex)
            {
                logger.Error(ex, $"GetUDICRecordsByKey() for {udicName} with key [{id}] call failed");
                return(VisionMessage.FromException(ex));
            }
        }
Beispiel #15
0
        /// <summary>
        /// produces a VisionMessage from xml document
        /// </summary>
        /// <param name="xmlDoc"></param>
        /// <returns></returns>
        public static VisionMessage FromXML(XDocument xmlDoc)
        {
            VisionMessage _retval = new VisionMessage();

            if (xmlDoc.Element("DLTKVisionMessage") != null)
            {
                _retval = new VisionMessage(
                    xmlDoc.Element("DLTKVisionMessage").TryGetElementValue("ReturnCode", ""),
                    xmlDoc.Element("DLTKVisionMessage").TryGetElementValue("ReturnDesc", ""),
                    xmlDoc.Element("DLTKVisionMessage").TryGetElementValue("Detail", "")
                    );

                //MD-2017-01-17: change in returned message. Can now have multiple <ReturnSelect> elements
                //and even returns code 1 if there are errors!!!
                if (xmlDoc.Element("DLTKVisionMessage").ElementExists("ReturnSelect"))
                {
                    _retval.ReturnedData = new XDocument();

                    foreach (var item in xmlDoc.Element("DLTKVisionMessage").Elements("ReturnSelect"))
                    {
                        if (item.ElementExists("MULTIRECS"))
                        {
                            _retval.ReturnedData.Add(item.Element("MULTIRECS").Elements("RECS"));
                        }
                        else if (item.ElementExists("RECS"))
                        {
                            _retval.ReturnedData.Add(item.Elements("RECS"));
                        }
                    }

                    //check if the returned data xml contains error items
                    if (_retval.ReturnedData.ElementExists("RECS"))
                    {
                        foreach (var item in _retval.ReturnedData.Elements("RECS"))
                        {
                            if (item.ElementExists("Error"))
                            {
                                foreach (var err in item.Elements("Error"))
                                {
                                    _retval.Errors.Add(err.TryGetElementValue("ErrorCode"),
                                                       err.TryGetElementValue("Message"));
                                }
                            }
                        }
                    }

                    if (_retval.Errors.Count > 0)
                    {
                        _retval.ReturnCode = "-1";
                        _retval.ReturnDesc = _retval.ReturnedData.ToString();
                    }
                }
            }

            //check if it's a value returned from executestoredproc
            if (xmlDoc.Root.Name == "NewDataSet")
            {
                _retval.ReturnCode   = "1";
                _retval.ReturnDesc   = "stored procedure returned data";
                _retval.ReturnedData = new XDocument(xmlDoc);
            }

            return(_retval);
        }
        /// <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));
            }
        }