示例#1
0
 // Methods
 public static bool ObtenerMensaje(MessageInfo message)
 {
     Func<XElement, bool> predicate = null;
     bool flag;
     XDocument document = null;
     try
     {
         document = XDocument.Load(MessageManagerSettings.GetInstance().PathDataMessage);
         if (predicate == null)
         {
             predicate = p => p.Element("MessageID").Value == message.MessageID.ToString();
         }
         MessageInfo mensaje2 = (from p in document.Elements("DataMessage").Elements<XElement>("MessageInfo").Where<XElement>(predicate) select new MessageInfo { MessageID = Convert.ToInt32(p.Element("MessageID").Value), MessageDescription = p.Element("MessageDescription").Value, MessageLog = p.Element("MessageLog").Value, Success = Convert.ToBoolean(p.Element("Success").Value) }).DefaultIfEmpty<MessageInfo>((from q in document.Elements("DataMessage").Elements<XElement>("MessageInfo")
                                                                                                                                                                                                                                                                                                                                                                                                          where q.Element("MessageID").Value == "0"
                                                                                                                                                                                                                                                                                                                                                                                                          select new MessageInfo { MessageID = Convert.ToInt32(q.Element("MessageID").Value), MessageDescription = q.Element("MessageDescription").Value, MessageLog = q.Element("MessageLog").Value, Success = Convert.ToBoolean(q.Element("Success").Value) }).FirstOrDefault<MessageInfo>()).FirstOrDefault<MessageInfo>();
         message.MessageID = mensaje2.MessageID;
         message.MessageDescription = mensaje2.MessageDescription;
         message.MessageLog = mensaje2.MessageLog;
         message.Success = mensaje2.Success;
         flag = true;
     }
     catch (Exception exception)
     {
         message.MessageID = -10001;
         message.MessageDescription = exception.Message;
         message.MessageLog = (exception.InnerException != null) ? exception.InnerException.ToString() : exception.Message;
         message.Success = false;
         flag = false;
     }
     finally
     {
         document = null;
     }
     return flag;
 }
示例#2
0
 public static MessageInfo ObtenerMensaje(int MessageID)
 {
     MessageInfo message = new MessageInfo
     {
         MessageID = MessageID
     };
     ObtenerMensaje(message);
     return message;
 }
示例#3
0
        public string addAgentFacade(AgentModel agentModel)
        {
            responseOperation = new MessageInfo();
            try
            {
                //Add arguments to  list
                List<keyValue> lstParams = new List<keyValue>();
                //lstParams.Add(new keyValue("agent", agent)); lstParams.Add(new keyValue("idUser", idUser));
                string method = string.Format("{0}.{1}", MethodBase.GetCurrentMethod().DeclaringType.FullName, MethodBase.GetCurrentMethod().Name);

                ObjectParameter prmOutIdAgent = new ObjectParameter("prmOutIdAgent", typeof(int));
                ObjectParameter prmOutResult = new ObjectParameter("prmOutResult", typeof(int));

                objController.addAgentController(agentModel, ref prmOutIdAgent,    ref prmOutResult);

                int op = Int32.Parse(prmOutResult.Value.ToString());
                switch (op)
                {

                    case 0:
                        responseOperation.messageID = 100;
                        break;

                    case -1:
                        responseOperation.messageID = 101;
                        break;
                    case -2:
                        responseOperation.messageID = 102;
                        break;
                    case -3:
                        responseOperation.messageID = 103;
                        break;
                }

                DataMessage.ObtenerMensaje(responseOperation);
                responseOperation.MessageLog = string.Format(" It was created on record [Agent] with ID :", Int32.Parse(prmOutIdAgent.Value.ToString()));
                Log4NetHelper.addLog(Log4NetHelper.levelLog.INFO,  string.Format(" It was created on record [Agent] with ID :", prmOutIdAgent.ToString()));
                return JavaScriptSerializerHelper.GetString(new object[] { responseOperation, null });
            }
            catch (Exception exc)
            {
                responseOperation.messageID = 3;
                responseOperation.MessageLog = exc.ToString();
                DataMessage.ObtenerMensaje(responseOperation);
                Log4NetHelper.addLog(Log4NetHelper.levelLog.ERROR, "An exception is presented  .", exc);
                return JavaScriptSerializerHelper.GetString(new object[] { responseOperation, null });
            }
        }
