LogError() public static method

Log an exception
public static LogError ( Exception ex ) : void
ex System.Exception the exception
return void
Beispiel #1
0
        /// <summary>
        /// Gets a single reference data entry by ID
        /// </summary>
        /// <typeparam name="T">The system type of the data</typeparam>
        /// <param name="id">The "ID" of the reference data entry</param>
        /// <returns>One data entry, if it matches</returns>
        public static T GetOne <T>(long id) where T : IReferenceData
        {
            IReferenceData returnValue = default(T);
            var            parms       = new Dictionary <string, object>();

            parms.Add("id", id);

            try
            {
                var baseType = GetDataTableName(typeof(T));
                var sql      = string.Format("select * from [dbo].[{0}] where ID = @id", baseType.Name);
                var ds       = SqlWrapper.RunDataset(sql, CommandType.Text, parms);

                if (ds.Rows != null)
                {
                    foreach (DataRow dr in ds.Rows)
                    {
                        returnValue = Activator.CreateInstance(baseType) as IReferenceData;
                        returnValue.Fill(dr);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
            }

            return((T)returnValue);
        }
Beispiel #2
0
        /// <summary>
        /// Get all of the reference data in the table
        /// </summary>
        /// <typeparam name="T">The system type of the data</typeparam>
        /// <returns>A list of all of the data for that type</returns>
        public static IEnumerable <T> GetAll <T>() where T : IReferenceData
        {
            var returnList = new List <T>();

            try
            {
                var baseType = GetDataTableName(typeof(T));
                var sql      = string.Format("select * from [dbo].[{0}]", baseType.Name);
                var ds       = SqlWrapper.RunDataset(sql, CommandType.Text);

                if (ds.Rows != null)
                {
                    foreach (DataRow dr in ds.Rows)
                    {
                        var newValue = Activator.CreateInstance(baseType) as IReferenceData;
                        newValue.Fill(dr);
                        returnList.Add((T)newValue);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
            }

            return(returnList);
        }
Beispiel #3
0
        /// <summary>
        /// Get a single entry from a table that matches a key value
        /// </summary>
        /// <typeparam name="T">The system type of the data</typeparam>
        /// <typeparam name="sharedKeyName">Thet db column name to check against</typeparam>
        /// <typeparam name="sharedKeyValue">The value to match (exact match)</typeparam>
        /// <returns>The one data that matches of the data returned</returns>
        public static T GetOneBySharedKey <T>(string sharedKeyName, string sharedKeyValue) where T : IData
        {
            IData returnValue = default(T);
            var   parms       = new Dictionary <string, object>();

            parms.Add("value", sharedKeyValue);

            try
            {
                var baseType = GetDataTableName(typeof(T));
                var sql      = string.Format("select * from [dbo].[{0}] where {1} = @value", baseType.Name, sharedKeyName);
                var ds       = SqlWrapper.RunDataset(sql, CommandType.Text, parms);

                if (ds.Rows != null)
                {
                    if (ds.Rows.Count > 1)
                    {
                        throw new InvalidOperationException("More than one row returned for shared key.");
                    }

                    foreach (DataRow dr in ds.Rows)
                    {
                        returnValue = Activator.CreateInstance(baseType) as IData;
                        returnValue.Fill(dr);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
            }

            return((T)returnValue);
        }
Beispiel #4
0
        /// <summary>
        /// Get all of the data in a table that matches a key value
        /// </summary>
        /// <typeparam name="T">The system type of the data</typeparam>
        /// <typeparam name="sharedKeyName">Thet db column name to check against</typeparam>
        /// <typeparam name="sharedKeyValue">The value to match (exact match)</typeparam>
        /// <returns>A list of all of the data returned</returns>
        public static IEnumerable <T> GetAllBySharedKey <T>(string sharedKeyName, string sharedKeyValue) where T : IData
        {
            var returnList = new List <T>();
            var parms      = new Dictionary <string, object>();

            parms.Add("value", sharedKeyValue);

            try
            {
                var baseType = GetDataTableName(typeof(T));
                var sql      = string.Format("select * from [dbo].[{0}] where {1} = @value", baseType.Name, sharedKeyName);

                var ds = SqlWrapper.RunDataset(sql, CommandType.Text, parms);

                if (ds.Rows != null)
                {
                    foreach (DataRow dr in ds.Rows)
                    {
                        var newValue = Activator.CreateInstance(baseType) as IData;
                        newValue.Fill(dr);
                        returnList.Add((T)newValue);
                    }
                }
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
            }

            return(returnList);
        }
Beispiel #5
0
        /// <summary>
        /// Gets one entity from the cache by its key
        /// </summary>
        /// <typeparam name="T">the type of the entity</typeparam>
        /// <param name="key">the key it was cached with</param>
        /// <returns>the entity requested</returns>
        public static T Get <T>(LiveCacheKey key) where T : IEntity
        {
            try
            {
                return((T)globalCache[key.KeyHash()]);
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
            }

            return(default(T));
        }
Beispiel #6
0
        /// <summary>
        /// Gets one entity from the cache by its ID, only works for Singleton spawners
        /// </summary>
        /// <typeparam name="T">the underlying type of the entity</typeparam>
        /// <param name="id">the id</param>
        /// <param name="mainType">the primary type of the entity</param>
        /// <returns>the entity requested</returns>
        public static T Get <T>(long id, Type mainType) where T : IEntity
        {
            try
            {
                var allTheStuff = GetAll <T>(mainType);

                if (allTheStuff.Any(p => ((IEntity)p).DataTemplate.ID.Equals(id)))
                {
                    return(allTheStuff.First(p => ((IEntity)p).DataTemplate.ID.Equals(id)));
                }
            }
            catch (Exception ex)
            {
                LoggingUtility.LogError(ex);
            }

            return(default(T));
        }
Beispiel #7
0
        /// <summary>
        /// Verifies the existence of or creates a new directory, also creates the base directory if necessary
        /// </summary>
        /// <param name="directoryName">the directory to create</param>
        /// <param name="createIfMissing">creates the directory if it doesn't already exist</param>
        /// <returns>success</returns>
        private static bool VerifyDirectory(string directoryName)
        {
            string mappedName = directoryName;

            if (!mappedName.EndsWith("/"))
            {
                mappedName += "/";
            }

            try
            {
                return(Directory.Exists(HostingEnvironment.MapPath(mappedName)));
            }
            catch (Exception ex)
            {
                //Log any filesystem errors
                LoggingUtility.LogError(ex, false);
            }

            return(false);
        }