public override Task <InterceptionResult <int> > NonQueryExecutingAsync(DbCommand command, CommandEventData eventData, InterceptionResult <int> result, CancellationToken cancellationToken = default)
    {
        var pattern = @"^CREATE DATABASE (\[.*\])(.*)$";

        if (Regex.IsMatch(command.CommandText, pattern))
        {
            command.CommandText = Regex.Replace(command.CommandText, pattern, $"CREATE DATABASE $1 COLLATE {_collation} $2");
        }

        return(Task.FromResult(result));
    }
 public override InterceptionResult <object> ScalarExecuting(DbCommand command, CommandEventData eventData, InterceptionResult <object> result)
 {
     return(base.ScalarExecuting(command, eventData, result));
 }
 public InterceptionResult <DbDataReader> ReaderExecuting(DbCommand command, CommandEventData eventData,
                                                          InterceptionResult <DbDataReader> result)
 {
     TrackEvent(nameof(ReaderExecuting), eventData.Connection, command, eventData.ConnectionId);
     return(result);
 }
 public InterceptionResult <int> NonQueryExecuting(DbCommand command, CommandEventData eventData,
                                                   InterceptionResult <int> result)
 {
     TrackEvent(nameof(NonQueryExecuting), eventData.Connection, command, eventData.ConnectionId);
     return(result);
 }
 public override InterceptionResult <object> ScalarExecuting(DbCommand command, CommandEventData eventData, InterceptionResult <object> result)
 {
     command.CommandText = TableAliasRegex.Replace(
         command.CommandText,
         "${tableAlias} WITH (NOLOCK)"
         );
     return(base.ScalarExecuting(command, eventData, result));
 }
Exemple #6
0
 public override InterceptionResult <DbDataReader> ReaderExecuting(DbCommand command, CommandEventData eventData, InterceptionResult <DbDataReader> result)
 {
     //查询总数时替换掉*
     command.CommandText = command.CommandText.Replace("COUNT(*)", "COUNT(1)");
     return(base.ReaderExecuting(command, eventData, result));
 }
Exemple #7
0
        public override InterceptionResult <int> NonQueryExecuting(DbCommand command, CommandEventData eventData, InterceptionResult <int> result)
        {
            if (command?.CommandText != null)
            {
                lock (AboutToBeExecutedCommands)
                {
                    AboutToBeExecutedCommands.Add(BuildCommandInformation(command));
                }
            }

            return(base.NonQueryExecuting(command, eventData, result));
        }
 public override InterceptionResult <DbDataReader> ReaderExecuting(DbCommand command, CommandEventData eventData, InterceptionResult <DbDataReader> result)
 {
     command.CommandText = ReplaceTenantId(command.CommandText);
     return(base.ReaderExecuting(command, eventData, result));
 }
Exemple #9
0
 public Task <InterceptionResult <int> > NonQueryExecutingAsync(DbCommand command, CommandEventData eventData,
                                                                InterceptionResult <int> result,
                                                                CancellationToken cancellationToken = new CancellationToken())
 {
     CommandExecuting(command);
     return(Task.FromResult(result));
 }
Exemple #10
0
        public override DbCommand CommandInitialized(CommandEventData eventData, DbCommand command)
        {
            ((dynamic)command).BindByName = false;

            return(command);
        }
Exemple #11
0
 public InterceptionResult <int> NonQueryExecuting(DbCommand command, CommandEventData eventData, InterceptionResult <int> result)
 {
     CommandExecuting(command);
     return(result);
 }
Exemple #12
0
 public InterceptionResult <object> ScalarExecuting(DbCommand command, CommandEventData eventData, InterceptionResult <object> result)
 {
     CommandExecuting(command);
     return(result);
 }
 private void LockInput( CommandEventData data )
 {
     enabled = !data.IsLockInput;
 }
Exemple #14
0
 public override ValueTask <InterceptionResult <int> > NonQueryExecutingAsync(DbCommand command, CommandEventData eventData, InterceptionResult <int> result, CancellationToken cancellationToken = default)
 {
     return(base.NonQueryExecutingAsync(command, eventData, result, cancellationToken));
 }