示例#4
0
        public string addBookFacade(BookModel BookModel)
        {
            responseOperation = new MessageInfo();
            try
            {
                string method = string.Format("{0}.{1}", MethodBase.GetCurrentMethod().DeclaringType.FullName, MethodBase.GetCurrentMethod().Name);
                int res = 0;

                res = objController.addBookController(BookModel);

                DataMessage.ObtenerMensaje(responseOperation);
                responseOperation.MessageLog = " It was created on record [Book]";
                Log4NetHelper.addLog(Log4NetHelper.levelLog.INFO, string.Format(" It was created on record [Book] and return:", res));
                return JavaScriptSerializerHelper.GetString(new object[] { responseOperation, null });
            }
            catch (Exception exc)
            {
                responseOperation.messageID = 3;
                responseOperation.MessageLog = exc.ToString();
                DataMessage.ObtenerMensaje(responseOperation);
                Log4NetHelper.addLog(Log4NetHelper.levelLog.ERROR, "An exception is presented  .", exc);
                return JavaScriptSerializerHelper.GetString(new object[] { responseOperation, null });
            }
        }
示例#5
0
        public string updateAgentFacade(AgentModel agentModel)
        {
            responseOperation = new MessageInfo();
            try
            {

                  objController.updateAgentController(agentModel);

                responseOperation.messageID = 1;
                DataMessage.ObtenerMensaje(responseOperation);
                responseOperation.MessageLog = string.Format(" It was updated on record [Agent] with ID :", agentModel.IdAgent.ToString());
                Log4NetHelper.addLog(Log4NetHelper.levelLog.INFO, string.Format(" It was updated on record [Agent] with ID :", agentModel.IdAgent.ToString()));
                return JavaScriptSerializerHelper.GetString(new object[] { responseOperation, null });
            }
            catch (Exception exc)
            {
                responseOperation.messageID = 3;
                responseOperation.MessageLog = exc.ToString();
                DataMessage.ObtenerMensaje(responseOperation);
                Log4NetHelper.addLog(Log4NetHelper.levelLog.ERROR, "An exception is presented  .", exc);
                return JavaScriptSerializerHelper.GetString(new object[] { responseOperation, null });
            }
        }
示例#6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="idAgent"></param>
        /// <param name="idUser"></param>
        /// <returns></returns>
        public string deleteAgentFacade(string pridAgent, string pridUser)
        {
            int res;

            int idAgent;
            short idUser;

            bool residAgent = int.TryParse(pridAgent, out idAgent);
            bool resUser = short.TryParse(pridUser, out idUser);

            responseOperation = new MessageInfo();
            try
            {

                res = objController.deleteAgentController(idAgent, idUser);

                responseOperation.messageID = 1;
                DataMessage.ObtenerMensaje(responseOperation);
                responseOperation.MessageLog = string.Format(" It was delete on record [Agent] :");
                responseOperation.MessageDescription = string.Format("Result execution SP Agent_Delete ({0},{1} = {2})", idAgent, idUser, res);
                Log4NetHelper.addLog(Log4NetHelper.levelLog.INFO, string.Format("Result execution SP Agent_Delete ({0},{1} = {2})", idAgent, idUser, res));
                return JavaScriptSerializerHelper.GetString(new object[] { responseOperation, res });
            }
            catch (Exception exc)
            {
                responseOperation.messageID = 3;
                responseOperation.MessageLog = exc.ToString();
                DataMessage.ObtenerMensaje(responseOperation);
                Log4NetHelper.addLog(Log4NetHelper.levelLog.ERROR, "An exception is presented  .", exc);
                return JavaScriptSerializerHelper.GetString(new object[] { responseOperation, null });
            }
        }
示例#7
0
        /// <summary>
        /// Method to call the corresponding method of the controller class , as well as write to the execution log
        /// </summary>
        /// <param name="objResultController"></param>
        /// <param name="listParams"></param>
        /// <param name="method"></param>
        /// <returns></returns>
        public string controllerResponse(object objResultController, List<keyValue> listParams, string method)
        {
            string result = string.Empty;
            try
            {
                StringBuilder sbParams = new StringBuilder();
                responseOperation = new MessageInfo();

                foreach (var item in listParams)
                {
                    sbParams.AppendFormat(" Method :[{0}] - Params {1} = [{2}] \t ", method, item.key, item.value.ToString());

                }

                //Log parameters the method
                Log4NetHelper.addLog(Log4NetHelper.levelLog.DEBUG, sbParams.ToString());

                if (objResultController == null)
                {
                    Log4NetHelper.addLog(Log4NetHelper.levelLog.INFO, "result not found for request.");
                }

                else
                {
                    responseOperation.messageID = 1;
                    object obj = new object[] { responseOperation, objResultController };
                    DataMessage.ObtenerMensaje(responseOperation);
                    result = JavaScriptSerializerHelper.GetString(obj);
                }
            }

            catch (Exception ex)
            {
                responseOperation.messageID = 3;
                Log4NetHelper.addLog(Log4NetHelper.levelLog.ERROR, string.Format(" Method [{0}]. An exception is presented .", method), ex);
            }

            return result;
        }