Ejemplo n.º 1
0
        public static string GetConnectionString(SqlLogInfo sqlLogInfo)
        {
            string connectionString = string.Empty;

            if (sqlLogInfo.FetchFromConfig)
            {
                sqlLogInfo.ConnectionStringKey.Trim().CheckEmpty(ErrorCode.CDX_NO_VALUE, Messages.CONNECTION_STRING_KEY_MISSING);

                try
                { connectionString = ConfigurationManager.AppSettings[sqlLogInfo.ConnectionStringKey].ToString(); }
                catch (Exception ex)
                { throw ErrorGenerator.Generate(ErrorCode.CDX_NO_VALUE, ex.Message); }

                if (connectionString == null)
                {
                    throw ErrorGenerator.Generate(ErrorCode.CDX_NO_VALUE, Messages.CONNECTION_STRING_READ_ERROR);
                }
            }
            else
            {
                // GENERATE CONNECTIONSTRING
                connectionString = sqlLogInfo.GetConnectionString();
            }
            return(connectionString);
        }
Ejemplo n.º 2
0
        public static void ValidateSQLAuthentication(SqlLogInfo sqlLogInfo)
        {
            sqlLogInfo.ServerName.Trim().CheckEmpty(ErrorCode.CDX_NO_VALUE, Messages.SQL_SERVER_NAME_MISSING);

            sqlLogInfo.UserName.Trim().CheckEmpty(ErrorCode.CDX_NO_VALUE, Messages.SQL_USER_NAME_MISSING);

            sqlLogInfo.Password.Trim().CheckEmpty(ErrorCode.CDX_NO_VALUE, Messages.SQL_PWD_MISSING);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// WRITE LOG TO DATABASE
        /// </summary>
        /// <param name="logInfo">Database and message definition</param>
        /// <returns></returns>
        public ILogMessage Write(T logInfo)
        {
            try
            {
                if (logInfo == null)
                {
                    throw ErrorGenerator.Generate(ErrorCode.CDX_NO_VALUE, Messages.NULL_LOG_INFO);
                }

                if (typeof(T) != typeof(SqlLogInfo))
                {
                    throw ErrorGenerator.Generate(ErrorCode.CDX_SQL_CAST_FAIL);
                }

                SqlLogInfo sqlLogInfo = logInfo as SqlLogInfo;

                sqlLogInfo.Database.Trim().CheckEmpty(ErrorCode.CDX_NO_VALUE, Messages.SQL_DATABASE_NAME_MISSING);

                if (!sqlLogInfo.WindowsAuthentication)
                {
                    MsSQL.SQLUtil.ValidateSQLAuthentication(sqlLogInfo);
                }

                // [ CONFIGURE CONNECTION STRING ]
                string connectionString = MsSQL.SQLUtil.GetConnectionString(sqlLogInfo);


                if (sqlLogInfo.CallType == SQLCallType.Query)
                {
                    sqlLogInfo.Query.CheckEmpty(ErrorCode.CDX_NO_VALUE, Messages.EMPTY_QUERY);
                }
                else
                {
                    if (sqlLogInfo.StoredProcedureInfo == null)
                    {
                        throw ErrorGenerator.Generate(ErrorCode.CDX_NO_VALUE, Messages.NULL_SP_INFO);
                    }

                    sqlLogInfo.StoredProcedureInfo.StoredProcedureName.CheckEmpty(ErrorCode.CDX_NO_VALUE, Messages.SQL_SP_NAME_MISSING);

                    if (sqlLogInfo.StoredProcedureInfo.LogParams == null || sqlLogInfo.StoredProcedureInfo.LogParams.Count <= 0)
                    {
                        MsSQL.MsSQLHandler handler = new MsSQL.MsSQLHandler(connectionString);
                    }
                }


                // WRITE LOG TO SQL

                return(new LogMessageCode()
                {
                    Status = StatusType.SUCCESS, Message = Messages.LOG_SUCCESSFULL
                });
            }
            catch (Exception ex)
            {
                return(new LogMessageCode()
                {
                    Status = StatusType.EXCEPTION, Message = ex.Message
                });
            }
        }