Exemple #15
0
        public override ValueTask <InterceptionResult <int> > NonQueryExecutingAsync(DbCommand command, CommandEventData eventData, InterceptionResult <int> result, CancellationToken cancellationToken = default)
        {
            if (command?.CommandText != null)
            {
                lock (AboutToBeExecutedCommands)
                {
                    AboutToBeExecutedCommands.Add(BuildCommandInformation(command));
                }
            }

            return(base.NonQueryExecutingAsync(command, eventData, result, cancellationToken));
        }
        private CommandEventData Execute( GameObject targetObject )
        {
            if( targetObject == null )	return new CommandEventData();

            CommandManager.CommandEventData data = new CommandEventData();
            targetObject.SendMessage( CommandEventMessage, data );
            Debug.Log( targetObject.name, targetObject );
            return data;
        }
Exemple #17
0
 public override InterceptionResult <DbDataReader> ReaderExecuting(
     DbCommand command, CommandEventData eventData, InterceptionResult <DbDataReader> result)
 => throw new InvalidOperationException("Sync interception not implemented; use async queries.");
 public override InterceptionResult <DbDataReader> ReaderExecuting(DbCommand command, CommandEventData eventData, InterceptionResult <DbDataReader> result)
 {
     command.CommandText = TableAliasRegex.Replace(
         command.CommandText,
         "${tableAlias} WITH (NOLOCK)"
         );
     return(result);
 }
Exemple #19
0
        private void HandleCommand(CommandEventData eventData)
        {
            if (eventData?.Command == null)
            {
                return;
            }

            try
            {
                var messageBuilder = new StringBuilder(1024);
                var command        = eventData.Command;

                string caption, shortenedQuery;
                if (command.CommandType == CommandType.StoredProcedure)
                {
                    shortenedQuery = command.CommandText;
                    caption        = string.Format("Executing Procedure '{0}'", shortenedQuery);
                }
                else
                {
                    //we want to make a more compact version of the SQL Query for the caption...
                    var queryLines = command.CommandText.Split(new[] { '\r', '\n' });

                    //now rip out any leading/trailing white space...
                    var cleanedUpLines = new List <string>(queryLines.Length);
                    foreach (var queryLine in queryLines)
                    {
                        if (string.IsNullOrWhiteSpace(queryLine) == false)
                        {
                            string minimizedLine = queryLine.Trim();

                            if (string.IsNullOrWhiteSpace(minimizedLine) == false)
                            {
                                cleanedUpLines.Add(minimizedLine);
                            }
                        }
                    }

                    //and rejoin to make the shortened command.
                    shortenedQuery = string.Join(" ", cleanedUpLines);
                    if (shortenedQuery.Length > 512)
                    {
                        shortenedQuery = shortenedQuery.Substring(0, 512) + "(...)";
                        messageBuilder.AppendFormat("Full Query:\r\n\r\n{0}\r\n\r\n", command.CommandText);
                    }
                    caption = string.Format("Executing Sql: '{0}'", shortenedQuery);
                }

                string paramString = null;
                if (eventData.LogParameterValues && (command.Parameters.Count > 0))
                {
                    messageBuilder.AppendLine("Parameters:");

                    var paramStringBuilder = new StringBuilder(1024);
                    foreach (DbParameter parameter in command.Parameters)
                    {
                        string value = parameter.Value.FormatDbValue();
                        messageBuilder.AppendFormat("    {0}: {1}\r\n", parameter.ParameterName, value);
                        paramStringBuilder.AppendFormat("{0}: {1}, ", parameter.ParameterName, value);
                    }

                    paramString = paramStringBuilder.ToString();
                    paramString = paramString.Substring(0, paramString.Length - 2); //get rid of the trailing comma

                    messageBuilder.AppendLine();
                }

                var trackingMetric = new DatabaseMetric(eventData, shortenedQuery);
                trackingMetric.Parameters = paramString;

                if (command.Transaction != null)
                {
                    messageBuilder.AppendFormat("Transaction:\r\n    Id: {0:X}\r\n    Isolation Level: {1}\r\n\r\n", command.Transaction.GetHashCode(), command.Transaction.IsolationLevel);
                }

                var connection = command.Connection;
                if (connection != null)
                {
                    trackingMetric.Server   = connection.DataSource;
                    trackingMetric.Database = connection.Database;
                    messageBuilder.AppendFormat("Server:\r\n    DataSource: {3}\r\n    Database: {4}\r\n    Connection Timeout: {2:N0} Seconds\r\n    Provider: {0}\r\n    Server Version: {1}\r\n\r\n",
                                                connection.GetType(), connection.ServerVersion, connection.ConnectionTimeout, connection.DataSource, connection.Database);
                }

                var messageSourceProvider = new MessageSourceProvider(2); //It's a minimum of two frames to our caller.
                if (LogCallStack)
                {
                    messageBuilder.AppendFormat("Call Stack:\r\n{0}\r\n\r\n", messageSourceProvider.StackTrace);
                }

                Log.Write(_configuration.QueryMessageSeverity, LogSystem, messageSourceProvider, null, null, LogWriteMode.Queued, null, LogCategory, caption,
                          messageBuilder.ToString());

                trackingMetric.MessageSourceProvider = messageSourceProvider;

                //we have to stuff the tracking metric in our index so that we can update it on the flipside.
                try
                {
                    _commands[eventData.CommandId] = new DatabaseMetric(eventData, shortenedQuery);
                }
                catch (Exception ex)
                {
#if DEBUG
                    Log.Error(ex, LogCategory, "Unable to set database tracking metric for command due to " + ex.GetType(), "While storing the database metric for the current operation a {0} was thrown so it's unpredictable what will be recorded at the end of the operation.\r\n{1}", ex.GetType(), ex.Message);
#endif
                    GC.KeepAlive(ex);
                }
            }
            catch (Exception ex)
            {
#if DEBUG
                Log.Error(ex, LogCategory, "Unable to record Entity Framework event due to " + ex.GetType(), "While calculating the log message for this event a {0} was thrown so we are unable to record the event.\r\n{1}", ex.GetType(), ex.Message);
#endif
                GC.KeepAlive(ex);
            }
        }
 public override Task <InterceptionResult <object> > ScalarExecutingAsync(DbCommand command, CommandEventData eventData, InterceptionResult <object> result,
                                                                          CancellationToken cancellationToken = new CancellationToken())
 {
     command.CommandText = TableAliasRegex.Replace(
         command.CommandText,
         "${tableAlias} WITH (NOLOCK)"
         );
     return(base.ScalarExecutingAsync(command, eventData, result, cancellationToken));
 }
