Exemplo n.º 1
0
        public async Task DeleteAsync(int id)
        {
            // If error is not exist in list then exit
            if (!ErrorIds.ContainsKey(id))
            {
                return;
            }

            using (var sqlConn = new SqlCeConnection(ConnectionString))
                using (var cmd = sqlConn.CreateCommand())
                {
                    try
                    {
                        cmd.CommandText = string.Format("Delete From ErrorLog Where ErrorId = {0}", id);

                        await sqlConn.OpenAsync();

                        await cmd.ExecuteNonQueryAsync();

                        ErrorIds.Remove(id);
                    }
                    finally
                    {
                        sqlConn.Close();
                    }
                }
        }
Exemplo n.º 2
0
        public async Task <bool> InsertOrUpdateAsync(Error error)
        {
            if (ErrorIds.ContainsKey(error.Id))
            {
                await UpdateAsync(error);

                return(false); // In update state not necessary to check cache size
            }

            await InsertAsync(error);

            return(true); // New error added to database, so need to check cache size
        }
Exemplo n.º 3
0
        public async Task UpdateAsync(Error error)
        {
            // If error is not exist in list or error state is now at unhandled exception state then exit
            if (!ErrorIds.ContainsKey(error.Id) || !ErrorIds[error.Id])
            {
                return;
            }

            using (var sqlConn = new SqlCeConnection(ConnectionString))
                using (var cmd = sqlConn.CreateCommand())
                {
                    cmd.CommandText =
                        string.Format("UPDATE [ErrorLog] SET [DuplicateNo] = [DuplicateNo] + 1 {0} WHERE ErrorId = @id",
                                      error.IsHandled ? "" : ", [IsHandled] = @isHandled, [StackTrace] = @stackTrace");

                    //
                    // Add parameters to command, which will be passed to the stored procedure
                    cmd.Parameters.AddWithValue("@id", error.Id);
                    if (!error.IsHandled) // Just in Unhandled Exceptions
                    {
                        cmd.Parameters.AddWithValue("@isHandled", error.IsHandled);
                        cmd.Parameters.AddWithValue("@stackTrace", SubLimitString(error.StackTrace));
                    }

                    try
                    {
                        await sqlConn.OpenAsync();

                        await cmd.ExecuteNonQueryAsync();

                        ErrorIds[error.Id] = error.IsHandled;
                    }
                    finally
                    {
                        sqlConn.Close();
                    }
                }
        }