Example #1
0
        /// <summary>
        /// SearchByParam
        /// </summary>
        ///<param name="pEvent">Event</param>
        ///<param name="pEndDate">pEndDate</param>
        /// <returns>LogsList</returns>
        /// <Date>2010-02-26T10:05:27</Date>
        /// <Author>moviedo</Author>
        public override Events SearchByParam(Event pEvent, DateTime pEndDate)
        {
            Events wEventList = new Events();
            Event  wEvent;

            using (SqlConnection wCnn = new SqlConnection(GetCnnString()))
                using (SqlCommand wCmd = new SqlCommand())
                {
                    try
                    {
                        wCnn.Open();
                        wCmd.Connection  = wCnn;
                        wCmd.CommandType = CommandType.StoredProcedure;
                        wCmd.CommandText = "fwk_Logs_s";
                        SqlParameter wParam = null;


                        if (!string.IsNullOrEmpty(pEvent.Source))
                        {
                            wParam       = wCmd.Parameters.Add("Source", SqlDbType.NVarChar);
                            wParam.Value = string.Concat("%", pEvent.Source, "%");
                        }



                        if (pEvent.LogType != EventType.None)
                        {
                            wParam       = wCmd.Parameters.Add("LogType", SqlDbType.NVarChar);
                            wParam.Value = pEvent.LogType;
                        }
                        if (pEvent.LogDate != Fwk.HelperFunctions.DateFunctions.NullDateTime)
                        {
                            wParam       = wCmd.Parameters.Add("LogDateDesde", SqlDbType.DateTime);
                            wParam.Value = pEvent.LogDate;
                        }

                        if (pEndDate != Fwk.HelperFunctions.DateFunctions.NullDateTime)
                        {
                            wParam       = wCmd.Parameters.Add("LogDateHasta", SqlDbType.DateTime);
                            wParam.Value = pEndDate;
                        }

                        if (!string.IsNullOrEmpty(pEvent.Machine))
                        {
                            wParam       = wCmd.Parameters.Add("Machine", SqlDbType.NVarChar);
                            wParam.Value = string.Concat("%", pEvent.Machine, "%");
                        }

                        if (!string.IsNullOrEmpty(pEvent.User))
                        {
                            wParam       = wCmd.Parameters.Add("UserLoginName", SqlDbType.NVarChar);
                            wParam.Value = string.Concat("%", pEvent.User, "%");
                        }

                        if (!string.IsNullOrEmpty(pEvent.AppId))
                        {
                            wParam       = wCmd.Parameters.Add("AppId", SqlDbType.NVarChar);
                            wParam.Value = string.Concat("%", pEvent.AppId, "%");
                        }



                        using (IDataReader reader = wCmd.ExecuteReader())
                        {
                            while (reader.Read())
                            {
                                wEvent    = new Event();
                                wEvent.Id = new Guid(reader["Id"].ToString());

                                wEvent.Message.Text = TypeFunctions.ConvertBytesToTextString((Byte[])(reader["Message"]));
                                wEvent.Source       = reader["Source"].ToString();
                                wEvent.LogType      = (EventType)Enum.Parse(typeof(EventType), reader["LogType"].ToString());
                                wEvent.Machine      = reader["Machine"].ToString();
                                wEvent.LogDate      = Convert.ToDateTime(reader["LogDate"]);
                                wEvent.User         = reader["UserLoginName"].ToString();
                                wEvent.AppId        = reader["AppId"].ToString();
                                wEventList.Add(wEvent);
                            }
                        }

                        return(wEventList);
                    }
                    catch (Exception ex)
                    {
                        TechnicalException te = new TechnicalException("Error de Fwk.Logging", ex);
                        te.ErrorId = "9004";
                        Fwk.Exceptions.ExceptionHelper.SetTechnicalException <DatabaseTarget>(te);
                        throw te;
                    }
                }
        }