Exemple #21
0
 /// <summary>
 /// </summary>
 /// <param name="command"></param>
 /// <param name="eventData"></param>
 /// <param name="result"></param>
 /// <returns></returns>
 public override InterceptionResult <object> ScalarExecuting(DbCommand command, CommandEventData eventData, InterceptionResult <object> result)
 {
     if (command.Connection.DataSource.EndsWith(":wasm", System.StringComparison.CurrentCultureIgnoreCase))
     {
         InterceptionResult <int> .SuppressWithResult(42);
     }
     return(base.ScalarExecuting(command, eventData, result));
 }
Exemple #22
0
 public override Task <InterceptionResult <DbDataReader> > ReaderExecutingAsync(DbCommand command, CommandEventData eventData, InterceptionResult <DbDataReader> result, CancellationToken cancellationToken = default)
 {
     //查询总数时替换掉*
     command.CommandText = command.CommandText.Replace("COUNT(*)", "COUNT(1)");
     return(base.ReaderExecutingAsync(command, eventData, result, cancellationToken));
 }
Exemple #23
0
 /// <summary>
 /// </summary>
 /// <param name="command"></param>
 /// <param name="eventData"></param>
 /// <param name="result"></param>
 /// <param name="cancellationToken"></param>
 /// <returns></returns>
 public override Task <InterceptionResult <object> > ScalarExecutingAsync(DbCommand command, CommandEventData eventData, InterceptionResult <object> result, CancellationToken cancellationToken = default)
 {
     if (command.Connection.DataSource.EndsWith(":wasm", System.StringComparison.CurrentCultureIgnoreCase))
     {
         InterceptionResult <int> .SuppressWithResult(42);
     }
     return(base.ScalarExecutingAsync(command, eventData, result, cancellationToken));
 }
 public InterceptionResult <object> ScalarExecuting(DbCommand command, CommandEventData eventData,
                                                    InterceptionResult <object> result)
 {
     TrackEvent(nameof(ScalarExecuting), eventData.Connection, command, eventData.ConnectionId);
     return(result);
 }
 public override ValueTask <InterceptionResult <DbDataReader> > ReaderExecutingAsync(DbCommand command, CommandEventData eventData, InterceptionResult <DbDataReader> result, CancellationToken cancellationToken = default)
 {
     command.CommandText = WithNoLockInterceptor.TableAliasRegex.Replace(command.CommandText, "${tableAlias} WITH (NOLOCK)");
     return(base.ReaderExecutingAsync(command, eventData, result, cancellationToken));
 }
 public ValueTask <InterceptionResult <int> > NonQueryExecutingAsync(DbCommand command, CommandEventData eventData,
                                                                     InterceptionResult <int> result,
                                                                     CancellationToken cancellationToken = new CancellationToken())
 {
     TrackEvent(nameof(NonQueryExecutingAsync), eventData.Connection, command, eventData.ConnectionId);
     return(ValueTask.FromResult(result));
 }
 public override InterceptionResult <int> NonQueryExecuting(DbCommand command, CommandEventData eventData, InterceptionResult <int> result)
 {
     if (command.CommandText.Contains("nvarchar(max)"))
     {
         //  When you set a string length greater then 4000,
         //  "nvarchar(max)" will be set. This is not yet handled
         //  by the frameworks translation between MS SQL & SQLite.
         command.CommandText = command.CommandText.Replace("nvarchar(max)", "nvarchar(8000)");
     }
     return(base.NonQueryExecuting(command, eventData, result));
 }
 public override Task <InterceptionResult <DbDataReader> > ReaderExecutingAsync(DbCommand command, CommandEventData eventData, InterceptionResult <DbDataReader> result,
                                                                                CancellationToken cancellationToken = new CancellationToken())
 {
     return(base.ReaderExecutingAsync(command, eventData, result, cancellationToken));
 }
 public override InterceptionResult <int> NonQueryExecuting(DbCommand command, CommandEventData eventData, InterceptionResult <int> result)
 {
     command.CommandText = ReplaceTenantId(command.CommandText);
     return(base.NonQueryExecuting(command, eventData, result));
 }
Exemple #30
0
 public override InterceptionResult <int> NonQueryExecuting(DbCommand command, CommandEventData eventData, InterceptionResult <int> result)
 {
     return(base.NonQueryExecuting(command, eventData, result));
 }
 public override InterceptionResult <object> ScalarExecuting(DbCommand command, CommandEventData eventData, InterceptionResult <object> result)
 {
     command.CommandText = ReplaceTenantId(command.CommandText);
     return(base.ScalarExecuting(command, eventData, result));
 }
Exemple #32
0
        public override InterceptionResult <DbDataReader> ReaderExecuting(DbCommand command, CommandEventData eventData, InterceptionResult <DbDataReader> result)
        {
            var parameters = command.Parameters;

            return(base.ReaderExecuting(command, eventData, result));
        }
 private void UpdateCursorId()
 {
     if( MyInput.UpKeyDown && !disableUpDownEvent )
     {
         AddCursorId( -1 );
         SoundManager.Instance.Play( "CursorSelect" );
     }
     if( MyInput.DownKeyDown && !disableUpDownEvent )
     {
         AddCursorId( 1 );
         SoundManager.Instance.Play( "CursorSelect" );
     }
     if( MyInput.LeftKeyDown )
     {
         ExecuteEvent( refInputEventList[cursorId].LeftEventExecute );
     }
     if( MyInput.RightKeyDown )
     {
         ExecuteEvent( refInputEventList[cursorId].RightEventExecute );
     }
     if( MyInput.FireKeyDown )
     {
         ExecuteEvent( refInputEventList[cursorId].DecideEventExecute );
     }
     if( MyInput.BombKeyDown )
     {
         var data = new CommandEventData();
         if( refCancelEventObject != null )
         {
             refCancelEventObject.BroadcastMessage( InputEvent.CommandEventMessage, data );
         }
         LockInput( data );
     }
 }